blob: 26c97d13317cadf4c899d7e600ad5a58481b023d [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
Srinivas Girigowda576b2352017-08-25 14:44:26 -0700748 if (cds_is_load_or_unload_in_progress())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800749 return -EAGAIN;
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530750
751 if (hdd_ctx->start_modules_in_progress ||
752 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800753 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530754 (void *)_RET_IP_);
755 return -EAGAIN;
756 }
757
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530758 if (cds_is_driver_in_bad_state()) {
759 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
760 (void *)_RET_IP_, cds_get_driver_state());
761 return -ENODEV;
762 }
763
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764 return 0;
765}
766
Jeff Johnson9d295242017-08-29 14:39:48 -0700767int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700768{
769 if (!adapter) {
770 hdd_err("adapter is null");
771 return -EINVAL;
772 }
773
774 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
775 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
776 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
777 return -EINVAL;
778 }
779
780 if (!adapter->dev) {
781 hdd_err("adapter net_device is null");
782 return -EINVAL;
783 }
784
785 if (!(adapter->dev->flags & IFF_UP)) {
786 hdd_info("adapter net_device is not up");
787 return -EAGAIN;
788 }
789
790 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
791 hdd_info("adapter session is not open");
792 return -EAGAIN;
793 }
794
795 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
796 hdd_err("bad adapter session Id: %u", adapter->sessionId);
797 return -EINVAL;
798 }
799
800 return 0;
801}
802
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530804 * wlan_hdd_validate_modules_state() - Check modules status
805 * @hdd_ctx: HDD context pointer
806 *
807 * Check's the driver module's state and returns true if the
808 * modules are enabled returns false if modules are closed.
809 *
810 * Return: True if modules are enabled or false.
811 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700812bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530813{
814 mutex_lock(&hdd_ctx->iface_change_lock);
815 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
816 mutex_unlock(&hdd_ctx->iface_change_lock);
817 hdd_notice("Modules not enabled, Present status: %d",
818 hdd_ctx->driver_status);
819 return false;
820 }
821 mutex_unlock(&hdd_ctx->iface_change_lock);
822 return true;
823}
824
825/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700827 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828 *
829 * This function sets the IBSS power save config parameters to WMA
830 * which will send it to firmware if FW supports IBSS power save
831 * before vdev start.
832 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530833 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834 * on failure.
835 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700836QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837{
838 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700839 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840
841 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700842 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530843 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800844 }
845
Naveen Rawat247a8682017-06-05 15:00:31 -0700846 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
848 hdd_ctx->config->ibssATIMWinSize,
849 VDEV_CMD);
850 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700851 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530852 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 }
854
Naveen Rawat247a8682017-06-05 15:00:31 -0700855 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
857 hdd_ctx->config->isIbssPowerSaveAllowed,
858 VDEV_CMD);
859 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700860 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
861 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530862 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 }
864
Naveen Rawat247a8682017-06-05 15:00:31 -0700865 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
867 hdd_ctx->config->
868 isIbssPowerCollapseAllowed, VDEV_CMD);
869 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700870 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
871 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530872 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873 }
874
Naveen Rawat247a8682017-06-05 15:00:31 -0700875 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
877 hdd_ctx->config->isIbssAwakeOnTxRx,
878 VDEV_CMD);
879 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700880 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530881 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800882 }
883
Naveen Rawat247a8682017-06-05 15:00:31 -0700884 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
886 hdd_ctx->config->ibssInactivityCount,
887 VDEV_CMD);
888 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700889 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530890 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800891 }
892
Naveen Rawat247a8682017-06-05 15:00:31 -0700893 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
895 hdd_ctx->config->ibssTxSpEndInactivityTime,
896 VDEV_CMD);
897 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700898 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
899 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530900 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 }
902
Naveen Rawat247a8682017-06-05 15:00:31 -0700903 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
905 hdd_ctx->config->ibssPsWarmupTime,
906 VDEV_CMD);
907 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700908 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
909 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530910 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 }
912
Naveen Rawat247a8682017-06-05 15:00:31 -0700913 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
915 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
916 VDEV_CMD);
917 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700918 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
919 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530920 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 }
922
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530923 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924}
925
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800926#define INTF_MACADDR_MASK 0x7
927
928/**
929 * hdd_update_macaddr() - update mac address
930 * @config: hdd configuration
931 * @hw_macaddr: mac address
932 *
933 * Mac address for multiple virtual interface is found as following
934 * i) The mac address of the first interface is just the actual hw mac address.
935 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
936 * define the mac address for the remaining interfaces and locally
937 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
938 * supported virtual interfaces, right now this is 0x07 (meaning 8
939 * interface).
940 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
941 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
942 *
943 * Return: None
944 */
945void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530946 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800947{
948 int8_t i;
949 uint8_t macaddr_b3, tmp_br3;
950
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530951 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530952 QDF_MAC_ADDR_SIZE);
953 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530954 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530955 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 macaddr_b3 = config->intfMacAddr[i].bytes[3];
957 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
958 INTF_MACADDR_MASK;
959 macaddr_b3 += tmp_br3;
960
961 /* XOR-ing bit-24 of the mac address. This will give enough
962 * mac address range before collision
963 */
964 macaddr_b3 ^= (1 << 7);
965
966 /* Set locally administered bit */
967 config->intfMacAddr[i].bytes[0] |= 0x02;
968 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800969 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800970 MAC_ADDRESS_STR, i,
971 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
972 }
973}
974
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700975static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800976 struct wma_tgt_services *cfg)
977{
978 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800979
980 /* Set up UAPSD */
981 config->apUapsdEnabled &= cfg->uapsd;
982
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800983 /* 11AX mode support */
984 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
985 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
986 config->dot11Mode = eHDD_DOT11_MODE_11ac;
987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988 /* 11AC mode support */
989 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
990 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
991 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992
993 /* ARP offload: override user setting if invalid */
994 config->fhostArpOffload &= cfg->arp_offload;
995
996#ifdef FEATURE_WLAN_SCAN_PNO
997 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800998 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999 if (cfg->pno_offload)
1000 config->PnoOffload = true;
1001#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002#ifdef FEATURE_WLAN_TDLS
1003 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301004 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1005 cfg->en_tdls_offchan;
1006 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1007 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001008 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001010 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001011 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1014 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1015#endif
Will Huang496b36c2017-07-11 16:38:50 +08001016 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001017 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018
1019}
1020
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001021/**
1022 * hdd_update_vdev_nss() - sets the vdev nss
1023 * @hdd_ctx: HDD context
1024 *
1025 * Sets the Nss per vdev type based on INI
1026 *
1027 * Return: None
1028 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001029static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001030{
1031 struct hdd_config *cfg_ini = hdd_ctx->config;
1032 uint8_t max_supp_nss = 1;
1033
Naveen Rawat10b1c152017-01-18 11:16:06 -08001034 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001035 max_supp_nss = 2;
1036
1037 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1038 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1039
1040 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1041 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1042}
1043
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301044/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301045 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1046 * @hdd_ctx: HDD context
1047 *
1048 * Updates wiphy vhtcap fields
1049 *
1050 * Return: None
1051 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001052static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301053{
1054 struct ieee80211_supported_band *band_5g =
1055 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1056 uint32_t val;
1057
1058 if (!band_5g) {
1059 hdd_debug("5GHz band disabled, skipping capability population");
1060 return;
1061 }
1062
1063 val = hdd_ctx->config->txBFCsnValue;
1064 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1065
1066 val = NUM_OF_SOUNDING_DIMENSIONS;
1067 band_5g->vht_cap.cap |=
1068 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1069
1070 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1071 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1072}
1073
1074/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301075 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1076 * @hdd_ctx: HDD context
1077 *
1078 * Sets the DBS capability as per INI and firmware capability
1079 *
1080 * Return: None
1081 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001082static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301083{
1084 struct hdd_config *cfg_ini = hdd_ctx->config;
1085 uint8_t hw_dbs_capable = 0;
1086
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001087 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1088 ((cfg_ini->dual_mac_feature_disable ==
1089 ENABLE_DBS_CXN_AND_SCAN) ||
1090 (cfg_ini->dual_mac_feature_disable ==
1091 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301092 hw_dbs_capable = 1;
1093
1094 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1095}
1096
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001097static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001098 struct wma_tgt_ht_cap *cfg)
1099{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301100 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001101 uint32_t value, val32;
1102 uint16_t val16;
1103 struct hdd_config *pconfig = hdd_ctx->config;
1104 tSirMacHTCapabilityInfo *phtCapInfo;
1105 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1106 uint8_t enable_tx_stbc;
1107
1108 /* check and update RX STBC */
1109 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1110 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1111
1112 /* get the MPDU density */
1113 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1114
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301115 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001116 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117 value = 0;
1118 }
1119
1120 /*
1121 * MPDU density:
1122 * override user's setting if value is larger
1123 * than the one supported by target
1124 */
1125 if (value > cfg->mpdu_density) {
1126 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1127 cfg->mpdu_density);
1128
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301129 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001130 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131 }
1132
1133 /* get the HT capability info */
1134 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301135 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001136 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001137 return;
1138 }
1139 val16 = (uint16_t) val32;
1140 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1141
1142 /* Set the LDPC capability */
1143 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1144
1145 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1146 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1147
1148 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1149 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1150
1151 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1152 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1153
1154 enable_tx_stbc = pconfig->enableTxSTBC;
1155
1156 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1157 pconfig->enable2x2 = 1;
1158 } else {
1159 pconfig->enable2x2 = 0;
1160 enable_tx_stbc = 0;
1161
1162 /* 1x1 */
1163 /* Update Rx Highest Long GI data Rate */
1164 if (sme_cfg_set_int(hdd_ctx->hHal,
1165 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001166 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301167 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001168 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001169 }
1170
1171 /* Update Tx Highest Long GI data Rate */
1172 if (sme_cfg_set_int
1173 (hdd_ctx->hHal,
1174 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001175 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301176 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001177 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178 }
1179 }
1180 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1181 enable_tx_stbc = 0;
1182 phtCapInfo->txSTBC = enable_tx_stbc;
1183
1184 val32 = val16;
1185 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301186 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001187 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001188#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1189 value = SIZE_OF_SUPPORTED_MCS_SET;
1190 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301191 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001192 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193
1194 if (pconfig->enable2x2) {
1195 for (value = 0; value < cfg->num_rf_chains; value++)
1196 mcs_set[value] =
1197 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1198
1199 status =
1200 sme_cfg_set_str(hdd_ctx->hHal,
1201 WNI_CFG_SUPPORTED_MCS_SET,
1202 mcs_set,
1203 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301204 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001205 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001206 }
1207 }
1208#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1209}
1210
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001211static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212 struct wma_tgt_vht_cap *cfg)
1213{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301214 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001215 uint32_t value = 0;
1216 struct hdd_config *pconfig = hdd_ctx->config;
1217 struct wiphy *wiphy = hdd_ctx->wiphy;
1218 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001219 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001220 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001221 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001222 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001223
Dustin Brown5e06bd32016-10-04 12:49:10 -07001224 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001225 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001226 return;
1227 }
1228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001229 /* Get the current MPDU length */
1230 status =
1231 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1232 &value);
1233
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301234 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001235 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 value = 0;
1237 }
1238
1239 /*
1240 * VHT max MPDU length:
1241 * override if user configured value is too high
1242 * that the target cannot support
1243 */
1244 if (value > cfg->vht_max_mpdu) {
1245 status = sme_cfg_set_int(hdd_ctx->hHal,
1246 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1247 cfg->vht_max_mpdu);
1248
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001249 if (status == QDF_STATUS_E_FAILURE)
1250 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251 }
1252
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001253 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1254 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1255
1256 if (pconfig->enable2x2)
1257 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1258
1259 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1260 QDF_STATUS_E_FAILURE) {
1261 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1262 }
1263
1264 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1265 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1266 if (pconfig->enable2x2)
1267 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1268
1269 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1270 QDF_STATUS_E_FAILURE) {
1271 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1272 }
1273
1274 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1275 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1276 if (pconfig->enable2x2)
1277 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1278
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001279 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001280 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1281
1282 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1283 QDF_STATUS_E_FAILURE) {
1284 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1285 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001286 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001287 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001288 &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 VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001292 value = 0;
1293 }
1294
jiad4a7a33c2017-08-08 15:32:24 +08001295 /* Set HW RX LDPC capability */
1296 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1297 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001298 status = sme_cfg_set_int(hdd_ctx->hHal,
1299 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001300 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001301
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001302 if (status == QDF_STATUS_E_FAILURE)
1303 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001304 }
1305
1306 /* Get current GI 80 value */
1307 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1308 &value);
1309
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301310 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001311 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001312 value = 0;
1313 }
1314
1315 /* set the Guard interval 80MHz */
1316 if (value && !cfg->vht_short_gi_80) {
1317 status = sme_cfg_set_int(hdd_ctx->hHal,
1318 WNI_CFG_VHT_SHORT_GI_80MHZ,
1319 cfg->vht_short_gi_80);
1320
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001321 if (status == QDF_STATUS_E_FAILURE)
1322 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 }
1324
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325 /* Get VHT TX STBC cap */
1326 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1327
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301328 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001329 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001330 value = 0;
1331 }
1332
1333 /* VHT TX STBC cap */
1334 if (value && !cfg->vht_tx_stbc) {
1335 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1336 cfg->vht_tx_stbc);
1337
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001338 if (status == QDF_STATUS_E_FAILURE)
1339 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001340 }
1341
1342 /* Get VHT RX STBC cap */
1343 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1344
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301345 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001346 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 value = 0;
1348 }
1349
1350 /* VHT RX STBC cap */
1351 if (value && !cfg->vht_rx_stbc) {
1352 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1353 cfg->vht_rx_stbc);
1354
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001355 if (status == QDF_STATUS_E_FAILURE)
1356 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001357 }
1358
1359 /* Get VHT SU Beamformer cap */
1360 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1361 &value);
1362
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301363 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001364 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 value = 0;
1366 }
1367
1368 /* set VHT SU Beamformer cap */
1369 if (value && !cfg->vht_su_bformer) {
1370 status = sme_cfg_set_int(hdd_ctx->hHal,
1371 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1372 cfg->vht_su_bformer);
1373
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001374 if (status == QDF_STATUS_E_FAILURE)
1375 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001376 }
1377
1378 /* check and update SU BEAMFORMEE capabality */
1379 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1380 pconfig->enableTxBF = cfg->vht_su_bformee;
1381
1382 status = sme_cfg_set_int(hdd_ctx->hHal,
1383 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1384 pconfig->enableTxBF);
1385
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001386 if (status == QDF_STATUS_E_FAILURE)
1387 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001388
1389 /* Get VHT MU Beamformer cap */
1390 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1391 &value);
1392
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301393 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001394 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001395 value = 0;
1396 }
1397
1398 /* set VHT MU Beamformer cap */
1399 if (value && !cfg->vht_mu_bformer) {
1400 status = sme_cfg_set_int(hdd_ctx->hHal,
1401 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1402 cfg->vht_mu_bformer);
1403
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001404 if (status == QDF_STATUS_E_FAILURE)
1405 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406 }
1407
1408 /* Get VHT MU Beamformee cap */
1409 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1410 &value);
1411
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301412 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001413 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001414 value = 0;
1415 }
1416
1417 /* set VHT MU Beamformee cap */
1418 if (value && !cfg->vht_mu_bformee) {
1419 status = sme_cfg_set_int(hdd_ctx->hHal,
1420 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1421 cfg->vht_mu_bformee);
1422
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001423 if (status == QDF_STATUS_E_FAILURE)
1424 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001425 }
1426
1427 /* Get VHT MAX AMPDU Len exp */
1428 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1429 &value);
1430
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301431 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001432 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001433 value = 0;
1434 }
1435
1436 /*
1437 * VHT max AMPDU len exp:
1438 * override if user configured value is too high
1439 * that the target cannot support.
1440 * Even though Rome publish ampdu_len=7, it can
1441 * only support 4 because of some h/w bug.
1442 */
1443
1444 if (value > cfg->vht_max_ampdu_len_exp) {
1445 status = sme_cfg_set_int(hdd_ctx->hHal,
1446 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1447 cfg->vht_max_ampdu_len_exp);
1448
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001449 if (status == QDF_STATUS_E_FAILURE)
1450 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451 }
1452
1453 /* Get VHT TXOP PS CAP */
1454 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1455
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301456 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001457 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 value = 0;
1459 }
1460
1461 /* set VHT TXOP PS cap */
1462 if (value && !cfg->vht_txop_ps) {
1463 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1464 cfg->vht_txop_ps);
1465
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001466 if (status == QDF_STATUS_E_FAILURE)
1467 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 }
1469
1470 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1471 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1472 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1473 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1474 else
1475 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1476
1477
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001478 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1479 status = sme_cfg_set_int(hdd_ctx->hHal,
1480 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1481 VHT_CAP_160_AND_80P80_SUPP);
1482 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001483 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001484 band_5g->vht_cap.cap |=
1485 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001486 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1487 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1488 status = sme_cfg_set_int(hdd_ctx->hHal,
1489 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1490 VHT_CAP_160_SUPP);
1491 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001492 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001493 band_5g->vht_cap.cap |=
1494 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001495 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1496 }
1497 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1498 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301499 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001500 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301501 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001502 &value);
1503 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301504 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001505 value = 0;
1506 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301507 /* set the Guard interval 160MHz */
1508 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001509 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301510 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1511 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001512
1513 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301514 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001515 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516
1517 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1518 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1519
1520 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1521 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1522 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1523 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1524
1525 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1526 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1527
1528 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1529 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1530 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1531 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1532 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1533 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1534
1535 band_5g->vht_cap.cap |=
1536 (cfg->vht_max_ampdu_len_exp <<
1537 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1538
1539 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1540 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1541 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1542 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1543 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1544 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1545 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1546 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1547
1548 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1549 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1550
1551}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001553/**
1554 * hdd_generate_macaddr_auto() - Auto-generate mac address
1555 * @hdd_ctx: Pointer to the HDD context
1556 *
1557 * Auto-generate mac address using device serial number.
1558 * Keep the first 3 bytes of OUI as before and replace
1559 * the last 3 bytes with the lower 3 bytes of serial number.
1560 *
1561 * Return: 0 for success
1562 * Non zero failure code for errors
1563 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001564static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001565{
1566 unsigned int serialno = 0;
1567 struct qdf_mac_addr mac_addr = {
1568 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1569 };
1570
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001571 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001572 if (serialno == 0)
1573 return -EINVAL;
1574
1575 serialno &= 0x00ffffff;
1576
1577 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1578 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1579 mac_addr.bytes[5] = serialno & 0xff;
1580
1581 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1582 return 0;
1583}
1584
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301585/**
1586 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1587 * configuration to cfg_ini in HDD
1588 * @hdd_ctx: Pointer to hdd_ctx
1589 * @cfg: target configuration
1590 *
1591 * Return: None
1592 */
1593#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001594static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301595 struct wma_tgt_cfg *cfg)
1596{
1597 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1598}
1599#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001600static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301601 struct wma_tgt_cfg *cfg)
1602{
1603}
1604#endif
1605
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001606void hdd_update_tgt_cfg(void *context, void *param)
1607{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001608 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001609 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001610 struct wma_tgt_cfg *cfg = param;
1611 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001612 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301613 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301614
Yue Mae3e86ab2017-05-08 10:48:24 -07001615 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301616 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1617 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1618 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1619 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1620 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001621 /* Restore pdev to MAC/WMA contexts */
1622 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001623 } else {
1624 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1625 if (ret) {
1626 hdd_err("pdev creation fails!");
1627 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301628 } else
1629 hdd_debug("New pdev has been created with pdev_id = %u",
1630 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301631 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001632
Naveen Rawat64e477e2016-05-20 10:34:56 -07001633 if (cds_cfg) {
1634 if (hdd_ctx->config->enable_sub_20_channel_width !=
1635 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1636 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1637 cds_cfg->sub_20_channel_width =
1638 WLAN_SUB_20_CH_WIDTH_NONE;
1639 } else {
1640 cds_cfg->sub_20_channel_width =
1641 hdd_ctx->config->enable_sub_20_channel_width;
1642 }
1643 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644
1645 /* first store the INI band capability */
1646 temp_band_cap = hdd_ctx->config->nBandCapability;
1647
1648 hdd_ctx->config->nBandCapability = cfg->band_cap;
1649
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001650 /*
1651 * now overwrite the target band capability with INI
1652 * setting if INI setting is a subset
1653 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001654
1655 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1656 (temp_band_cap != eCSR_BAND_ALL))
1657 hdd_ctx->config->nBandCapability = temp_band_cap;
1658 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1659 (temp_band_cap != eCSR_BAND_ALL) &&
1660 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001661 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001662 }
1663
Amar Singhal58b45ef2017-08-01 13:43:54 -07001664 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1665
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301666 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001667 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1668 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1669 }
1670
1671 /* This can be extended to other configurations like ht, vht cap... */
1672
Anurag Chouhanc5548422016-02-24 18:33:27 +05301673 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001675 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001677 static struct qdf_mac_addr default_mac_addr = {
1678 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1679 };
1680 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1681 &default_mac_addr)) {
1682 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1683 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1684 MAC_ADDRESS_STR,
1685 MAC_ADDR_ARRAY(hdd_ctx->config->
1686 intfMacAddr[0].bytes));
1687 } else {
1688 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1689 MAC_ADDRESS_STR,
1690 MAC_ADDR_ARRAY(hdd_ctx->config->
1691 intfMacAddr[0].bytes));
1692 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001693 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 }
1695
1696 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001697 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001698
1699 hdd_ctx->max_intf_count = cfg->max_intf_count;
1700
Jeff Johnsonc875e242016-09-23 18:12:34 -07001701 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001702 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001703
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1705 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1706
1707 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1708
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001709 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001710 if (cfg->services.en_11ax) {
1711 hdd_info("11AX: 11ax is enabled - update HDD config");
1712 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1713 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001714
1715 hdd_update_vdev_nss(hdd_ctx);
1716
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301717 hdd_update_hw_dbs_capable(hdd_ctx);
1718
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001719 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001720 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001721 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001722 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001723
Nitesh Shahe50711f2017-04-26 16:30:45 +05301724 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1725 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1726 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001727 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001728 hdd_ctx->current_antenna_mode);
1729
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001730 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1731 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301732 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301733
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301734 if ((hdd_ctx->config->txBFCsnValue >
1735 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1736 !cfg->tx_bfee_8ss_enabled)
1737 hdd_ctx->config->txBFCsnValue =
1738 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1739
1740 if (sme_cfg_set_int(hdd_ctx->hHal,
1741 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1742 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1743 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1744
1745
1746 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1747 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1748 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301749
1750 /*
1751 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1752 */
1753 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301754
1755 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1756
Arun Khandavallid454d422016-08-17 12:47:05 +05301757 /*
1758 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1759 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1760 * configure the STA mode wow pattern.
1761 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301762 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301763 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301764
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301765 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1766
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001767 /* Configure NAN datapath features */
1768 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001769 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001770}
1771
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001772bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001773{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001774 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001775 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301776 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001777 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001778
Arif Hussaincd151632017-02-11 16:57:19 -08001779 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001780 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001781 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301782 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001783 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784
Arif Hussaincd151632017-02-11 16:57:19 -08001785 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1786 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001787 adapter = adapterNode->adapter;
Arif Hussaincd151632017-02-11 16:57:19 -08001788 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1789
1790 if ((QDF_SAP_MODE == adapter->device_mode ||
1791 QDF_P2P_GO_MODE == adapter->device_mode) &&
1792 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1793 ap_ctx->operatingChannel))) {
1794 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1795 true;
1796 hdd_info("tx blocked for session: %d",
1797 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301798 }
Arif Hussaincd151632017-02-11 16:57:19 -08001799 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1800 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001801 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301802
1803 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001804}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001805
1806/**
1807 * hdd_is_valid_mac_address() - validate MAC address
1808 * @pMacAddr: Pointer to the input MAC address
1809 *
1810 * This function validates whether the given MAC address is valid or not
1811 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1812 * where X is the hexa decimal digit character and separated by ':'
1813 * This algorithm works even if MAC address is not separated by ':'
1814 *
1815 * This code checks given input string mac contains exactly 12 hexadecimal
1816 * digits and a separator colon : appears in the input string only after
1817 * an even number of hex digits.
1818 *
1819 * Return: 1 for valid and 0 for invalid
1820 */
1821bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1822{
1823 int xdigit = 0;
1824 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001825
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001826 while (*pMacAddr) {
1827 if (isxdigit(*pMacAddr)) {
1828 xdigit++;
1829 } else if (':' == *pMacAddr) {
1830 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1831 break;
1832
1833 ++separator;
1834 } else {
1835 /* Invalid MAC found */
1836 return 0;
1837 }
1838 ++pMacAddr;
1839 }
1840 return xdigit == 12 && (separator == 5 || separator == 0);
1841}
1842
1843/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301844 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1845 * @dev: Handle to struct net_device to be updated.
1846 *
1847 * Return: None
1848 */
1849static void hdd_mon_mode_ether_setup(struct net_device *dev)
1850{
1851 dev->header_ops = NULL;
1852 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1853 dev->hard_header_len = ETH_HLEN;
1854 dev->mtu = ETH_DATA_LEN;
1855 dev->addr_len = ETH_ALEN;
1856 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1857 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1858 dev->priv_flags |= IFF_TX_SKB_SHARING;
1859
1860 memset(dev->broadcast, 0xFF, ETH_ALEN);
1861}
1862
1863/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001864 * __hdd__mon_open() - HDD Open function
1865 * @dev: Pointer to net_device structure
1866 *
1867 * This is called in response to ifconfig up
1868 *
1869 * Return: 0 for success; non-zero for failure
1870 */
1871static int __hdd_mon_open(struct net_device *dev)
1872{
1873 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001874 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1875 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001876
1877 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001878
1879 ret = wlan_hdd_validate_context(hdd_ctx);
1880 if (ret)
1881 return ret;
1882
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301883 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001884
1885 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1886 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1887 if (ret) {
1888 hdd_err("Failed to start WLAN modules return");
1889 return ret;
1890 }
1891 hdd_err("hdd_wlan_start_modules() successful !");
1892
1893 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1894 ret = hdd_start_adapter(adapter);
1895 if (ret) {
1896 hdd_err("Failed to start adapter :%d",
1897 adapter->device_mode);
1898 return ret;
1899 }
1900 hdd_err("hdd_start_adapters() successful !");
1901 }
1902 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1903 }
1904
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001905 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001906
1907 if (!ret)
1908 ret = hdd_enable_monitor_mode(dev);
1909
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001910 return ret;
1911}
1912
1913/**
1914 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1915 * @dev: Pointer to net_device structure
1916 *
1917 * This is called in response to ifconfig up
1918 *
1919 * Return: 0 for success; non-zero for failure
1920 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001921static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001922{
1923 int ret;
1924
1925 cds_ssr_protect(__func__);
1926 ret = __hdd_mon_open(dev);
1927 cds_ssr_unprotect(__func__);
1928
1929 return ret;
1930}
1931
1932/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301933 * hdd_start_adapter() - Wrapper function for device specific adapter
1934 * @adapter: pointer to HDD adapter
1935 *
1936 * This function is called to start the device specific adapter for
1937 * the mode passed in the adapter's device_mode.
1938 *
1939 * Return: 0 for success; non-zero for failure
1940 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001941int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05301942{
1943
1944 int ret;
1945 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1946
1947 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001948 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301949
1950 switch (device_mode) {
1951 case QDF_P2P_CLIENT_MODE:
1952 case QDF_P2P_DEVICE_MODE:
1953 case QDF_OCB_MODE:
1954 case QDF_STA_MODE:
1955 case QDF_MONITOR_MODE:
1956 ret = hdd_start_station_adapter(adapter);
1957 if (ret)
1958 goto err_start_adapter;
1959 break;
1960 case QDF_P2P_GO_MODE:
1961 case QDF_SAP_MODE:
1962 ret = hdd_start_ap_adapter(adapter);
1963 if (ret)
1964 goto err_start_adapter;
1965 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301966 case QDF_IBSS_MODE:
1967 /*
1968 * For IBSS interface is initialized as part of
1969 * hdd_init_station_mode()
1970 */
1971 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301972 case QDF_FTM_MODE:
1973 ret = hdd_start_ftm_adapter(adapter);
1974 if (ret)
1975 goto err_start_adapter;
1976 break;
1977 default:
1978 hdd_err("Invalid session type %d", device_mode);
1979 QDF_ASSERT(0);
1980 goto err_start_adapter;
1981 }
1982 if (hdd_set_fw_params(adapter))
1983 hdd_err("Failed to set the FW params for the adapter!");
1984
1985 /*
1986 * Action frame registered in one adapter which will
1987 * applicable to all interfaces
1988 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05301989 ret = wlan_hdd_cfg80211_register_frames(adapter);
1990 if (ret < 0) {
1991 hdd_err("Failed to register frames - ret %d", ret);
1992 goto err_start_adapter;
1993 }
1994
Arun Khandavallifae92942016-08-01 13:31:08 +05301995 EXIT();
1996 return 0;
1997err_start_adapter:
1998 return -EINVAL;
1999}
2000
2001/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302002 * hdd_enable_power_management() - API to Enable Power Management
2003 *
2004 * API invokes Bus Interface Layer power management functionality
2005 *
2006 * Return: None
2007 */
2008static void hdd_enable_power_management(void)
2009{
2010 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2011
2012 if (!hif_ctx) {
2013 hdd_err("Bus Interface Context is Invalid");
2014 return;
2015 }
2016
2017 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2018}
2019
2020/**
2021 * hdd_disable_power_management() - API to disable Power Management
2022 *
2023 * API disable Bus Interface Layer Power management functionality
2024 *
2025 * Return: None
2026 */
2027static void hdd_disable_power_management(void)
2028{
2029 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2030
2031 if (!hif_ctx) {
2032 hdd_err("Bus Interface Context is Invalid");
2033 return;
2034 }
2035
2036 hif_disable_power_management(hif_ctx);
2037}
2038
2039/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302040 * hdd_update_hw_sw_info() - API to update the HW/SW information
2041 *
2042 * API to update the HW and SW information in the driver
2043 *
2044 * Return: None
2045 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002046static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302047{
2048 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002049 size_t target_hw_name_len;
2050 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302051
2052 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2053 if (!hif_sc) {
2054 hdd_err("HIF context is NULL");
2055 return;
2056 }
2057
2058 /*
2059 * target hw version/revision would only be retrieved after firmware
2060 * download
2061 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002062 hif_get_hw_info(hif_sc,
2063 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302064 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002065 &target_hw_name);
2066
2067 if (hdd_ctx->target_hw_name)
2068 qdf_mem_free(hdd_ctx->target_hw_name);
2069
2070 target_hw_name_len = strlen(target_hw_name) + 1;
2071 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2072 if (hdd_ctx->target_hw_name)
2073 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2074 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302075
2076 /* Get the wlan hw/fw version */
2077 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302078}
2079
2080/**
gbian62edd7e2017-03-07 13:12:13 +08002081 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2082 * @hdd_ctx: Pointer to hdd context
2083 *
2084 * Return: none
2085 */
2086static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002087hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002088{
2089 uint8_t num_entries = 0;
2090 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2091 uint8_t *tx_sched_wrr_ac;
2092 int i;
2093 cds_context_type *cds_ctx;
2094
2095 if (NULL == hdd_ctx)
2096 return;
2097
2098 if (NULL == hdd_ctx->config) {
2099 /* Do nothing if hdd_ctx is invalid */
2100 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2101 return;
2102 }
2103
2104 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2105
2106 if (!cds_ctx) {
2107 hdd_err("Invalid CDS Context");
2108 return;
2109 }
2110
2111 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2112 switch (i) {
2113 case OL_TX_WMM_AC_BE:
2114 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2115 break;
2116 case OL_TX_WMM_AC_BK:
2117 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2118 break;
2119 case OL_TX_WMM_AC_VI:
2120 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2121 break;
2122 case OL_TX_WMM_AC_VO:
2123 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2124 break;
2125 default:
2126 tx_sched_wrr_ac = NULL;
2127 break;
2128 }
2129
2130 hdd_string_to_u8_array(tx_sched_wrr_ac,
2131 tx_sched_wrr_param,
2132 &num_entries,
2133 sizeof(tx_sched_wrr_param));
2134
2135 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2136 cds_ctx->ac_specs[i].wrr_skip_weight =
2137 tx_sched_wrr_param[0];
2138 cds_ctx->ac_specs[i].credit_threshold =
2139 tx_sched_wrr_param[1];
2140 cds_ctx->ac_specs[i].send_limit =
2141 tx_sched_wrr_param[2];
2142 cds_ctx->ac_specs[i].credit_reserve =
2143 tx_sched_wrr_param[3];
2144 cds_ctx->ac_specs[i].discard_weight =
2145 tx_sched_wrr_param[4];
2146 }
2147
2148 num_entries = 0;
2149 }
2150}
2151
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002152#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002153static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2154 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2155{
Jeff Johnson9d295242017-08-29 14:39:48 -07002156 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002157 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002158
2159 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2160 if (!adapter) {
2161 hdd_err("Adapter is NULL");
2162 return PM_MAX_NUM_OF_MODE;
2163 }
2164
2165 return policy_mgr_convert_device_mode_to_qdf_type(
2166 adapter->device_mode);
2167}
2168
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002169static void hdd_register_policy_manager_callback(
2170 struct wlan_objmgr_psoc *psoc)
2171{
2172 struct policy_mgr_hdd_cbacks hdd_cbacks;
2173 hdd_cbacks.sap_restart_chan_switch_cb =
2174 sap_restart_chan_switch_cb;
2175 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2176 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002177 hdd_cbacks.get_mode_for_non_connected_vdev =
2178 wlan_hdd_get_mode_for_non_connected_vdev;
2179
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002180 if (QDF_STATUS_SUCCESS !=
2181 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2182 hdd_err("HDD callback registration with policy manager failed");
2183 }
2184}
2185#else
2186static void hdd_register_policy_manager_callback(
2187 struct wlan_objmgr_psoc *psoc)
2188{
2189}
2190#endif
2191
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002192#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002193static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002194{
2195 struct nan_callbacks cb_obj = {0};
2196
2197 cb_obj.ndi_open = hdd_ndi_open;
2198 cb_obj.ndi_close = hdd_ndi_close;
2199 cb_obj.ndi_start = hdd_ndi_start;
2200 cb_obj.ndi_delete = hdd_ndi_delete;
2201 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2202 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2203
Naveen Rawat37f62c82017-03-26 22:24:43 -07002204 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2205 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002206 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002207
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002208 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2209}
2210#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002211static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002212{
2213}
2214#endif
2215
gbian62edd7e2017-03-07 13:12:13 +08002216/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302217 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2218 * @hdd_ctx: HDD context
2219 * @adapter: HDD adapter
2220 * @reinit: flag to indicate from SSR or normal path
2221 *
2222 * This function maintains the driver state machine it will be invoked from
2223 * startup, reinit and change interface. Depending on the driver state shall
2224 * perform the opening of the modules.
2225 *
2226 * Return: 0 for success; non-zero for failure
2227 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002228int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2229 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302230 bool reinit)
2231{
2232 int ret;
2233 qdf_device_t qdf_dev;
2234 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302235 bool unint = false;
2236 void *hif_ctx;
2237
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002238 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302239
2240 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2241 if (!qdf_dev) {
2242 hdd_err("QDF Device Context is Invalid return");
2243 return -EINVAL;
2244 }
2245
2246 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302247 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302248
2249 if (QDF_TIMER_STATE_RUNNING ==
2250 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2251
2252 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002253 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302254 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2255 }
2256
2257 switch (hdd_ctx->driver_status) {
2258 case DRIVER_MODULES_UNINITIALIZED:
2259 unint = true;
2260 /* Fall through dont add break here */
2261 case DRIVER_MODULES_CLOSED:
2262 if (!reinit && !unint) {
2263 ret = pld_power_on(qdf_dev->dev);
2264 if (ret) {
2265 hdd_err("Failed to Powerup the device: %d", ret);
2266 goto release_lock;
2267 }
2268 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002269
2270 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2271 hdd_ctx->config->enable_fw_log);
2272
Arun Khandavallifae92942016-08-01 13:31:08 +05302273 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2274 qdf_dev->bus_type,
2275 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2276 HIF_ENABLE_TYPE_PROBE);
2277 if (ret) {
2278 hdd_err("Failed to open hif: %d", ret);
2279 goto power_down;
2280 }
2281
2282 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302283 if (!hif_ctx) {
2284 hdd_err("hif context is null!!");
2285 goto power_down;
2286 }
2287
Arun Khandavallifae92942016-08-01 13:31:08 +05302288 status = ol_cds_init(qdf_dev, hif_ctx);
2289 if (status != QDF_STATUS_SUCCESS) {
2290 hdd_err("No Memory to Create BMI Context :%d", status);
2291 goto hif_close;
2292 }
2293
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002294 ret = hdd_update_config(hdd_ctx);
2295 if (ret) {
2296 hdd_err("Failed to update configuration :%d", ret);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002297 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002298 }
2299
gbian62edd7e2017-03-07 13:12:13 +08002300 hdd_update_cds_ac_specs_params(hdd_ctx);
2301
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302302 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302303 if (!QDF_IS_STATUS_SUCCESS(status)) {
2304 hdd_err("Failed to Open CDS: %d", status);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002305 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302306 }
2307
Mukul Sharma9d797a02017-01-05 20:26:03 +05302308 /* initalize components configurations after psoc open */
2309 ret = hdd_update_components_config(hdd_ctx);
2310 if (ret) {
2311 hdd_err("Failed to update components configs :%d",
2312 ret);
2313 goto close;
2314 }
2315
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002316 /*
2317 * NAN compoenet requires certian operations like, open adapter,
2318 * close adapter, etc. to be initiated by HDD, for those
2319 * register HDD callbacks with UMAC's NAN componenet.
2320 */
2321 hdd_nan_register_callbacks(hdd_ctx);
2322
Arun Khandavallifae92942016-08-01 13:31:08 +05302323 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2324
Jeff Johnson3a280122017-09-13 07:42:00 -07002325 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302326 if (!QDF_IS_STATUS_SUCCESS(status)) {
2327 hdd_err("Failed to pre-enable CDS: %d", status);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002328 goto close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302329 }
2330
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002331 hdd_register_policy_manager_callback(
2332 hdd_ctx->hdd_psoc);
2333
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302334 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302335 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302336
Arun Khandavallifae92942016-08-01 13:31:08 +05302337 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2338 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2339 hdd_ftm_mc_process_msg);
2340 break;
2341 }
2342 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002343 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302344 break;
2345 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302346
2347 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002348 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2349 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002350 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002351 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302352 }
2353
Arun Khandavallifae92942016-08-01 13:31:08 +05302354 /* Fall through dont add break here */
2355 case DRIVER_MODULES_OPENED:
2356 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002357 hdd_alert("adapter is Null");
2358 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302359 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302360 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2361 hdd_err("in ftm mode, no need to configure cds modules");
2362 break;
2363 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302364 if (hdd_configure_cds(hdd_ctx, adapter)) {
2365 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002366 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302367 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302368 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302369 hdd_info("Driver Modules Successfully Enabled");
2370 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2371 break;
2372 case DRIVER_MODULES_ENABLED:
2373 hdd_info("Driver modules already Enabled");
2374 break;
2375 default:
2376 hdd_err("WLAN start invoked in wrong state! :%d\n",
2377 hdd_ctx->driver_status);
2378 goto release_lock;
2379 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302380 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302381 mutex_unlock(&hdd_ctx->iface_change_lock);
2382 EXIT();
2383 return 0;
2384
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002385post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002386 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002387
Arun Khandavallifae92942016-08-01 13:31:08 +05302388close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002389 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002390 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302391
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002392ol_cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302393 ol_cds_free();
2394
2395hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002396 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2397 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302398power_down:
2399 if (!reinit && !unint)
2400 pld_power_off(qdf_dev->dev);
2401release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302402 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302403 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302404 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002405
Arun Khandavallifae92942016-08-01 13:31:08 +05302406 return -EINVAL;
2407}
2408
Naveen Rawat910726a2017-03-06 11:42:51 -08002409#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002410static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002411{
2412 int ret = os_if_wifi_pos_register_nl();
2413
2414 if (ret)
2415 hdd_err("os_if_wifi_pos_register_nl failed");
2416
2417 return ret;
2418}
2419
2420static int hdd_deactivate_wifi_pos(void)
2421{
2422 int ret = os_if_wifi_pos_deregister_nl();
2423
2424 if (ret)
2425 hdd_err("os_if_wifi_pos_deregister_nl failed");
2426
2427 return ret;
2428}
2429
2430/**
2431 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2432 * @hdd_ctx: hdd context
2433 *
2434 * Return: status of operation
2435 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002436static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002437{
2438 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2439 struct hdd_config *cfg = hdd_ctx->config;
2440
2441 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2442 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2443 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2444 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2445 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2446 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2447 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2448 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2449}
2450#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002451static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002452{
2453 return oem_activate_service(hdd_ctx);
2454}
2455
2456static int hdd_deactivate_wifi_pos(void)
2457{
2458 return 0;
2459}
2460
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002461static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002462{
2463}
2464#endif
2465
Arun Khandavallifae92942016-08-01 13:31:08 +05302466/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002467 * __hdd_open() - HDD Open function
2468 * @dev: Pointer to net_device structure
2469 *
2470 * This is called in response to ifconfig up
2471 *
2472 * Return: 0 for success; non-zero for failure
2473 */
2474static int __hdd_open(struct net_device *dev)
2475{
Jeff Johnson9d295242017-08-29 14:39:48 -07002476 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002477 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002478 int ret;
2479
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002480 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302481 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302482 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002483
Arunk Khandavallie1b3a382017-09-26 12:01:26 +05302484 if (!hdd_wait_for_recovery_completion()) {
2485 hdd_err("Recovery failed");
2486 return -EIO;
2487 }
2488
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302489 /* Nothing to be done if device is unloading */
2490 if (cds_is_driver_unloading()) {
2491 hdd_err("Driver is unloading can not open the hdd");
2492 return -EBUSY;
2493 }
2494
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302495 mutex_lock(&hdd_init_deinit_lock);
2496
2497 /*
2498 * This scenario can be hit in cases where in the wlan driver after
2499 * registering the netdevices and there is a failure in driver
2500 * initialization. So return error gracefully because the netdevices
2501 * will be de-registered as part of the load failure.
2502 */
2503
2504 if (!cds_is_driver_loaded()) {
2505 hdd_err("Failed to start the wlan driver!!");
2506 ret = -EIO;
2507 goto err_hdd_hdd_init_deinit_lock;
2508 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302509
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002510
Arun Khandavallifae92942016-08-01 13:31:08 +05302511 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2512 if (ret) {
2513 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302514 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302515 }
2516
2517
2518 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2519 ret = hdd_start_adapter(adapter);
2520 if (ret) {
2521 hdd_err("Failed to start adapter :%d",
2522 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302523 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302524 }
2525 }
2526
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002527 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2528 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002529 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002530 /* Enable TX queues only when we are connected */
2531 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302532 WLAN_START_ALL_NETIF_QUEUE,
2533 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002534 }
2535
Naveen Rawat286def52016-09-23 15:38:02 -07002536 /* Enable carrier and transmit queues for NDI */
2537 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002538 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002539 wlan_hdd_netif_queue_control(adapter,
2540 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2541 WLAN_CONTROL_PATH);
2542 }
2543
Naveen Rawat910726a2017-03-06 11:42:51 -08002544 hdd_populate_wifi_pos_cfg(hdd_ctx);
2545
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302546err_hdd_hdd_init_deinit_lock:
2547 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002548 return ret;
2549}
2550
Arun Khandavallifae92942016-08-01 13:31:08 +05302551
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002552/**
2553 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2554 * @dev: Pointer to net_device structure
2555 *
2556 * This is called in response to ifconfig up
2557 *
2558 * Return: 0 for success; non-zero for failure
2559 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002560static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002561{
2562 int ret;
2563
2564 cds_ssr_protect(__func__);
2565 ret = __hdd_open(dev);
2566 cds_ssr_unprotect(__func__);
2567
2568 return ret;
2569}
2570
2571/**
2572 * __hdd_stop() - HDD stop function
2573 * @dev: Pointer to net_device structure
2574 *
2575 * This is called in response to ifconfig down
2576 *
2577 * Return: 0 for success; non-zero for failure
2578 */
2579static int __hdd_stop(struct net_device *dev)
2580{
Jeff Johnson9d295242017-08-29 14:39:48 -07002581 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002582 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002583 int ret;
2584
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002585 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002586
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302587 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002588 adapter->sessionId, adapter->device_mode));
2589
2590 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302591 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002592 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002593
2594 /* Nothing to be done if the interface is not opened */
2595 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002596 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002597 return -ENODEV;
2598 }
2599
2600 /* Make sure the interface is marked as closed */
2601 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302602
2603 hdd_debug("Disabling Auto Power save timer");
2604 sme_ps_disable_auto_ps_timer(
2605 WLAN_HDD_GET_HAL_CTX(adapter),
2606 adapter->sessionId);
2607
2608 /*
2609 * Disable TX on the interface, after this hard_start_xmit() will not
2610 * be called on that interface
2611 */
2612 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302613 wlan_hdd_netif_queue_control(adapter,
2614 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2615 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002616
2617 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002618 * NAN data interface is different in some sense. The traffic on NDI is
2619 * bursty in nature and depends on the need to transfer. The service
2620 * layer may down the interface after the usage and up again when
2621 * required. In some sense, the NDI is expected to be available
2622 * (like SAP) iface until NDI delete request is issued by the service
2623 * layer. Skip BSS termination and adapter deletion for NAN Data
2624 * interface (NDI).
2625 */
2626 if (WLAN_HDD_IS_NDI(adapter))
2627 return 0;
2628
2629 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002630 * The interface is marked as down for outside world (aka kernel)
2631 * But the driver is pretty much alive inside. The driver needs to
2632 * tear down the existing connection on the netdev (session)
2633 * cleanup the data pipes and wait until the control plane is stabilized
2634 * for this interface. The call also needs to wait until the above
2635 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002636 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002637 * That is intentional to be able to scan if it is a STA/P2P interface
2638 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302639 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002640
2641 /* DeInit the adapter. This ensures datapath cleanup as well */
2642 hdd_deinit_adapter(hdd_ctx, adapter, true);
2643
Arun Khandavallifae92942016-08-01 13:31:08 +05302644
2645 /*
2646 * Find if any iface is up. If any iface is up then can't put device to
2647 * sleep/power save mode
2648 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302649 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002650 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302651 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302652 hdd_ctx->config->iface_change_wait_time);
Arun Khandavallifae92942016-08-01 13:31:08 +05302653 }
2654
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002655 EXIT();
2656 return 0;
2657}
2658
2659/**
2660 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2661 * @dev: pointer to net_device structure
2662 *
2663 * This is called in response to ifconfig down
2664 *
2665 * Return: 0 for success and error number for failure
2666 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002667static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002668{
2669 int ret;
2670
2671 cds_ssr_protect(__func__);
2672 ret = __hdd_stop(dev);
2673 cds_ssr_unprotect(__func__);
2674
2675 return ret;
2676}
2677
2678/**
2679 * __hdd_uninit() - HDD uninit function
2680 * @dev: Pointer to net_device structure
2681 *
2682 * This is called during the netdev unregister to uninitialize all data
2683 * associated with the device
2684 *
2685 * Return: None
2686 */
2687static void __hdd_uninit(struct net_device *dev)
2688{
Jeff Johnson9d295242017-08-29 14:39:48 -07002689 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002690 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002691
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002692 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002693
2694 do {
2695 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002696 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002697 break;
2698 }
2699
Jeff Johnson399c6272017-08-30 10:51:00 -07002700 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2701 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002702 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002703 break;
2704 }
2705
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002706 if (dev != adapter->dev)
2707 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002708
Jeff Johnson399c6272017-08-30 10:51:00 -07002709 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002710
2711 /* after uninit our adapter structure will no longer be valid */
2712 adapter->dev = NULL;
2713 adapter->magic = 0;
2714 } while (0);
2715
2716 EXIT();
2717}
2718
2719/**
2720 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2721 * @dev: pointer to net_device structure
2722 *
2723 * This is called during the netdev unregister to uninitialize all data
2724 * associated with the device
2725 *
2726 * Return: none
2727 */
2728static void hdd_uninit(struct net_device *dev)
2729{
2730 cds_ssr_protect(__func__);
2731 __hdd_uninit(dev);
2732 cds_ssr_unprotect(__func__);
2733}
2734
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002735static int hdd_open_cesium_nl_sock(void)
2736{
2737#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2738 struct netlink_kernel_cfg cfg = {
2739 .groups = WLAN_NLINK_MCAST_GRP_ID,
2740 .input = NULL
2741 };
2742#endif
2743 int ret = 0;
2744
2745#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2746 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2747#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2748 THIS_MODULE,
2749#endif
2750 &cfg);
2751#else
2752 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2753 WLAN_NLINK_MCAST_GRP_ID,
2754 NULL, NULL, THIS_MODULE);
2755#endif
2756
2757 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002758 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002759 ret = -ECONNREFUSED;
2760 }
2761
2762 return ret;
2763}
2764
2765static void hdd_close_cesium_nl_sock(void)
2766{
2767 if (NULL != cesium_nl_srv_sock) {
2768 netlink_kernel_release(cesium_nl_srv_sock);
2769 cesium_nl_srv_sock = NULL;
2770 }
2771}
2772
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002773/**
2774 * __hdd_set_mac_address() - set the user specified mac address
2775 * @dev: Pointer to the net device.
2776 * @addr: Pointer to the sockaddr.
2777 *
2778 * This function sets the user specified mac address using
2779 * the command ifconfig wlanX hw ether <mac adress>.
2780 *
2781 * Return: 0 for success, non zero for failure
2782 */
2783static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2784{
Jeff Johnson9d295242017-08-29 14:39:48 -07002785 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002786 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002787 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302788 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002789 int ret;
2790
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002791 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002792
2793 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2794 ret = wlan_hdd_validate_context(hdd_ctx);
2795 if (0 != ret)
2796 return ret;
2797
2798 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2799 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2800
2801 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302802 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002803}
2804
2805/**
2806 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2807 * function from SSR
2808 * @dev: pointer to net_device structure
2809 * @addr: Pointer to the sockaddr
2810 *
2811 * This function sets the user specified mac address using
2812 * the command ifconfig wlanX hw ether <mac adress>.
2813 *
2814 * Return: 0 for success.
2815 */
2816static int hdd_set_mac_address(struct net_device *dev, void *addr)
2817{
2818 int ret;
2819
2820 cds_ssr_protect(__func__);
2821 ret = __hdd_set_mac_address(dev, addr);
2822 cds_ssr_unprotect(__func__);
2823
2824 return ret;
2825}
2826
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002827uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002828{
2829 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002830
Anurag Chouhan6d760662016-02-20 16:05:43 +05302831 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002832 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2833 break;
2834 }
2835
Anurag Chouhan6d760662016-02-20 16:05:43 +05302836 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002837 return NULL;
2838
2839 hdd_ctx->config->intfAddrMask |= (1 << i);
2840 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2841}
2842
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002843void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx, uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002844{
2845 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002846
Anurag Chouhan6d760662016-02-20 16:05:43 +05302847 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002848 if (!memcmp(releaseAddr,
2849 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2850 6)) {
2851 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2852 break;
2853 }
2854 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002855}
2856
2857#ifdef WLAN_FEATURE_PACKET_FILTERING
2858/**
2859 * __hdd_set_multicast_list() - set the multicast address list
2860 * @dev: Pointer to the WLAN device.
2861 * @skb: Pointer to OS packet (sk_buff).
2862 *
2863 * This funciton sets the multicast address list.
2864 *
2865 * Return: None
2866 */
2867static void __hdd_set_multicast_list(struct net_device *dev)
2868{
Jeff Johnson9d295242017-08-29 14:39:48 -07002869 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002870 int i = 0, status;
2871 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002872 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302873 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2874 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2875 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002876
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002877 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302878 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302879 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302880
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002881 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302882 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302883 goto out;
2884
Dustin Brownc788acb2017-08-01 17:43:51 -07002885 status = hdd_validate_adapter(adapter);
2886 if (status)
2887 goto out;
2888
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302889 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2890 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002891 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302892 goto out;
2893 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002894
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302895 /* Delete already configured multicast address list */
2896 if (adapter->mc_addr_list.mc_cnt > 0) {
2897 hdd_info("clear previously configured MC address list");
2898 hdd_disable_and_flush_mc_addr_list(adapter,
2899 pmo_mc_list_change_notify);
2900 }
2901
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002902 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002903 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302904 hdd_disable_and_flush_mc_addr_list(adapter,
2905 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002906 } else {
2907 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302908 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002909 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302910 pmo_ucfg_max_mc_addr_supported(psoc));
2911 hdd_disable_and_flush_mc_addr_list(adapter,
2912 pmo_mc_list_change_notify);
2913 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002914 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002915 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002916 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302917 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002918 if (i == mc_count)
2919 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302920 memset(&(mc_list_request->mc_addr[i].bytes),
2921 0, ETH_ALEN);
2922 memcpy(&(mc_list_request->mc_addr[i].bytes),
2923 ha->addr, ETH_ALEN);
2924 hdd_info("mlist[%d] = %pM", i,
2925 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926 i++;
2927 }
2928 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302929
2930 mc_list_request->psoc = psoc;
2931 mc_list_request->vdev_id = adapter->sessionId;
2932 mc_list_request->count = mc_count;
2933 status = hdd_cache_mc_addr_list(mc_list_request);
2934 if (status == 0) {
2935 hdd_enable_mc_addr_filtering(adapter,
2936 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002937 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302938 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002939 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302940out:
2941 if (mc_list_request)
2942 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302943 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002944}
2945
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947/**
2948 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2949 * @dev: pointer to net_device
2950 *
2951 * Return: none
2952 */
2953static void hdd_set_multicast_list(struct net_device *dev)
2954{
2955 cds_ssr_protect(__func__);
2956 __hdd_set_multicast_list(dev);
2957 cds_ssr_unprotect(__func__);
2958}
2959#endif
2960
2961/**
2962 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2963 * @dev: Pointer to the WLAN device.
2964 * @skb: Pointer to OS packet (sk_buff).
2965 *
2966 * This function is registered with the Linux OS for network
2967 * core to decide which queue to use first.
2968 *
2969 * Return: ac, Queue Index/access category corresponding to UP in IP header
2970 */
2971static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2972#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2973 , void *accel_priv
2974#endif
2975#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2976 , select_queue_fallback_t fallback
2977#endif
2978)
2979{
2980 return hdd_wmm_select_queue(dev, skb);
2981}
2982
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002983static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002984 .ndo_open = hdd_open,
2985 .ndo_stop = hdd_stop,
2986 .ndo_uninit = hdd_uninit,
2987 .ndo_start_xmit = hdd_hard_start_xmit,
2988 .ndo_tx_timeout = hdd_tx_timeout,
2989 .ndo_get_stats = hdd_get_stats,
2990 .ndo_do_ioctl = hdd_ioctl,
2991 .ndo_set_mac_address = hdd_set_mac_address,
2992 .ndo_select_queue = hdd_select_queue,
2993#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002994 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002995#endif
2996};
2997
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002998/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002999static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003000 .ndo_open = hdd_mon_open,
3001 .ndo_stop = hdd_stop,
3002 .ndo_get_stats = hdd_get_stats,
3003};
3004
3005/**
3006 * hdd_set_station_ops() - update net_device ops for monitor mode
3007 * @pWlanDev: Handle to struct net_device to be updated.
3008 * Return: None
3009 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003010void hdd_set_station_ops(struct net_device *pWlanDev)
3011{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003012 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
3013 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
3014 else
3015 pWlanDev->netdev_ops = &wlan_drv_ops;
3016}
3017
Komal Seelama89be8d2016-09-29 11:09:26 +05303018#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05303019/**
3020 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
3021 * @hdd_ctx: HDD context
3022 *
3023 * Return: None
3024 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003025static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05303026{
3027 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
3028
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003029 qdf_runtime_lock_init(&ctx->roc);
3030 qdf_runtime_lock_init(&ctx->dfs);
Komal Seelam8634b772016-09-29 12:12:24 +05303031}
3032
3033/**
3034 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
3035 * @hdd_ctx: HDD Context
3036 *
3037 * Return: None
3038 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003039static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05303040{
3041 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
3042
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003043 qdf_runtime_lock_deinit(&ctx->roc);
3044 qdf_runtime_lock_deinit(&ctx->dfs);
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05303045
3046 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05303047}
3048
Jeff Johnson9d295242017-08-29 14:39:48 -07003049static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05303050{
3051 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
3052
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003053 qdf_runtime_lock_init(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05303054}
3055
Jeff Johnson9d295242017-08-29 14:39:48 -07003056static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05303057{
3058 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
3059
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003060 qdf_runtime_lock_deinit(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05303061}
3062#else /* FEATURE_RUNTIME_PM */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003063static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
3064static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Jeff Johnson9d295242017-08-29 14:39:48 -07003065static inline void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
3066static inline void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05303067#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003068/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003069 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3070 * @hdd_ctx: global hdd context
3071 * @macAddr: mac address to assign to the interface
3072 * @name: User-visible name of the interface
3073 *
3074 * hdd adapter pointer would point to the netdev->priv space, this function
3075 * would retrive the pointer, and setup the hdd adapter configuration.
3076 *
3077 * Return: the pointer to hdd adapter, otherwise NULL
3078 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003079static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003080 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003081 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003082 const char *name)
3083{
3084 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003085 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003086 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003087 /*
3088 * cfg80211 initialization and registration....
3089 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003090 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003091#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3092 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003093#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003094 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3095 hdd_mon_mode_ether_setup : ether_setup),
3096 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003097
3098 if (pWlanDev != NULL) {
3099
3100 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003101 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003102
Jeff Johnson9d295242017-08-29 14:39:48 -07003103 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303104 sta_ctx = &adapter->sessionCtx.station;
3105 qdf_mem_set(sta_ctx->conn_info.staId,
3106 sizeof(sta_ctx->conn_info.staId),
3107 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003108 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003109 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303111 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003112
3113 init_completion(&adapter->session_open_comp_var);
3114 init_completion(&adapter->session_close_comp_var);
3115 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303116 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003117 init_completion(&adapter->linkup_event_var);
3118 init_completion(&adapter->cancel_rem_on_chan_var);
3119 init_completion(&adapter->rem_on_chan_ready_event);
3120 init_completion(&adapter->sta_authorized_event);
3121 init_completion(&adapter->offchannel_tx_event);
3122 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003123 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124 init_completion(&adapter->change_country_code);
3125
3126
3127 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303128 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003129
3130 adapter->offloads_configured = false;
3131 adapter->isLinkUpSvcNeeded = false;
3132 adapter->higherDtimTransition = true;
3133 /* Init the net_device structure */
3134 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3135
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303136 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303138 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003139 sizeof(tSirMacAddr));
3140 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003141
3142 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3143 pWlanDev->features |=
3144 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3145 pWlanDev->features |= NETIF_F_RXCSUM;
3146
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003147 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3148
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003149 hdd_set_station_ops(adapter->dev);
3150
Dustin Brownc81dd412017-08-15 16:26:28 -07003151 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003153 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154 adapter->wdev.wiphy = hdd_ctx->wiphy;
3155 adapter->wdev.netdev = pWlanDev;
3156 /* set pWlanDev's parent to underlying device */
3157 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3158 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303159 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003160 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303161 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003162 }
3163
3164 return adapter;
3165}
3166
Jeff Johnson9d295242017-08-29 14:39:48 -07003167static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003168{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003169 struct net_device *dev = adapter->dev;
3170 int ret;
3171
3172 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003174 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003175 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3176
3177 ret = dev_alloc_name(dev, dev->name);
3178 if (ret < 0) {
3179 hdd_err(
3180 "unable to get dev name: %s, err = 0x%x",
3181 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303182 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003183 }
3184 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003185
3186 ret = register_netdevice(dev);
3187 if (ret) {
3188 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3189 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303190 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003191 }
3192 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003193 ret = register_netdev(dev);
3194 if (ret) {
3195 hdd_err("register_netdev(%s) failed, err = 0x%x",
3196 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303197 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198 }
3199 }
3200 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3201
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003202 EXIT();
3203
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303204 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205}
3206
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003207QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208{
Jeff Johnson9d295242017-08-29 14:39:48 -07003209 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003210
3211 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003212 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303213 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003214 }
3215
3216 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003217 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303218 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003219 }
3220
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003221 /*
3222 * For NAN Data interface, the close session results in the final
3223 * indication to the userspace
3224 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003225 if (adapter->device_mode == QDF_NDI_MODE)
3226 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003227
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003228 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003230 /*
3231 * We can be blocked while waiting for scheduled work to be
3232 * flushed, and the adapter structure can potentially be freed, in
3233 * which case the magic will have been reset. So make sure the
3234 * magic is still good, and hence the adapter structure is still
3235 * valid, before signaling completion
3236 */
3237 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3238 complete(&adapter->session_close_comp_var);
3239
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303240 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241}
3242
Jeff Johnson9d295242017-08-29 14:39:48 -07003243int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244{
Dustin Brownd28772b2017-03-17 14:16:07 -07003245 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003246
Dustin Brownd28772b2017-03-17 14:16:07 -07003247 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003248 if (QDF_IS_STATUS_ERROR(status))
3249 return qdf_status_to_os_return(status);
3250
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003251 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003252 if (QDF_IS_STATUS_ERROR(status))
3253 return qdf_status_to_os_return(status);
3254
3255 if (wma_capability_enhanced_mcast_filter())
3256 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3257 else
3258 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003259
3260 return qdf_status_to_os_return(status);
3261}
3262
Jeff Johnson9d295242017-08-29 14:39:48 -07003263int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003264{
3265 QDF_STATUS status;
3266 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003267 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003268 unsigned long rc;
3269
3270 hdd_info("destroying vdev %d", adapter->sessionId);
3271
3272 /* vdev created sanity check */
3273 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3274 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3275 return -EINVAL;
3276 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003277 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003278 /*
3279 * In SSR case, there is no need to destroy vdev in firmware since
3280 * it has already asserted. vdev can be released directly.
3281 */
3282 if (cds_is_driver_recovering())
3283 goto release_vdev;
3284
Dustin Brownd28772b2017-03-17 14:16:07 -07003285 /* close sme session (destroy vdev in firmware via legacy API) */
3286 INIT_COMPLETION(adapter->session_close_comp_var);
3287 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3288 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3289 hdd_sme_close_session_callback, adapter);
3290 if (QDF_IS_STATUS_ERROR(status)) {
3291 hdd_err("failed to close sme session: %d", status);
3292 return qdf_status_to_os_return(status);
3293 }
3294
3295 /* block on a completion variable until sme session is closed */
3296 rc = wait_for_completion_timeout(
3297 &adapter->session_close_comp_var,
3298 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3299 if (!rc) {
3300 hdd_err("timed out waiting for close sme session: %ld", rc);
3301 if (adapter->device_mode == QDF_NDI_MODE)
3302 hdd_ndp_session_end_handler(adapter);
3303 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3304 return -ETIMEDOUT;
3305 }
Yue Maf9782842017-05-08 12:49:49 -07003306release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003307 /* do vdev logical destroy via objmgr */
3308 errno = hdd_objmgr_destroy_vdev(adapter);
3309 if (errno) {
3310 hdd_err("failed to destroy objmgr vdev: %d", errno);
3311 return errno;
3312 }
3313
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003314 /* now that sme session is closed, allow physical vdev destroy */
3315 errno = hdd_objmgr_release_vdev(adapter);
3316 if (errno) {
3317 hdd_err("failed to release objmgr vdev: %d", errno);
3318 return errno;
3319 }
3320
Dustin Brownd28772b2017-03-17 14:16:07 -07003321 hdd_info("vdev destroyed successfully");
3322
3323 return 0;
3324}
3325
Jeff Johnson9d295242017-08-29 14:39:48 -07003326int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003327{
3328 QDF_STATUS status;
3329 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003330 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003331 uint32_t type;
3332 uint32_t sub_type;
3333 unsigned long rc;
3334
3335 hdd_info("creating new vdev");
3336
3337 /* determine vdev (sub)type */
3338 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303339 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003340 hdd_err("failed to get vdev type: %d", status);
3341 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003342 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003343
3344 /* do vdev create via objmgr */
3345 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003346 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003347 if (errno) {
3348 hdd_err("failed to create objmgr vdev: %d", errno);
3349 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003350 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003351
3352 /* Open a SME session (prepare vdev in firmware via legacy API) */
3353 INIT_COMPLETION(adapter->session_open_comp_var);
3354 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3355 (uint8_t *)&adapter->macAddressCurrent,
3356 adapter->sessionId, type, sub_type);
3357 if (QDF_IS_STATUS_ERROR(status)) {
3358 hdd_err("failed to open sme session: %d", status);
3359 errno = qdf_status_to_os_return(status);
3360 goto objmgr_vdev_destroy;
3361 }
3362
3363 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364 rc = wait_for_completion_timeout(
3365 &adapter->session_open_comp_var,
3366 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3367 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003368 hdd_err("timed out waiting for open sme session: %ld", rc);
3369 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303370 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3371 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003372 }
3373
3374 /* firmware ready for component communication, raise vdev_ready event */
3375 errno = hdd_vdev_ready(adapter);
3376 if (errno) {
3377 hdd_err("failed to dispatch vdev ready event: %d", errno);
3378 goto hdd_vdev_destroy;
3379 }
3380
3381 hdd_info("vdev %d created successfully", adapter->sessionId);
3382
3383 return 0;
3384
3385 /*
3386 * Due to legacy constraints, we need to destroy in the same order as
3387 * create. So, split error handling into 2 cases to accommodate.
3388 */
3389
3390objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003391 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003392
3393 return errno;
3394
3395hdd_vdev_destroy:
3396 QDF_BUG(!hdd_vdev_destroy(adapter));
3397
3398 return errno;
3399}
3400
Jeff Johnson9d295242017-08-29 14:39:48 -07003401QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003402{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003403 struct hdd_station_ctx *sta_ctx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003404 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003405 QDF_STATUS status;
3406 int ret_val;
3407
3408 ret_val = hdd_vdev_create(adapter);
3409 if (ret_val) {
3410 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303411 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412 }
3413
Dustin Brownd28772b2017-03-17 14:16:07 -07003414 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3415 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3416 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003417 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003418
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003419 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003420 status = hdd_register_wext(adapter->dev);
3421 if (QDF_IS_STATUS_ERROR(status)) {
3422 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423 goto error_register_wext;
3424 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003425 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003426
Jeff Johnsond377dce2017-10-04 10:32:42 -07003427 qdf_mem_set(sta_ctx->conn_info.staId,
3428 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303429
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003430 /* set fast roaming capability in sme session */
3431 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3432 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003433 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003434 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003435 hdd_ctx->config->OperatingChannel;
3436
3437 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003438 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003439
3440 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303441 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003442 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003443 status, status);
3444 goto error_init_txrx;
3445 }
3446
3447 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3448
3449 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303450 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003451 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 status, status);
3453 goto error_wmm_init;
3454 }
3455
3456 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3457
Naveen Rawat247a8682017-06-05 15:00:31 -07003458 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003459 WMI_PDEV_PARAM_BURST_ENABLE,
3460 hdd_ctx->config->enableSifsBurst,
3461 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003462 if (ret_val)
3463 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003464
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003465 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303466 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003467
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468error_wmm_init:
3469 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3470 hdd_deinit_tx_rx(adapter);
3471error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003472 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003474 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476 return status;
3477}
3478
Jeff Johnson9d295242017-08-29 14:39:48 -07003479void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003480{
Jeff Johnson5e4b93c2017-09-30 18:09:16 -07003481 struct hdd_cfg80211_state *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003482
3483 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3484
3485 if (NULL != cfgState->buf) {
3486 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003487
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488 rc = wait_for_completion_timeout(
3489 &adapter->tx_action_cnf_event,
3490 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3491 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003492 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303493 /*
3494 * Inform tx status as FAILURE to upper layer and free
3495 * cfgState->buf
3496 */
3497 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498 }
3499 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500}
3501
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303502/**
3503 * hdd_station_adapter_deinit() - De-initialize the station adapter
3504 * @hdd_ctx: global hdd context
3505 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003506 * @rtnl_held: Used to indicate whether or not the caller is holding
3507 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303508 *
3509 * This function De-initializes the STA/P2P/OCB adapter.
3510 *
3511 * Return: None.
3512 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003513static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003514 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003515 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303516{
3517 ENTER_DEV(adapter->dev);
3518
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303519 if (adapter->dev) {
3520 if (rtnl_held)
3521 adapter->dev->wireless_handlers = NULL;
3522 else {
3523 rtnl_lock();
3524 adapter->dev->wireless_handlers = NULL;
3525 rtnl_unlock();
3526 }
3527 }
3528
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303529 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3530 hdd_deinit_tx_rx(adapter);
3531 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3532 }
3533
3534 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3535 hdd_wmm_adapter_close(adapter);
3536 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3537 }
3538
3539 hdd_cleanup_actionframe(hdd_ctx, adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303540
3541 EXIT();
3542}
3543
3544/**
3545 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3546 * @hdd_ctx: global hdd context
3547 * @adapter: HDD adapter
3548 * @rtnl_held: the rtnl lock hold flag
3549 * This function De-initializes the AP/P2PGo adapter.
3550 *
3551 * Return: None.
3552 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003553static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003554 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003555 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303556{
3557 ENTER_DEV(adapter->dev);
3558
3559 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3560 hdd_wmm_adapter_close(adapter);
3561 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3562 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003563 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303564
3565 hdd_cleanup_actionframe(hdd_ctx, adapter);
3566
3567 hdd_unregister_hostapd(adapter, rtnl_held);
3568
3569 EXIT();
3570}
3571
Jeff Johnson9d295242017-08-29 14:39:48 -07003572void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003573 bool rtnl_held)
3574{
3575 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303576
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003577 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003578 case QDF_STA_MODE:
3579 case QDF_P2P_CLIENT_MODE:
3580 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003581 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303582 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003583 break;
3584 }
3585
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003586 case QDF_SAP_MODE:
3587 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588 {
3589
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303590 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591 break;
3592 }
3593
3594 default:
3595 break;
3596 }
3597
3598 EXIT();
3599}
3600
Jeff Johnson9d295242017-08-29 14:39:48 -07003601static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003602 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603{
3604 struct net_device *pWlanDev = NULL;
3605
3606 if (adapter)
3607 pWlanDev = adapter->dev;
3608 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003609 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610 return;
3611 }
3612
Rajeev Kumardca5f812016-02-04 17:28:06 -08003613 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303614
3615 if (adapter->scan_info.default_scan_ies) {
3616 qdf_mem_free(adapter->scan_info.default_scan_ies);
3617 adapter->scan_info.default_scan_ies = NULL;
3618 }
3619
Komal Seelama89be8d2016-09-29 11:09:26 +05303620 hdd_adapter_runtime_suspend_denit(adapter);
3621
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003622 /*
3623 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3624 * the driver is almost closed and cannot handle either control
3625 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003626 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3627 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628 * is not right. Setting this flag helps hdd_stop() to recognize that
3629 * the interface is closed and restricts any operations on that
3630 */
3631 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3632
3633 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003634 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003636 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003638 /*
3639 * Note that the adapter is no longer valid at this point
3640 * since the memory has been reclaimed
3641 */
3642 }
3643}
3644
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003645static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003646 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003647{
3648 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003649 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303650 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003651
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003652 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303653 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003654 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303656 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003657 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303658 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003659 }
3660 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3661 adapterNode = pNext;
3662 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303663 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003664}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003665
Arun Khandavalli2358d522016-05-16 18:05:37 +05303666#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3667/**
3668 * hdd_set_fw_log_params() - Set log parameters to FW
3669 * @hdd_ctx: HDD Context
3670 * @adapter: HDD Adapter
3671 *
3672 * This function set the FW Debug log level based on the INI.
3673 *
3674 * Return: None
3675 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003676static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003677 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303678{
3679 uint8_t count = 0, numentries = 0,
3680 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3681 uint32_t value = 0;
3682 int ret;
3683
Arun Khandavallifae92942016-08-01 13:31:08 +05303684 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3685 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003686 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303687 return;
3688 }
3689
Arun Khandavallifae92942016-08-01 13:31:08 +05303690 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303691 hdd_ctx->fw_log_settings.dl_type =
3692 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003693 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303694 WMI_DBGLOG_TYPE,
3695 hdd_ctx->config->enableFwLogType,
3696 DBG_CMD);
3697 if (ret != 0)
3698 hdd_err("Failed to enable FW log type ret %d",
3699 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303700
3701 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303702 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003703 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303704 WMI_DBGLOG_LOG_LEVEL,
3705 hdd_ctx->config->enableFwLogLevel,
3706 DBG_CMD);
3707 if (ret != 0)
3708 hdd_err("Failed to enable FW log level ret %d",
3709 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303710
3711 hdd_string_to_u8_array(
3712 hdd_ctx->config->enableFwModuleLogLevel,
3713 moduleloglevel,
3714 &numentries,
3715 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3716
3717 while (count < numentries) {
3718 /*
3719 * FW module log level input string looks like
3720 * below:
3721 * gFwDebugModuleLoglevel=<FW Module ID>,
3722 * <Log Level>,...
3723 * For example:
3724 * gFwDebugModuleLoglevel=
3725 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3726 * Above input string means :
3727 * For FW module ID 1 enable log level 0
3728 * For FW module ID 2 enable log level 1
3729 * For FW module ID 3 enable log level 2
3730 * For FW module ID 4 enable log level 3
3731 * For FW module ID 5 enable log level 4
3732 * For FW module ID 6 enable log level 5
3733 * For FW module ID 7 enable log level 6
3734 */
3735
Nishank Aggarwale239d962017-03-03 12:26:02 +05303736 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3737 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3738 hdd_err("Module id %d and dbglog level %d input length is more than max",
3739 moduleloglevel[count],
3740 moduleloglevel[count + 1]);
3741 return;
3742 }
3743
3744 value = moduleloglevel[count] << 16;
3745 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003746 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303747 WMI_DBGLOG_MOD_LOG_LEVEL,
3748 value, DBG_CMD);
3749 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303750 hdd_err("Failed to enable FW module log level %d ret %d",
3751 value, ret);
3752
3753 count += 2;
3754 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303755
Arun Khandavalli2358d522016-05-16 18:05:37 +05303756}
3757#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003758static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003759 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303760{
3761}
3762
3763#endif
3764
3765/**
3766 * hdd_set_fw_params() - Set parameters to firmware
3767 * @adapter: HDD adapter
3768 *
3769 * This function Sets various parameters to fw once the
3770 * adapter is started.
3771 *
3772 * Return: 0 on success or errno on failure
3773 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003774int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303775{
3776 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003777 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303778
3779 ENTER_DEV(adapter->dev);
3780
3781 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3782 if (!hdd_ctx)
3783 return -EINVAL;
3784
Dustin Brown732ab9c2017-06-15 13:24:09 -07003785 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3786 hdd_debug("FTM Mode is active; nothing to do");
3787 return 0;
3788 }
3789
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303790 ret = sme_cli_set_command(adapter->sessionId,
3791 WMI_PDEV_PARAM_DTIM_SYNTH,
3792 hdd_ctx->config->enable_lprx, PDEV_CMD);
3793 if (ret) {
3794 hdd_err("Failed to set LPRx");
3795 goto error;
3796 }
3797
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303798 if (adapter->device_mode == QDF_STA_MODE) {
3799 sme_set_smps_cfg(adapter->sessionId,
3800 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3801 hdd_ctx->config->upper_brssi_thresh);
3802
3803 sme_set_smps_cfg(adapter->sessionId,
3804 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3805 hdd_ctx->config->lower_brssi_thresh);
3806
3807 sme_set_smps_cfg(adapter->sessionId,
3808 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3809 hdd_ctx->config->enable_dtim_1chrx);
3810 }
3811
Dustin Brown732ab9c2017-06-15 13:24:09 -07003812 if (hdd_ctx->config->enable2x2) {
3813 hdd_debug("configuring 2x2 mode fw params");
3814
Naveen Rawat247a8682017-06-05 15:00:31 -07003815 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003816 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3817 hdd_ctx->config->enable_cck_tx_fir_override,
3818 PDEV_CMD);
3819 if (ret) {
3820 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3821 ret);
3822 goto error;
3823 }
3824 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303825#define HDD_DTIM_1CHAIN_RX_ID 0x5
3826#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003827 hdd_debug("configuring 1x1 mode fw params");
3828
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003829 /*
3830 * Disable DTIM 1 chain Rx when in 1x1,
3831 * we are passing two value
3832 * as param_id << 29 | param_value.
3833 * Below param_value = 0(disable)
3834 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003835 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003836 WMI_STA_SMPS_PARAM_CMDID,
3837 HDD_DTIM_1CHAIN_RX_ID <<
3838 HDD_SMPS_PARAM_VALUE_S,
3839 VDEV_CMD);
3840 if (ret) {
3841 hdd_err("DTIM 1 chain set failed %d", ret);
3842 goto error;
3843 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303844
Naveen Rawat247a8682017-06-05 15:00:31 -07003845 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003846 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3847 hdd_ctx->config->txchainmask1x1,
3848 PDEV_CMD);
3849 if (ret) {
3850 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3851 ret);
3852 goto error;
3853 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303854
Naveen Rawat247a8682017-06-05 15:00:31 -07003855 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003856 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3857 hdd_ctx->config->rxchainmask1x1,
3858 PDEV_CMD);
3859 if (ret) {
3860 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3861 ret);
3862 goto error;
3863 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303864#undef HDD_DTIM_1CHAIN_RX_ID
3865#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003866 }
3867
Naveen Rawat247a8682017-06-05 15:00:31 -07003868 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003869 WMI_PDEV_PARAM_HYST_EN,
3870 hdd_ctx->config->enableMemDeepSleep,
3871 PDEV_CMD);
3872 if (ret) {
3873 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3874 goto error;
3875 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303876
Naveen Rawat247a8682017-06-05 15:00:31 -07003877 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003878 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3879 hdd_ctx->config->rts_profile,
3880 VDEV_CMD);
3881 if (ret) {
3882 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3883 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303884 }
3885
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003886 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3887
3888 ret = wma_cli_set_command(adapter->sessionId,
3889 GEN_VDEV_PARAM_AMSDU,
3890 hdd_ctx->config->max_amsdu_num,
3891 GEN_CMD);
3892 if (ret != 0) {
3893 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3894 goto error;
3895 }
3896
Arun Khandavalli2358d522016-05-16 18:05:37 +05303897 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303898 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003899
Arun Khandavalli2358d522016-05-16 18:05:37 +05303900 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303901
Arun Khandavalli2358d522016-05-16 18:05:37 +05303902error:
3903 return -EINVAL;
3904}
3905
Ryan Hsu07495ea2016-01-21 15:25:39 -08003906/**
3907 * hdd_open_adapter() - open and setup the hdd adatper
3908 * @hdd_ctx: global hdd context
3909 * @session_type: type of the interface to be created
3910 * @iface_name: User-visible name of the interface
3911 * @macAddr: MAC address to assign to the interface
3912 * @name_assign_type: the name of assign type of the netdev
3913 * @rtnl_held: the rtnl lock hold flag
3914 *
3915 * This function open and setup the hdd adpater according to the device
3916 * type request, assign the name, the mac address assigned, and then prepared
3917 * the hdd related parameters, queue, lock and ready to start.
3918 *
3919 * Return: the pointer of hdd adapter, otherwise NULL.
3920 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003921struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003922 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003923 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003924 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925{
Jeff Johnson9d295242017-08-29 14:39:48 -07003926 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003927 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303928 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Jeff Johnson5e4b93c2017-09-30 18:09:16 -07003929 struct hdd_cfg80211_state *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931
3932 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3933 /*
3934 * Max limit reached on the number of vdevs configured by the
3935 * host. Return error
3936 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303937 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3938 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939 return NULL;
3940 }
3941
3942 if (macAddr == NULL) {
3943 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303944 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945 return NULL;
3946 }
3947 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303948 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303949 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3950 " already exists",
3951 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003952 return NULL;
3953 }
3954
3955 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003956 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957 /* Reset locally administered bit if the device mode is STA */
3958 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303959 hdd_info("locally administered bit reset in sta mode: "
3960 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003961 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003962 case QDF_P2P_CLIENT_MODE:
3963 case QDF_P2P_DEVICE_MODE:
3964 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003965 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303966 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003967 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3968 name_assign_type,
3969 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970
3971 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303972 hdd_err("failed to allocate adapter for session %d",
3973 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974 return NULL;
3975 }
3976
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003977 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003978 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003979 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303981 else if (QDF_MONITOR_MODE == session_type)
3982 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983 else
3984 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3985
3986 adapter->device_mode = session_type;
3987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003988
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989 /*
3990 * Workqueue which gets scheduled in IPv4 notification
3991 * callback
3992 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3994 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003995
3996#ifdef WLAN_NS_OFFLOAD
3997 /*
3998 * Workqueue which gets scheduled in IPv6
3999 * notification callback.
4000 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4002 hdd_ipv6_notifier_work_queue);
4003#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304005 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304007 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 }
4009
4010 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004011 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304013 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4014 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304015
Ravi Joshi1a292562017-05-18 16:28:54 -07004016 /* Initialize NAN Data Interface */
4017 if (QDF_NDI_MODE == session_type) {
4018 status = hdd_init_nan_data_mode(adapter);
4019 if (QDF_STATUS_SUCCESS != status)
4020 goto err_free_netdev;
4021 }
4022
4023 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004025 case QDF_P2P_GO_MODE:
4026 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004027 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4028 name_assign_type,
4029 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004031 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304032 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033 return NULL;
4034 }
4035
4036 adapter->wdev.iftype =
4037 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004038 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 NL80211_IFTYPE_P2P_GO;
4040 adapter->device_mode = session_type;
4041
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004042 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304043 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4045 goto err_free_netdev;
4046 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004047 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004048 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304049 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4050 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004051 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304052 case QDF_FTM_MODE:
4053 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4054 name_assign_type,
4055 "wlan0");
4056 if (NULL == adapter) {
4057 hdd_err("Failed to allocate adapter for FTM mode");
4058 return NULL;
4059 }
4060 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4061 adapter->device_mode = session_type;
4062 status = hdd_register_interface(adapter, rtnl_held);
4063 if (QDF_STATUS_SUCCESS != status) {
4064 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4065 goto err_free_netdev;
4066 }
4067 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004068 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304069 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304070 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4071 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304072 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004074 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304075 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 return NULL;
4077 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078
hqueaa33ee2017-05-04 17:56:35 +08004079 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4080
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004081 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4082 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4083
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304084 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004085 /* Add it to the hdd's session list. */
4086 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304087 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004088 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304089 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004090 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004091 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004092 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4093 }
4094 }
4095
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304096 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097 if (NULL != adapter) {
4098 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4099 adapter = NULL;
4100 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004101 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304102 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004103
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104 return NULL;
4105 }
4106
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304107 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004108 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4109 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004111 /* Adapter successfully added. Increment the vdev count */
4112 hdd_ctx->current_intf_count++;
4113
Jeff Johnson5880d792016-08-15 13:32:30 -07004114 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115 hdd_ctx->current_intf_count);
4116
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004117 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004118 }
4119
Rajeev Kumardca5f812016-02-04 17:28:06 -08004120 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004121 hdd_err("Interface %s wow debug_fs init failed",
4122 netdev_name(adapter->dev));
4123
4124 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4125 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004126
4127 return adapter;
4128
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004129err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304131 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004132
4133 return NULL;
4134}
4135
Jeff Johnson9d295242017-08-29 14:39:48 -07004136QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004137 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004138{
4139 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304140 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004141
4142 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304143 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004144 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145 status);
4146 return status;
4147 }
4148
Jeff Johnson57eb2732017-10-02 11:40:20 -07004149 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304151 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152 break;
4153
4154 pCurrent = pNext;
4155 }
4156 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304157 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004158 /*
4159 * Here we are stopping global bus_bw timer & work per adapter.
4160 *
4161 * The reason is to fix one race condition between
4162 * bus bandwidth work and cleaning up an adapter.
4163 * Under some conditions, it is possible for the bus bandwidth
4164 * work to access a particularly destroyed adapter, leading to
4165 * use-after-free.
4166 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004167 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004168 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004169 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004170
4171 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004172 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4173 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004174 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304176 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177 adapterNode = NULL;
4178
Dustin Brown5ec6b552017-03-31 12:11:40 -07004179 /* conditionally restart the bw timer */
4180 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4181
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004182 /* Adapter removed. Decrement vdev count */
4183 if (hdd_ctx->current_intf_count != 0)
4184 hdd_ctx->current_intf_count--;
4185
4186 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304187 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304189
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304190 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004191}
4192
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004193/**
4194 * hdd_close_all_adapters - Close all open adapters
4195 * @hdd_ctx: Hdd context
4196 * rtnl_held: True if RTNL lock held
4197 *
4198 * Close all open adapters.
4199 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304200 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004201 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004202QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004203{
4204 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304205 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206
4207 ENTER();
4208
4209 do {
4210 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304211 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304212 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004213 pHddAdapterNode->adapter->macAddressCurrent.bytes);
4214 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004215 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304216 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304217 /* Adapter removed. Decrement vdev count */
4218 if (hdd_ctx->current_intf_count != 0)
4219 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304221 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004222
4223 EXIT();
4224
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304225 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004226}
4227
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004228void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004229{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304230 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004231 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004232
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004233 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004234 case QDF_STA_MODE:
4235 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004236 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004237 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004238 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004239 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004240 break;
4241 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004242 case QDF_SAP_MODE:
4243 case QDF_P2P_GO_MODE:
4244 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004245 {
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004246 bssid = &adapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004247 break;
4248 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004249 case QDF_FTM_MODE:
4250 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004251 default:
4252 /*
4253 * wlan_hdd_reset_prob_rspies should not have been called
4254 * for these kind of devices
4255 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004256 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004257 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004258 return;
4259 }
4260
Anurag Chouhanc5548422016-02-24 18:33:27 +05304261 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004262 updateIE.smeSessionId = adapter->sessionId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004263 updateIE.ieBufferlength = 0;
4264 updateIE.pAdditionIEBuffer = NULL;
4265 updateIE.append = true;
4266 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004267 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004268 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304269 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004270 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004271 }
4272}
4273
Jeff Johnson9d295242017-08-29 14:39:48 -07004274QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275 const bool bCloseSession)
4276{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304277 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004278 struct hdd_wext_state *pWextState =
4279 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280 union iwreq_data wrqu;
4281 tSirUpdateIE updateIE;
4282 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004283 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004284
4285 ENTER();
4286
Sachin Ahuja988fd102016-09-15 17:16:25 +05304287 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004288 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304289 wlan_hdd_netif_queue_control(adapter,
4290 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4291 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004292 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004293 case QDF_STA_MODE:
4294 case QDF_P2P_CLIENT_MODE:
4295 case QDF_IBSS_MODE:
4296 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004297 case QDF_NDI_MODE:
4298 if ((QDF_NDI_MODE == adapter->device_mode) ||
4299 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004300 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4301 hdd_is_connecting(
4302 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004303 INIT_COMPLETION(adapter->disconnect_comp_var);
4304 /*
4305 * For NDI do not use pWextState from sta_ctx, if needed
4306 * extract from ndi_ctx.
4307 */
4308 if (QDF_NDI_MODE == adapter->device_mode)
4309 qdf_ret_status = sme_roam_disconnect(
4310 hdd_ctx->hHal,
4311 adapter->sessionId,
4312 eCSR_DISCONNECT_REASON_NDI_DELETE);
4313 else if (pWextState->roamProfile.BSSType ==
4314 eCSR_BSS_TYPE_START_IBSS)
4315 qdf_ret_status = sme_roam_disconnect(
4316 hdd_ctx->hHal,
4317 adapter->sessionId,
4318 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004319 else if (QDF_STA_MODE == adapter->device_mode)
4320 qdf_ret_status =
4321 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004323 qdf_ret_status = sme_roam_disconnect(
4324 hdd_ctx->hHal,
4325 adapter->sessionId,
4326 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004327 /* success implies disconnect command got
4328 * queued up successfully
4329 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004330 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4331 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004332 rc = wait_for_completion_timeout(
4333 &adapter->disconnect_comp_var,
4334 msecs_to_jiffies
4335 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004336 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004337 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004339 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4340 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004341 memset(&wrqu, '\0', sizeof(wrqu));
4342 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4343 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4344 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4345 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304346 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004347 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304348 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004349
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304350 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304351 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004352
4353#ifdef WLAN_OPEN_SOURCE
4354 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4355#endif
4356
4357 hdd_deregister_tx_flow_control(adapter);
4358
4359#ifdef WLAN_NS_OFFLOAD
4360#ifdef WLAN_OPEN_SOURCE
4361 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4362#endif
4363#endif
4364
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304365 if (adapter->device_mode == QDF_STA_MODE)
4366 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4367 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004368 /*
4369 * It is possible that the caller of this function does not
4370 * wish to close the session
4371 */
Krunal Soni985b8132017-02-10 18:49:08 -08004372 if (true == bCloseSession) {
4373 if (0 != wlan_hdd_try_disconnect(adapter)) {
4374 hdd_err("Error: Can't disconnect adapter");
4375 return QDF_STATUS_E_FAILURE;
4376 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004377 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004378 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004379 break;
4380
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004381 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304382 /* Flush IPA exception path packets */
4383 hdd_ipa_flush(hdd_ctx);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004384 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004385 if (QDF_SAP_MODE == adapter->device_mode) {
4386 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4387 cds_flush_delayed_work(
4388 &adapter->acs_pending_work);
4389 clear_bit(ACS_PENDING, &adapter->event_flags);
4390 }
4391 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004392 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004393 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4395
4396 hdd_deregister_tx_flow_control(adapter);
4397
Kapil Guptac1224bf2017-06-22 21:22:40 +05304398 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399 mutex_lock(&hdd_ctx->sap_lock);
4400 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304401 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304402 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004403
4404 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004405 status = wlansap_stop_bss(
4406 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004407
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304408 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004409 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004410 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304411 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304412 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304413 qdf_status =
4414 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004415 qdf_stop_bss_event,
4416 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004417
Anurag Chouhance0dc992016-02-16 18:18:03 +05304418 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004419 hdd_err("failure waiting for wlansap_stop_bss %d",
4420 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004421 }
4422 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004423 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 }
4425 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004426 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4427 adapter->device_mode,
4428 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429
Anurag Chouhanc5548422016-02-24 18:33:27 +05304430 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004431 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004432 updateIE.smeSessionId = adapter->sessionId;
4433 updateIE.ieBufferlength = 0;
4434 updateIE.pAdditionIEBuffer = NULL;
4435 updateIE.append = false;
4436 updateIE.notify = false;
4437 /* Probe bcn reset */
4438 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4439 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304440 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004441 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004442 }
4443 /* Assoc resp reset */
4444 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4445 &updateIE,
4446 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304447 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004448 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004449 }
4450 /* Reset WNI_CFG_PROBE_RSP Flags */
4451 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004452 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004453 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4454 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304455 /*
4456 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4457 */
4458 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4459 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4460
Peng Xu66162de2016-02-11 17:01:20 -08004461 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004462 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004463 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004465 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004466 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004467 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004468 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004469 break;
4470 default:
4471 break;
4472 }
4473
4474 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304475 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004476}
4477
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304478/**
4479 * hdd_deinit_all_adapters - deinit all adapters
4480 * @hdd_ctx: HDD context
4481 * @rtnl_held: True if RTNL lock held
4482 *
4483 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004484void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304485{
4486 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4487 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004488 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304489
4490 ENTER();
4491
4492 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4493
4494 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004495 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304496 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4497 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4498 adapter_node = next;
4499 }
4500
4501 EXIT();
4502}
4503
Dustin Brown27cd9942017-09-27 16:11:44 -07004504QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4505 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004506{
4507 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304508 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004509 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004510
4511 ENTER();
4512
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304513 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4514
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004515 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4516
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304517 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004518 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004519 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004520 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4521 adapterNode = pNext;
4522 }
4523
4524 EXIT();
4525
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304526 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004527}
4528
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004529QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004530{
4531 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304532 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004533 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004534 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004535 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004536
4537 ENTER();
4538
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304539 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4540
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004541 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4542
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304543 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004544 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004545 hdd_notice("Disabling queues for adapter type: %d",
4546 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304547
4548 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004549 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304550 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004551 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304552
Arun Khandavallicc544b32017-01-30 19:52:16 +05304553 if (hdd_ctx->config->sap_internal_restart &&
4554 adapter->device_mode == QDF_SAP_MODE) {
4555 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304556 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304557 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004558 if (test_bit(SOFTAP_BSS_STARTED,
4559 &adapter->event_flags)) {
4560 hdd_sap_indicate_disconnect_for_sta(adapter);
4561 hdd_cleanup_actionframe(hdd_ctx, adapter);
4562 hdd_sap_destroy_events(adapter);
4563 }
4564 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4565 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304566 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304567 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004569 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004570
4571 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4572
4573 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004574 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4575 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004576 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4577 hdd_wmm_adapter_close(adapter);
4578 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4579 }
4580
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304581 if (adapter->device_mode == QDF_STA_MODE)
4582 hdd_clear_fils_connection_info(adapter);
4583
Wu Gao3545e642017-07-14 19:24:41 +08004584 if (adapter->device_mode == QDF_SAP_MODE) {
4585 /*
4586 * If adapter is SAP, set session ID to invalid
4587 * since SAP session will be cleanup during SSR.
4588 */
Wu Gao36717432016-11-21 15:09:48 +08004589 wlansap_set_invalid_session(
4590 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4591
Wu Gao3545e642017-07-14 19:24:41 +08004592 wlansap_cleanup_cac_timer(
4593 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4594 }
4595
Yue Mad5b4b9f2017-05-26 16:23:40 -07004596 /* Delete peers if any for STA and P2P client modes */
4597 if (adapter->device_mode == QDF_STA_MODE ||
4598 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004599 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004600 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004601 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004602
4603 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4604 peerMacAddr.bytes);
4605 }
4606
Yue Maf9782842017-05-08 12:49:49 -07004607 /* Destroy vdev which will be recreated during reinit. */
4608 hdd_vdev_destroy(adapter);
4609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004610 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4611 adapterNode = pNext;
4612 }
4613
4614 EXIT();
4615
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304616 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004617}
4618
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004619bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304620{
4621 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4622 QDF_STATUS status;
4623 bool close_modules = true;
4624
Arun Khandavalliba479c42017-07-26 21:29:40 +05304625 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4626 hdd_info("FTM mode, don't close the module");
4627 return false;
4628 }
4629
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304630 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4631 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4632 if (test_bit(DEVICE_IFACE_OPENED,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004633 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004634 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304635 close_modules = false;
4636 break;
4637 }
4638 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4639 adapter_node = next;
4640 }
4641
4642 return close_modules;
4643}
4644
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304645bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304646{
4647 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4648 return true;
4649 else
4650 return false;
4651}
4652
Anurag Chouhanc4092922016-09-08 15:56:11 +05304653#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004654 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304655struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4656 struct ieee80211_channel *channel,
4657 const u8 *bssid, const u8 *ssid,
4658 size_t ssid_len)
4659{
4660 return cfg80211_get_bss(wiphy, channel, bssid,
4661 ssid, ssid_len,
4662 WLAN_CAPABILITY_ESS,
4663 WLAN_CAPABILITY_ESS);
4664}
4665#else
4666struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4667 struct ieee80211_channel *channel,
4668 const u8 *bssid, const u8 *ssid,
4669 size_t ssid_len)
4670{
4671 return cfg80211_get_bss(wiphy, channel, bssid,
4672 ssid, ssid_len,
4673 IEEE80211_BSS_TYPE_ESS,
4674 IEEE80211_PRIVACY_ANY);
4675}
4676#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304677
Abhishek Singha84d3952016-09-13 13:45:05 +05304678#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304679#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4680 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4681/**
4682 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4683 * @timeout_reason: reason for connect timeout
4684 *
4685 * This function is used to convert host timeout
4686 * reason enum to kernel specific enum.
4687 *
4688 * Return: nl timeout enum
4689 */
4690static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4691 tSirResultCodes timeout_reason)
4692{
4693 switch (timeout_reason) {
4694 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4695 return NL80211_TIMEOUT_SCAN;
4696 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4697 return NL80211_TIMEOUT_AUTH;
4698 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4699 return NL80211_TIMEOUT_ASSOC;
4700 default:
4701 return NL80211_TIMEOUT_UNSPECIFIED;
4702 }
4703}
4704
4705/**
4706 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4707 * @dev: network device
4708 * @bssid: bssid to which we want to associate
4709 * @timeout_reason: reason for connect timeout
4710 *
4711 * This API is used to send connection timeout reason to supplicant
4712 *
4713 * Return: void
4714 */
4715static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4716 const u8 *bssid,
4717 tSirResultCodes timeout_reason)
4718{
4719 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004720
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304721 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4722
4723 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4724 nl_timeout_reason);
4725}
4726
4727/**
4728 * __hdd_connect_bss() - API to send connection status to supplicant
4729 * @dev: network device
4730 * @bssid: bssid to which we want to associate
4731 * @req_ie: Request Information Element
4732 * @req_ie_len: len of the req IE
4733 * @resp_ie: Response IE
4734 * @resp_ie_len: len of ht response IE
4735 * @status: status
4736 * @gfp: Kernel Flag
4737 * @timeout_reason: reason for connect timeout
4738 *
4739 * Return: void
4740 */
4741static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4742 struct cfg80211_bss *bss, const u8 *req_ie,
4743 size_t req_ie_len, const u8 *resp_ie,
4744 size_t resp_ie_len, int status, gfp_t gfp,
4745 tSirResultCodes timeout_reason)
4746{
4747 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004748
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304749 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4750
4751 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4752 resp_ie, resp_ie_len, status, gfp,
4753 nl_timeout_reason);
4754}
4755#else
4756#if defined CFG80211_CONNECT_TIMEOUT
4757static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4758 const u8 *bssid,
4759 tSirResultCodes timeout_reason)
4760{
4761 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4762}
4763#endif
4764
4765static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4766 struct cfg80211_bss *bss, const u8 *req_ie,
4767 size_t req_ie_len, const u8 *resp_ie,
4768 size_t resp_ie_len, int status, gfp_t gfp,
4769 tSirResultCodes timeout_reason)
4770{
4771 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4772 resp_ie, resp_ie_len, status, gfp);
4773}
4774#endif
4775
Abhishek Singha84d3952016-09-13 13:45:05 +05304776/**
4777 * hdd_connect_bss() - API to send connection status to supplicant
4778 * @dev: network device
4779 * @bssid: bssid to which we want to associate
4780 * @req_ie: Request Information Element
4781 * @req_ie_len: len of the req IE
4782 * @resp_ie: Response IE
4783 * @resp_ie_len: len of ht response IE
4784 * @status: status
4785 * @gfp: Kernel Flag
4786 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304787 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304788 *
4789 * The API is a wrapper to send connection status to supplicant
4790 *
4791 * Return: Void
4792 */
4793#if defined CFG80211_CONNECT_TIMEOUT
4794static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4795 struct cfg80211_bss *bss, const u8 *req_ie,
4796 size_t req_ie_len, const u8 *resp_ie,
4797 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304798 bool connect_timeout,
4799 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304800{
4801 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304802 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304803 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304804 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4805 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304806}
4807#else
4808static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4809 struct cfg80211_bss *bss, const u8 *req_ie,
4810 size_t req_ie_len, const u8 *resp_ie,
4811 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304812 bool connect_timeout,
4813 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304814{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304815 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4816 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304817}
4818#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304819
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304820#ifdef WLAN_FEATURE_FILS_SK
4821#ifdef CFG80211_CONNECT_DONE
4822#ifdef CFG80211_FILS_SK_OFFLOAD_SUPPORT
4823/**
4824 * hdd_populate_fils_params() - Populate FILS keys to connect response
4825 * @fils_params: connect response to supplicant
4826 * @fils_kek: FILS kek
4827 * @fils_kek_len: FILS kek length
4828 * @pmk: FILS PMK
4829 * @pmk_len: FILS PMK length
4830 * @pmkid: PMKID
4831 * @fils_seq_num: FILS Seq number
4832 *
4833 * Return: None
4834 */
4835static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4836 *fils_params, const uint8_t *fils_kek,
4837 size_t fils_kek_len, const uint8_t *pmk,
4838 size_t pmk_len, const uint8_t *pmkid,
4839 uint16_t fils_seq_num)
4840{
4841 /* Increament seq number to be used for next FILS */
4842 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4843 fils_params->update_erp_next_seq_num = true;
4844 fils_params->fils_kek = fils_kek;
4845 fils_params->fils_kek_len = fils_kek_len;
4846 fils_params->pmk = pmk;
4847 fils_params->pmk_len = pmk_len;
4848 fils_params->pmkid = pmkid;
4849}
4850#else
4851static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4852 *fils_params, const uint8_t
4853 *fils_kek, size_t fils_kek_len,
4854 const uint8_t *pmk, size_t pmk_len,
4855 const uint8_t *pmkid,
4856 uint16_t fils_seq_num)
4857{ }
4858#endif
4859
4860/**
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304861 * hdd_update_hlp_info() - Update HLP packet received in FILS assoc rsp
4862 * @dev: net device
4863 * @roam_fils_params: Fils join rsp params
4864 *
4865 * This API is used to send the received HLP packet in Assoc rsp(FILS AKM)
4866 * to the network layer.
4867 *
4868 * Return: None
4869 */
4870static void hdd_update_hlp_info(struct net_device *dev,
4871 struct fils_join_rsp_params *roam_fils_params)
4872{
4873 struct sk_buff *skb;
4874 uint16_t skb_len;
4875 struct llc_snap_hdr_t *llc_hdr;
4876 QDF_STATUS status;
4877 uint8_t *hlp_data = roam_fils_params->hlp_data;
4878 uint16_t hlp_data_len = roam_fils_params->hlp_data_len;
4879 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
4880
4881 /* Calculate skb length */
4882 skb_len = (2 * ETH_ALEN) + hlp_data_len;
4883 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
4884 if (skb == NULL) {
4885 hdd_err("HLP packet nbuf alloc fails");
4886 return;
4887 }
4888
4889 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
4890 QDF_MAC_ADDR_SIZE);
4891 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
4892 QDF_MAC_ADDR_SIZE);
4893
4894 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
4895 if (IS_SNAP(llc_hdr)) {
4896 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4897 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4898 }
4899
4900 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
4901
4902 /*
4903 * This HLP packet is formed from HLP info encapsulated
4904 * in assoc response frame which is AEAD encrypted.
4905 * Hence, this checksum validation can be set unnecessary.
4906 * i.e. network layer need not worry about checksum.
4907 */
4908 skb->ip_summed = CHECKSUM_UNNECESSARY;
4909
4910 status = hdd_rx_packet_cbk(padapter, skb);
4911 if (QDF_IS_STATUS_ERROR(status)) {
4912 hdd_err("Sending HLP packet fails");
4913 return;
4914 }
4915 hdd_debug("send HLP packet to netif successfully");
4916}
4917
4918/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304919 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4920 * @dev: network device
4921 * @bssid: bssid to which we want to associate
4922 * @bss: cfg80211 bss info
4923 * @roam_info: information about connected bss
4924 * @req_ie: Request Information Element
4925 * @req_ie_len: len of the req IE
4926 * @resp_ie: Response IE
4927 * @resp_ie_len: len of ht response IE
4928 * @status: status
4929 * @gfp: allocation flags
4930 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4931 * @timeout_reason: reason for connect timeout
4932 * @roam_fils_params: FILS join response params
4933 *
4934 * This API is used as wrapper to send FILS key/sequence number
4935 * params etc. to supplicant in case of FILS connection
4936 *
4937 * Return: None
4938 */
4939static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4940 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4941 const u8 *req_ie, size_t req_ie_len,
4942 const u8 *resp_ie, size_t resp_ie_len, u16 status,
4943 gfp_t gfp, bool connect_timeout, tSirResultCodes
4944 timeout_reason, struct fils_join_rsp_params
4945 *roam_fils_params)
4946{
4947 struct cfg80211_connect_resp_params fils_params;
4948 qdf_mem_zero(&fils_params, sizeof(fils_params));
4949
4950 if (!roam_fils_params) {
4951 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4952 } else {
4953 fils_params.status = status;
4954 fils_params.bssid = bssid;
4955 fils_params.timeout_reason = timeout_reason;
4956 fils_params.req_ie = req_ie;
4957 fils_params.req_ie_len = req_ie_len;
4958 fils_params.resp_ie = resp_ie;
4959 fils_params.resp_ie_len = resp_ie_len;
4960 fils_params.bss = bss;
4961 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4962 roam_fils_params->kek_len,
4963 roam_fils_params->fils_pmk,
4964 roam_fils_params->fils_pmk_len,
4965 roam_fils_params->fils_pmkid,
4966 roam_info->fils_seq_num);
4967 }
4968 hdd_debug("FILS indicate connect status %d seq no %d",
4969 fils_params.status,
4970 fils_params.fils_erp_next_seq_num);
4971
4972 cfg80211_connect_done(dev, &fils_params, gfp);
4973
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304974 if (roam_fils_params && roam_fils_params->hlp_data_len)
4975 hdd_update_hlp_info(dev, roam_fils_params);
4976
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304977 /* Clear all the FILS key info */
4978 if (roam_fils_params && roam_fils_params->fils_pmk)
4979 qdf_mem_free(roam_fils_params->fils_pmk);
4980 if (roam_fils_params)
4981 qdf_mem_free(roam_fils_params);
4982 roam_info->fils_join_rsp = NULL;
4983}
4984#else
4985static inline void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4986 struct cfg80211_bss *bss, tCsrRoamInfo
4987 *roam_info, const u8 *req_ie,
4988 size_t req_ie_len, const u8 *resp_ie,
4989 size_t resp_ie_len, u16 status, gfp_t gfp,
4990 bool connect_timeout, tSirResultCodes
4991 timeout_reason, struct fils_join_rsp_params
4992 *roam_fils_params)
4993{ }
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304994
4995static inline void hdd_update_hlp_info(struct net_device *dev,
4996 struct fils_join_rsp_params *roam_fils_params)
4997
4998{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304999#endif
5000#endif
5001
5002#if defined(CFG80211_CONNECT_DONE) && defined(WLAN_FEATURE_FILS_SK)
5003/**
5004 * hdd_fils_update_connect_results() - API to send fils connection status to
5005 * supplicant.
5006 * @dev: network device
5007 * @bssid: bssid to which we want to associate
5008 * @bss: cfg80211 bss info
5009 * @roam_info: information about connected bss
5010 * @req_ie: Request Information Element
5011 * @req_ie_len: len of the req IE
5012 * @resp_ie: Response IE
5013 * @resp_ie_len: len of ht response IE
5014 * @status: status
5015 * @gfp: allocation flags
5016 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5017 * @timeout_reason: reason for connect timeout
5018 *
5019 * The API is a wrapper to send connection status to supplicant
5020 *
5021 * Return: 0 if success else failure
5022 */
5023static int hdd_fils_update_connect_results(struct net_device *dev,
5024 const u8 *bssid,
5025 struct cfg80211_bss *bss,
5026 tCsrRoamInfo *roam_info, const u8 *req_ie,
5027 size_t req_ie_len, const u8 *resp_ie,
5028 size_t resp_ie_len, u16 status, gfp_t gfp,
5029 bool connect_timeout,
5030 tSirResultCodes timeout_reason)
5031{
5032 ENTER();
5033 if (!roam_info || !roam_info->is_fils_connection)
5034 return -EINVAL;
5035
5036 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5037 resp_ie, resp_ie_len, status, gfp, connect_timeout,
5038 timeout_reason, roam_info->fils_join_rsp);
5039 return 0;
5040}
5041#else
5042static inline int hdd_fils_update_connect_results(struct net_device *dev,
5043 const u8 *bssid,
5044 struct cfg80211_bss *bss,
5045 tCsrRoamInfo *roam_info, const u8 *req_ie,
5046 size_t req_ie_len, const u8 *resp_ie,
5047 size_t resp_ie_len, u16 status, gfp_t gfp,
5048 bool connect_timeout,
5049 tSirResultCodes timeout_reason)
5050{
5051 return -EINVAL;
5052}
5053#endif
5054
Anurag Chouhanc4092922016-09-08 15:56:11 +05305055/**
5056 * hdd_connect_result() - API to send connection status to supplicant
5057 * @dev: network device
5058 * @bssid: bssid to which we want to associate
5059 * @roam_info: information about connected bss
5060 * @req_ie: Request Information Element
5061 * @req_ie_len: len of the req IE
5062 * @resp_ie: Response IE
5063 * @resp_ie_len: len of ht response IE
5064 * @status: status
5065 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305066 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305067 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305068 *
5069 * The API is a wrapper to send connection status to supplicant
5070 * and allow runtime suspend
5071 *
5072 * Return: Void
5073 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305074void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5075 tCsrRoamInfo *roam_info, const u8 *req_ie,
5076 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305077 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305078 bool connect_timeout,
5079 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305080{
Jeff Johnson9d295242017-08-29 14:39:48 -07005081 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305082 struct cfg80211_bss *bss = NULL;
5083
5084 if (WLAN_STATUS_SUCCESS == status) {
5085 struct ieee80211_channel *chan;
5086 int freq;
5087 int chan_no = roam_info->pBssDesc->channelId;
5088
5089 if (chan_no <= 14)
5090 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005091 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305092 else
5093 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005094 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305095
5096 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5097 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5098 roam_info->u.pConnectedProfile->SSID.ssId,
5099 roam_info->u.pConnectedProfile->SSID.length);
5100 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305101
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305102 if (hdd_fils_update_connect_results(dev, bssid, bss,
5103 roam_info, req_ie, req_ie_len, resp_ie,
5104 resp_ie_len, status, gfp, connect_timeout,
5105 timeout_reason) != 0) {
5106 hdd_connect_bss(dev, bssid, bss, req_ie,
5107 req_ie_len, resp_ie, resp_ie_len,
5108 status, gfp, connect_timeout, timeout_reason);
5109 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305110
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005111 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005112 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305113}
5114#else
5115void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5116 tCsrRoamInfo *roam_info, const u8 *req_ie,
5117 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305118 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305119 bool connect_timeout,
5120 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305121{
Jeff Johnson9d295242017-08-29 14:39:48 -07005122 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305123
Anurag Chouhanc4092922016-09-08 15:56:11 +05305124 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5125 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005126
5127 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005128 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305129}
5130#endif
5131
5132
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005133QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005134{
5135 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305136 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005137 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305139 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005140#endif
5141 eConnectionState connState;
5142
5143 ENTER();
5144
5145 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305146 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005147 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005148
Arun Khandavallifae92942016-08-01 13:31:08 +05305149 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305150 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305151
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005152 hdd_wmm_init(adapter);
5153
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005154 adapter->scan_info.mScanPending = false;
5155
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005156 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005157 case QDF_STA_MODE:
5158 case QDF_P2P_CLIENT_MODE:
5159 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005160
5161 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5162 ->conn_info.connState;
5163
5164 hdd_init_station_mode(adapter);
5165 /* Open the gates for HDD to receive Wext commands */
5166 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005167
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005168 /* Indicate disconnect event to supplicant
5169 * if associated previously
5170 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005171 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005172 eConnectionState_IbssConnected == connState ||
5173 eConnectionState_NotConnected == connState ||
5174 eConnectionState_IbssDisconnected == connState ||
5175 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005177
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005178 memset(&wrqu, '\0', sizeof(wrqu));
5179 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5180 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5181 wireless_send_event(adapter->dev, SIOCGIWAP,
5182 &wrqu, NULL);
5183 adapter->sessionCtx.station.
5184 hdd_ReassocScenario = false;
5185
5186 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305187 wlan_hdd_cfg80211_indicate_disconnect(
5188 adapter->dev, false,
5189 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005190 } else if (eConnectionState_Connecting == connState) {
5191 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005192 * Indicate connect failure to supplicant if we
5193 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005194 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305195 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305196 NULL, 0, NULL, 0,
5197 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005198 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199 }
5200
5201 hdd_register_tx_flow_control(adapter,
5202 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005203 hdd_tx_resume_cb,
5204 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205
5206 break;
5207
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005208 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005209 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305210 hdd_init_ap_mode(adapter, true);
5211
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005212 break;
5213
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005214 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005215#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005216 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5218#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005219 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005220 /* event supplicant to restart */
5221 cfg80211_del_sta(adapter->dev,
5222 (const u8 *)&bcastMac.bytes[0],
5223 GFP_KERNEL);
5224#endif
5225 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305226 case QDF_MONITOR_MODE:
5227 hdd_init_station_mode(adapter);
5228 hdd_set_mon_rx_cb(adapter->dev);
5229 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5230 adapter->mon_bandwidth);
5231 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005232 default:
5233 break;
5234 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005235 /*
5236 * Action frame registered in one adapter which will
5237 * applicable to all interfaces
5238 */
5239 wlan_hdd_cfg80211_register_frames(adapter);
5240
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305241get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005242 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5243 adapterNode = pNext;
5244 }
5245
5246 EXIT();
5247
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305248 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249}
5250
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005251QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252 hdd_adapter_list_node_t **padapterNode)
5253{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305254 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005255
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005256 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305257 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5258 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005259 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005260 return status;
5261}
5262
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005263QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005264 hdd_adapter_list_node_t *adapterNode,
5265 hdd_adapter_list_node_t **pNextAdapterNode)
5266{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305267 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005268
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005269 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305270 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5271 (qdf_list_node_t *) adapterNode,
5272 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005273
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005274 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005275 return status;
5276}
5277
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005278QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005279 hdd_adapter_list_node_t *adapterNode)
5280{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305281 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005282
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005283 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305284 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005285 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005286 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 return status;
5288}
5289
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005290QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005291 hdd_adapter_list_node_t **padapterNode)
5292{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305293 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005294
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005295 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305296 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5297 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005298 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005299 return status;
5300}
5301
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005302QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005303 hdd_adapter_list_node_t *adapterNode)
5304{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305305 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005306
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005307 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305308 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5309 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005310 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005311 return status;
5312}
5313
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005314QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005315 hdd_adapter_list_node_t *adapterNode)
5316{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305317 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005318
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005319 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305320 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5321 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005322 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005323 return status;
5324}
5325
Jeff Johnson9d295242017-08-29 14:39:48 -07005326struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005327 tSirMacAddr macAddr)
5328{
5329 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005330 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305331 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005332
5333 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5334
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305335 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005336 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005337
5338 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305339 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005340 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005341 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005342
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005343 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5344 adapterNode = pNext;
5345 }
5346
5347 return NULL;
5348
5349}
5350
Jeff Johnson9d295242017-08-29 14:39:48 -07005351struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005352 uint32_t vdev_id)
5353{
5354 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005355 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305356 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005357
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305358 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005359
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305360 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005361 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005362
5363 if (adapter->sessionId == vdev_id)
5364 return adapter;
5365
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305366 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005367 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5368 adapterNode = pNext;
5369 }
5370
Jeff Johnson5880d792016-08-15 13:32:30 -07005371 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005372
5373 return NULL;
5374}
5375
Abhishek Singh7996eb72015-12-30 17:24:02 +05305376/**
5377 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5378 * the sessionid
5379 * @hdd_ctx: hdd context.
5380 * @sme_session_id: sme session is for the adapter to get.
5381 *
5382 * This function is used to get the adapter with provided session id
5383 *
5384 * Return: adapter pointer if found
5385 *
5386 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005387struct hdd_adapter *hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
Abhishek Singh7996eb72015-12-30 17:24:02 +05305388 uint32_t sme_session_id)
5389{
5390 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005391 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305392 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305393
5394
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305395 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305396
5397 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305398 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005399 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305400
5401 if (adapter &&
5402 adapter->sessionId == sme_session_id)
5403 return adapter;
5404
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305405 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305406 hdd_get_next_adapter(hdd_ctx,
5407 adapter_node, &next);
5408 adapter_node = next;
5409 }
5410 return NULL;
5411}
5412
Jeff Johnson9d295242017-08-29 14:39:48 -07005413struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005414 const char *iface_name)
5415{
5416 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005417 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005418 QDF_STATUS qdf_status;
5419
5420 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5421
5422 while ((NULL != adapter_node) &&
5423 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005424 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005425
5426 if (adapter &&
5427 !qdf_str_cmp(adapter->dev->name, iface_name))
5428 return adapter;
5429
5430 qdf_status =
5431 hdd_get_next_adapter(hdd_ctx,
5432 adapter_node, &next);
5433 adapter_node = next;
5434 }
5435 return NULL;
5436}
5437
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005438/**
5439 * hdd_get_adapter() - to get adapter matching the mode
5440 * @hdd_ctx: hdd context
5441 * @mode: adapter mode
5442 *
5443 * This routine will return the pointer to adapter matching
5444 * with the passed mode.
5445 *
5446 * Return: pointer to adapter or null
5447 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005448struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005449 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005450{
5451 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005452 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305453 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005454
5455 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5456
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305457 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005458 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005459
5460 if (adapter && (mode == adapter->device_mode))
5461 return adapter;
5462
5463 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5464 adapterNode = pNext;
5465 }
5466
5467 return NULL;
5468
5469}
5470
5471/**
5472 * hdd_get_operating_channel() - return operating channel of the device mode
5473 * @hdd_ctx: Pointer to the HDD context.
5474 * @mode: Device mode for which operating channel is required.
5475 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005476 * QDF_STA_MODE,
5477 * QDF_P2P_CLIENT_MODE,
5478 * QDF_SAP_MODE,
5479 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005480 *
5481 * This API returns the operating channel of the requested device mode
5482 *
5483 * Return: channel number. "0" id the requested device is not found OR it is
5484 * not connected.
5485 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005486uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005487 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005488{
5489 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305490 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005491 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005492 uint8_t operatingChannel = 0;
5493
5494 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5495
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305496 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005497 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005498
5499 if (mode == adapter->device_mode) {
5500 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005501 case QDF_STA_MODE:
5502 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005503 if (hdd_conn_is_connected
5504 (WLAN_HDD_GET_STATION_CTX_PTR
5505 (adapter))) {
5506 operatingChannel =
5507 (WLAN_HDD_GET_STATION_CTX_PTR
5508 (adapter))->conn_info.
5509 operationChannel;
5510 }
5511 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005512 case QDF_SAP_MODE:
5513 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005514 /* softap connection info */
5515 if (test_bit
5516 (SOFTAP_BSS_STARTED,
5517 &adapter->event_flags))
5518 operatingChannel =
5519 (WLAN_HDD_GET_AP_CTX_PTR
5520 (adapter))->operatingChannel;
5521 break;
5522 default:
5523 break;
5524 }
5525
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005526 /* Found the device of interest. break the loop */
5527 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005528 }
5529
5530 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5531 adapterNode = pNext;
5532 }
5533 return operatingChannel;
5534}
5535
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005536static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005537 hdd_ctx)
5538{
5539 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305540 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005541 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005542
5543 ENTER();
5544
5545 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5546
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305547 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005548 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005549 if ((adapter->device_mode == QDF_STA_MODE) ||
5550 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5551 (adapter->device_mode == QDF_IBSS_MODE) ||
5552 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5553 (adapter->device_mode == QDF_SAP_MODE) ||
5554 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005555 wlan_hdd_cfg80211_deregister_frames(adapter);
5556 hdd_unregister_wext(adapter->dev);
5557 }
5558 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5559 adapterNode = pNext;
5560 }
5561
5562 EXIT();
5563
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305564 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005565}
5566
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005567QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005568{
5569 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305570 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005571 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005572
5573 ENTER();
5574
5575 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5576
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305577 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005578 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005579 if ((adapter->device_mode == QDF_STA_MODE) ||
5580 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5581 (adapter->device_mode == QDF_IBSS_MODE) ||
5582 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5583 (adapter->device_mode == QDF_SAP_MODE) ||
5584 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305585 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5586 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587 }
5588 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5589 adapterNode = pNext;
5590 }
5591
5592 EXIT();
5593
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305594 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005595}
5596
Dustin Brownf27bce82016-11-03 12:52:27 -07005597/**
5598 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5599 * adapters
5600 * @hdd_ctx: The HDD context containing the adapters to operate on
5601 *
5602 * return: QDF_STATUS_SUCCESS
5603 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005604static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005605{
5606 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5607 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005608 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005609 int err;
5610
5611 ENTER();
5612
5613 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5614
5615 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005616 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005617 if ((adapter->device_mode == QDF_STA_MODE) ||
5618 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5619 (adapter->device_mode == QDF_IBSS_MODE) ||
5620 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5621 (adapter->device_mode == QDF_SAP_MODE) ||
5622 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5623 err = wlan_hdd_sched_scan_stop(adapter->dev);
5624 if (err)
5625 hdd_err("Unable to stop scheduled scan");
5626 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005627 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5628 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005629 adapter_node = next_node;
5630 }
5631
5632 EXIT();
5633
5634 return QDF_STATUS_SUCCESS;
5635}
5636
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005637#ifdef WLAN_NS_OFFLOAD
5638/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005639 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005640 * @hdd_ctx: Pointer to hdd context
5641 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005642 * Unregister for IPv6 address change notifications.
5643 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005644 * Return: None
5645 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005646static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005647{
5648 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005649}
5650
5651/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005652 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005653 * @hdd_ctx: Pointer to hdd context
5654 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005655 * Register for IPv6 address change notifications.
5656 *
5657 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005658 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005659static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005660{
5661 int ret;
5662
5663 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5664 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005665 if (ret) {
5666 hdd_err("Failed to register IPv6 notifier: %d", ret);
5667 goto out;
5668 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005669
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005670 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005671out:
5672 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005673}
5674#else
5675/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005676 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005677 * @hdd_ctx: Pointer to hdd context
5678 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005679 * Unregister for IPv6 address change notifications.
5680 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681 * Return: None
5682 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005683static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005684{
5685}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005686
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005687/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005688 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689 * @hdd_ctx: Pointer to hdd context
5690 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005691 * Register for IPv6 address change notifications.
5692 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005693 * Return: None
5694 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005695static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005696{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005697 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005698}
5699#endif
5700
5701/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005702 * hdd_register_notifiers - Register netdev notifiers.
5703 * @hdd_ctx: HDD context
5704 *
5705 * Register netdev notifiers like IPv4 and IPv6.
5706 *
5707 * Return: 0 on success and errno on failure
5708 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005709static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005710{
5711 int ret;
5712
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005713 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5714 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305715 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005716
5717 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5718 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5719 if (ret) {
5720 hdd_err("Failed to register IPv4 notifier: %d", ret);
5721 goto unregister_ip6_notifier;
5722 }
5723
5724 return 0;
5725
5726unregister_ip6_notifier:
5727 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005728out:
5729 return ret;
5730
5731}
5732
5733/**
5734 * hdd_unregister_notifiers - Unregister netdev notifiers.
5735 * @hdd_ctx: HDD context
5736 *
5737 * Unregister netdev notifiers like IPv4 and IPv6.
5738 *
5739 * Return: None.
5740 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005741void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005742{
5743 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5744
5745 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005746}
5747
5748/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005749 * hdd_exit_netlink_services - Exit netlink services
5750 * @hdd_ctx: HDD context
5751 *
5752 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5753 * nl service.
5754 *
5755 * Return: None.
5756 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005757static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005758{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005759 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005760 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005761 ptt_sock_deactivate_svc();
5762
5763 nl_srv_exit();
5764}
5765
5766/**
5767 * hdd_init_netlink_services- Init netlink services
5768 * @hdd_ctx: HDD context
5769 *
5770 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5771 * nl service.
5772 *
5773 * Return: 0 on success and errno on failure.
5774 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005775static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005776{
5777 int ret;
5778
Ryan Hsuceddceb2016-04-28 10:20:14 -07005779 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005780 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005781 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005782 goto out;
5783 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005784 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005785
Naveen Rawat910726a2017-03-06 11:42:51 -08005786 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005787 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005788 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005789 goto err_nl_srv;
5790 }
5791
5792 ret = ptt_sock_activate_svc();
5793 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005794 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005795 goto err_nl_srv;
5796 }
5797
5798 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005799 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005800 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005801
5802 ret = cnss_diag_activate_service();
5803 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005804 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005805 goto err_close_cesium;
5806 }
5807
5808 return 0;
5809
5810err_close_cesium:
5811 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005812 ptt_sock_deactivate_svc();
5813err_nl_srv:
5814 nl_srv_exit();
5815out:
5816 return ret;
5817}
5818
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005819/**
5820 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5821 * @hdd_ctx: HDD context.
5822 *
5823 * Destroy RX wakelock.
5824 *
5825 * Return: None.
5826 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005827static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005828{
5829 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5830}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005831
5832/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005833 * hdd_rx_wake_lock_create() - Create RX wakelock
5834 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005835 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005836 * Create RX wakelock.
5837 *
5838 * Return: None.
5839 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005840static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005841{
5842 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5843}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005844
5845/**
5846 * hdd_roc_context_init() - Init ROC context
5847 * @hdd_ctx: HDD context.
5848 *
5849 * Initialize ROC context.
5850 *
5851 * Return: 0 on success and errno on failure.
5852 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005853static int hdd_roc_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005854{
5855 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5856 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5857
5858 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5859
5860 return 0;
5861}
5862
5863/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305864 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5865 * @hdd_ctx: HDD context.
5866 *
5867 * Free memory allocations made in ROC Req Queue nodes.
5868 *
5869 * Return: None.
5870 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005871static void hdd_destroy_roc_req_q(struct hdd_context *hdd_ctx)
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305872{
Jeff Johnson52b50602017-09-30 17:54:56 -07005873 struct hdd_roc_req *hdd_roc_req;
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305874 QDF_STATUS status;
5875
5876 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5877
5878 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5879 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5880 (qdf_list_node_t **) &hdd_roc_req);
5881
5882 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305883 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5884 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305885 QDF_ASSERT(0);
5886 return;
5887 }
5888
Jeff Johnson44d8af92017-10-02 12:25:55 -07005889 if (hdd_roc_req->remain_chan_ctx)
5890 qdf_mem_free(hdd_roc_req->remain_chan_ctx);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305891
5892 qdf_mem_free(hdd_roc_req);
5893 }
5894
5895 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5896}
5897
5898/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005899 * hdd_roc_context_destroy() - Destroy ROC context
5900 * @hdd_ctx: HDD context.
5901 *
5902 * Destroy roc list and flush the pending roc work.
5903 *
5904 * Return: None.
5905 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005906static void hdd_roc_context_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005907{
5908 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305909 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005910 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005911}
5912
5913/**
Houston Hoffman160db392016-10-10 17:37:51 -07005914 * hdd_context_deinit() - Deinitialize HDD context
5915 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005916 *
Houston Hoffman160db392016-10-10 17:37:51 -07005917 * Deinitialize HDD context along with all the feature specific contexts but
5918 * do not free hdd context itself. Caller of this API is supposed to free
5919 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005920 *
Houston Hoffman160db392016-10-10 17:37:51 -07005921 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005922 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005923static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005924{
Houston Hoffman160db392016-10-10 17:37:51 -07005925 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005926
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005927 hdd_roc_context_destroy(hdd_ctx);
5928
5929 hdd_sap_context_destroy(hdd_ctx);
5930
5931 hdd_rx_wake_lock_destroy(hdd_ctx);
5932
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005933 hdd_scan_context_destroy(hdd_ctx);
5934
5935 qdf_list_destroy(&hdd_ctx->hddAdapters);
5936
Houston Hoffman160db392016-10-10 17:37:51 -07005937 return 0;
5938}
5939
5940/**
5941 * hdd_context_destroy() - Destroy HDD context
5942 * @hdd_ctx: HDD context to be destroyed.
5943 *
5944 * Free config and HDD context as well as destroy all the resources.
5945 *
5946 * Return: None
5947 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005948static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005949{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005950 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305951
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305952 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5953
Houston Hoffman160db392016-10-10 17:37:51 -07005954 hdd_context_deinit(hdd_ctx);
5955
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305956 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005957 hdd_ctx->config = NULL;
5958
5959 wiphy_free(hdd_ctx->wiphy);
5960}
5961
5962/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305963 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5964 *
5965 * This function is used to destroy bug report lock
5966 *
5967 * Return: None
5968 */
5969static void wlan_destroy_bug_report_lock(void)
5970{
5971 p_cds_contextType p_cds_context;
5972
5973 p_cds_context = cds_get_global_context();
5974 if (!p_cds_context) {
5975 hdd_err("cds context is NULL");
5976 return;
5977 }
5978
5979 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5980}
5981
5982/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005983 * hdd_wlan_exit() - HDD WLAN exit function
5984 * @hdd_ctx: Pointer to the HDD Context
5985 *
5986 * This is the driver exit point (invoked during rmmod)
5987 *
5988 * Return: None
5989 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005990static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005991{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305992 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005993 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305994 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005995
5996 ENTER();
5997
Arun Khandavallifae92942016-08-01 13:31:08 +05305998 if (QDF_TIMER_STATE_RUNNING ==
5999 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006000 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05306001 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006002 }
6003
Arun Khandavallifae92942016-08-01 13:31:08 +05306004 if (!QDF_IS_STATUS_SUCCESS
6005 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
6006 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006007
Arun Khandavallifae92942016-08-01 13:31:08 +05306008
6009 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006010
Prashanth Bhattaab004382016-10-11 16:08:11 -07006011 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006012
6013#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306014 if (QDF_TIMER_STATE_RUNNING ==
6015 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6016 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006017 }
6018
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306019 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306020 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006021 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006022 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006023 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6024 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6025 hdd_ctx->last_acs_channel_list = NULL;
6026 hdd_ctx->num_of_channels = 0;
6027 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006028#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006029
Arun Khandavallifae92942016-08-01 13:31:08 +05306030 mutex_lock(&hdd_ctx->iface_change_lock);
6031 driver_status = hdd_ctx->driver_status;
6032 mutex_unlock(&hdd_ctx->iface_change_lock);
6033
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006034 /*
6035 * Powersave Offload Case
6036 * Disable Idle Power Save Mode
6037 */
6038 hdd_set_idle_ps_config(hdd_ctx, false);
6039
Arun Khandavallifae92942016-08-01 13:31:08 +05306040 if (driver_status != DRIVER_MODULES_CLOSED) {
6041 hdd_unregister_wext_all_adapters(hdd_ctx);
6042 /*
6043 * Cancel any outstanding scan requests. We are about to close
6044 * all of our adapters, but an adapter structure is what SME
6045 * passes back to our callback function. Hence if there
6046 * are any outstanding scan requests then there is a
6047 * race condition between when the adapter is closed and
6048 * when the callback is invoked. We try to resolve that
6049 * race condition here by canceling any outstanding scans
6050 * before we close the adapters.
6051 * Note that the scans may be cancelled in an asynchronous
6052 * manner, so ideally there needs to be some kind of
6053 * synchronization. Rather than introduce a new
6054 * synchronization here, we will utilize the fact that we are
6055 * about to Request Full Power, and since that is synchronized,
6056 * the expectation is that by the time Request Full Power has
6057 * completed, all scans will be cancelled
6058 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07006059 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05306060 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006061 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006062 hdd_stop_all_adapters(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006063 }
6064
6065 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306066 * Close the scheduler before calling cds_close to make sure
6067 * no thread is scheduled after the each module close is
6068 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006069 */
Jeff Johnson7d562272017-09-13 15:12:54 -07006070 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306071 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05306072 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306073 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006074 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006075
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306076 unregister_netdevice_notifier(&hdd_netdev_notifier);
6077
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006078 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306079
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306080 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6081 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6082 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6083
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006084 /*
6085 * Close CDS
6086 * This frees pMac(HAL) context. There should not be any call
6087 * that requires pMac access after this.
6088 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006089
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006090 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006091 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006092
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006093 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006094
6095 hdd_ipa_cleanup(hdd_ctx);
6096
6097 /* Free up RoC request queue and flush workqueue */
6098 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006099
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306100 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306101 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306102 /*
6103 * If there is re_init failure wiphy would have already de-registered
6104 * check the wiphy status before un-registering again
6105 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306106 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306107 wiphy_unregister(wiphy);
6108 wlan_hdd_cfg80211_deinit(wiphy);
6109 hdd_lpass_notify_stop(hdd_ctx);
6110 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006111
Arun Khandavallifae92942016-08-01 13:31:08 +05306112 hdd_exit_netlink_services(hdd_ctx);
6113 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306114#ifdef FEATURE_WLAN_CH_AVOID
6115 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6116#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306117
6118 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6119 if (driver_status)
6120 hdd_err("Pdev delete failed");
6121
6122 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6123 if (driver_status)
6124 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006125
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006126 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006127}
6128
6129void __hdd_wlan_exit(void)
6130{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006131 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006132
6133 ENTER();
6134
Anurag Chouhan6d760662016-02-20 16:05:43 +05306135 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006136 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006137 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006138 EXIT();
6139 return;
6140 }
6141
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006142 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306143 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006144
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006145 /* Do all the cleanup before deregistering the driver */
6146 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006147
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006148 EXIT();
6149}
6150
6151#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006152/**
6153 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006154 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006155 *
6156 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6157 * Then new ACS request will do a fresh scan without reusing the cached
6158 * scan information.
6159 *
6160 * Return: void
6161 */
Tang Yingying523322d2017-01-17 23:28:43 +08006162static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006163{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006164 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006165
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006166 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006167 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006168 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6169 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6170 hdd_ctx->last_acs_channel_list = NULL;
6171 hdd_ctx->num_of_channels = 0;
6172 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173
6174 if (!hdd_ctx->hHal)
6175 return;
6176 sme_scan_flush_result(hdd_ctx->hHal);
6177}
6178#endif
6179
6180#ifdef QCA_HT_2040_COEX
6181/**
6182 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
6183 * @adapter: pointer to adapter
6184 * @staId: station id
6185 * @macAddrSTA: station MAC address
6186 * @channel_type: channel type
6187 *
6188 * This function notifies FW with HT20/HT40 mode
6189 *
6190 * Return: 0 if successful, error number otherwise
6191 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006192int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05306193 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006194{
6195 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306196 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006197 struct hdd_context *hdd_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006198
6199 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6200
6201 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306202 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006203 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006205 if (!hdd_ctx->hHal)
6206 return -EINVAL;
6207
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306208 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306210 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006211 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006212 return -EINVAL;
6213 }
6214
6215 return 0;
6216}
6217#endif
6218
6219/**
6220 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6221 * @state: state
6222 *
6223 * This function notifies FW with modem power status
6224 *
6225 * Return: 0 if successful, error number otherwise
6226 */
6227int hdd_wlan_notify_modem_power_state(int state)
6228{
6229 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306230 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006231 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006232
Anurag Chouhan6d760662016-02-20 16:05:43 +05306233 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306235 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006236 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306237
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006238 if (!hdd_ctx->hHal)
6239 return -EINVAL;
6240
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306241 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6242 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006243 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006244 state);
6245 return -EINVAL;
6246 }
6247 return 0;
6248}
6249
6250/**
6251 *
6252 * hdd_post_cds_enable_config() - HDD post cds start config helper
6253 * @adapter - Pointer to the HDD
6254 *
6255 * Return: None
6256 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006257QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006258{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306259 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260
6261 /*
6262 * Send ready indication to the HDD. This will kick off the MAC
6263 * into a 'running' state and should kick off an initial scan.
6264 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306265 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6266 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006267 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6268 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306269 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006270 }
6271
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306272 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006273}
6274
6275/* wake lock APIs for HDD */
6276void hdd_prevent_suspend(uint32_t reason)
6277{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306278 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006279}
6280
6281void hdd_allow_suspend(uint32_t reason)
6282{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306283 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006284}
6285
6286void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6287{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306288 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6289 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006290}
6291
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006292/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006293QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006294{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006295
Amar Singhal6f8592b2017-04-26 14:31:58 -07006296 return sme_init_chan_list(hdd_ctx->hHal,
6297 hdd_ctx->reg.alpha2,
6298 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006299}
6300
6301/**
6302 * hdd_is_5g_supported() - check if hardware supports 5GHz
6303 * @hdd_ctx: Pointer to the hdd context
6304 *
6305 * HDD function to know if hardware supports 5GHz
6306 *
6307 * Return: true if hardware supports 5GHz
6308 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006309bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006310{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006311 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006312 return true;
6313
Amar Singhal58b45ef2017-08-01 13:43:54 -07006314 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006315 return true;
6316 else
6317 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006318}
6319
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006320static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006321{
6322 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006323 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006324
6325 wiphy = hdd_ctx->wiphy;
6326
6327 /*
6328 * The channel information in
6329 * wiphy needs to be initialized before wiphy registration
6330 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006331 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6332 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006333 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006334 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006335 }
6336
6337#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6338 wiphy->wowlan = &wowlan_support_reg_init;
6339#else
6340 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6341 WIPHY_WOWLAN_MAGIC_PKT |
6342 WIPHY_WOWLAN_DISCONNECT |
6343 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6344 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6345 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6346 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6347 WIPHY_WOWLAN_RFKILL_RELEASE;
6348
6349 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6350 WOW_MAX_FILTERS_PER_LIST);
6351 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6352 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6353#endif
6354
6355 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006356 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306357 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006358 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306359 return ret_val;
6360 }
6361
Amar Singhal5cccafe2017-02-15 12:42:58 -08006362 if (!hdd_ctx->reg_offload)
6363 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006364
Amar Singhale4f28ee2015-10-21 14:36:56 -07006365 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366}
6367
Ravi Joshie2331e82015-07-01 18:18:54 -07006368/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006369 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006370 * @hdd_ctx - handle to hdd context
6371 * @tx_packets - transmit packet count
6372 * @rx_packets - receive packet count
6373 *
6374 * The function controls the bus bandwidth and dynamic control of
6375 * tcp delayed ack configuration
6376 *
6377 * Returns: None
6378 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006379#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006380static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006381 const uint64_t tx_packets,
6382 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006383{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006384 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006385 uint64_t temp_rx = 0;
6386 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006387 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006388 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006389 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006390 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006391 uint16_t index = 0;
6392 bool vote_level_change = false;
6393 bool rx_level_change = false;
6394 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006395
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006396 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006397 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006398 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006399 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006400 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006401 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006402 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006403 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006404
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006405 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006406 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6407 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006408 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006409 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006410 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306411 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306412 if (hdd_ctx->hbw_requested) {
6413 pld_remove_pm_qos(hdd_ctx->parent_dev);
6414 hdd_ctx->hbw_requested = false;
6415 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306416 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006417 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306418 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306419 if (!hdd_ctx->hbw_requested) {
6420 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6421 hdd_ctx->hbw_requested = true;
6422 }
6423
Nirav Shah3bbfa512016-05-12 16:43:49 +05306424 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006425 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306426 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006427 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006428 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006429
Mohit Khannaf8f96822017-05-17 17:11:59 -07006430 qdf_dp_trace_throttle_live_mode(
6431 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6432
Mohit Khannae71e2262015-11-10 09:37:24 -08006433 /* fine-tuning parameters for RX Flows */
6434 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6435
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006436 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006437
Ravi Joshifed83572016-10-07 16:20:37 -07006438 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6439 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6440 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6441 next_rx_level = WLAN_SVC_TP_HIGH;
6442 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006443 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006444 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006445 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006446 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006447
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006448 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006449 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450 next_rx_level, temp_rx);
6451 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006452 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006453 /* Send throughput indication only if it is enabled.
6454 * Disabling tcp_del_ack will revert the tcp stack behavior
6455 * to default delayed ack. Note that this will disable the
6456 * dynamic delayed ack mechanism across the system
6457 */
6458 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306459 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6460 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006461 &next_rx_level,
6462 sizeof(next_rx_level));
6463 }
6464
Mohit Khannae71e2262015-11-10 09:37:24 -08006465 /* fine-tuning parameters for TX Flows */
6466 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6467 hdd_ctx->prev_tx = tx_packets;
6468 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6469 next_tx_level = WLAN_SVC_TP_HIGH;
6470 else
6471 next_tx_level = WLAN_SVC_TP_LOW;
6472
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006473 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006474 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6475 next_tx_level, temp_tx);
6476 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006477 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306478 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6479 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006480 &next_tx_level,
6481 sizeof(next_tx_level));
6482 }
6483
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006484 index = hdd_ctx->hdd_txrx_hist_idx;
6485
6486 if (vote_level_change || tx_level_change || rx_level_change) {
6487 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6488 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6489 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6490 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6491 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6492 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6493 hdd_ctx->hdd_txrx_hist_idx++;
6494 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6495 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006496}
6497
6498#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306499static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006500{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006501 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306502 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006503 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306504 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306505 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6506 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006507 uint64_t total_tx = 0, total_rx = 0;
6508 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306509 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306510 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006511 bool connected = false;
6512 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6513
Prashanth Bhattaab004382016-10-11 16:08:11 -07006514 if (wlan_hdd_validate_context(hdd_ctx))
6515 return;
6516
Jingxiang Gec64e1932017-08-22 14:38:59 +08006517 if (hdd_ctx->isWiphySuspended)
6518 goto restart_timer;
6519
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006520 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306521 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006522 status =
6523 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6524
Jeff Johnson57eb2732017-10-02 11:40:20 -07006525 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006526 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006527 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306528 /*
6529 * Validate magic so we don't end up accessing
6530 * an invalid adapter.
6531 */
6532 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6533 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006534
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006535 if ((adapter->device_mode == QDF_STA_MODE ||
6536 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006537 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6538 != eConnectionState_Associated) {
6539
6540 continue;
6541 }
6542
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006543 if ((adapter->device_mode == QDF_SAP_MODE ||
6544 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006545 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6546
6547 continue;
6548 }
6549
6550 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6551 adapter->prev_tx_packets);
6552 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6553 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306554
6555 if (adapter->device_mode == QDF_SAP_MODE ||
6556 adapter->device_mode == QDF_P2P_GO_MODE ||
6557 adapter->device_mode == QDF_IBSS_MODE) {
6558
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006559 ret = cdp_get_intra_bss_fwd_pkts_count(
6560 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306561 adapter->sessionId,
6562 &fwd_tx_packets, &fwd_rx_packets);
6563 if (ret == A_OK) {
6564 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6565 fwd_tx_packets,
6566 adapter->prev_fwd_tx_packets);
6567 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6568 fwd_tx_packets,
6569 adapter->prev_fwd_rx_packets);
6570 }
6571 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006572
6573 total_rx += adapter->stats.rx_packets;
6574 total_tx += adapter->stats.tx_packets;
6575
6576 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6577 adapter->prev_tx_packets = adapter->stats.tx_packets;
6578 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306579 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6580 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006581 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6582 connected = true;
6583 }
6584
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306585 /* add intra bss forwarded tx and rx packets */
6586 tx_packets += fwd_tx_packets_diff;
6587 rx_packets += fwd_rx_packets_diff;
6588
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006589 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6590 tx_packets += (uint64_t)ipa_tx_packets;
6591 rx_packets += (uint64_t)ipa_rx_packets;
6592
6593 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006594 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006595 return;
6596 }
6597
Yuanyuan Liu13738502016-04-06 17:41:37 -07006598 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599
6600 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6601 hdd_ipa_uc_stat_request(adapter, 2);
6602
Jingxiang Gec64e1932017-08-22 14:38:59 +08006603restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006604 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006605 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006606 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306607 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006608 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006609 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006610}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006611
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306612/**
6613 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6614 * @arg: Argument of timer function
6615 *
6616 * Schedule a workqueue in this function where all the processing is done.
6617 *
6618 * Return: None.
6619 */
6620static void __hdd_bus_bw_cbk(void *arg)
6621{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006622 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306623
6624 if (wlan_hdd_validate_context(hdd_ctx))
6625 return;
6626
6627 schedule_work(&hdd_ctx->bus_bw_work);
6628}
6629
6630/**
6631 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6632 * @arg: Argument of timer function
6633 *
6634 * Return: None.
6635 */
6636static void hdd_bus_bw_cbk(void *arg)
6637{
6638 cds_ssr_protect(__func__);
6639 __hdd_bus_bw_cbk(arg);
6640 cds_ssr_unprotect(__func__);
6641}
6642
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006643int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006644{
6645 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306646 INIT_WORK(&hdd_ctx->bus_bw_work,
6647 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006648 hdd_ctx->bus_bw_timer_running = false;
6649 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306650 qdf_timer_init(NULL,
6651 &hdd_ctx->bus_bw_timer,
6652 hdd_bus_bw_cbk, (void *)hdd_ctx,
6653 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006654
6655 return 0;
6656}
6657
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006658void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006659{
Dustin Brownfce08d12017-01-17 16:29:38 -08006660 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006661 hdd_reset_tcp_delack(hdd_ctx);
6662
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006663 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306664 cancel_work_sync(&hdd_ctx->bus_bw_work);
6665 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006666 hdd_ctx->bus_bw_timer_running = false;
6667 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006668}
Lin Baic5c06882017-09-21 13:58:43 +08006669
6670void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6671{
6672 if (hdd_ctx)
6673 cancel_work_sync(&hdd_ctx->bus_bw_work);
6674}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006675#endif
6676
6677/**
Nirav Shahed34b212016-04-25 10:59:16 +05306678 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6679 * @hdd_ctx: hdd context
6680 *
6681 * Return: 0 for success or error code
6682 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006683static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306684{
6685 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6686 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6687 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006688 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306689 return -ENOMEM;
6690 }
6691 return 0;
6692}
6693
6694/**
6695 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6696 * @hdd_ctx: hdd context
6697 *
6698 * Return: none
6699 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006700void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306701{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306702 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6703 return;
6704
6705 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6706 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306707}
6708
Nirav Shahda008342016-05-17 18:50:40 +05306709static uint8_t *convert_level_to_string(uint32_t level)
6710{
6711 switch (level) {
6712 /* initialize the wlan sub system */
6713 case WLAN_SVC_TP_NONE:
6714 return "NONE";
6715 case WLAN_SVC_TP_LOW:
6716 return "LOW";
6717 case WLAN_SVC_TP_MEDIUM:
6718 return "MED";
6719 case WLAN_SVC_TP_HIGH:
6720 return "HIGH";
6721 default:
6722 return "INVAL";
6723 }
6724}
6725
Nirav Shahed34b212016-04-25 10:59:16 +05306726
6727/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006728 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6729 * @hdd_ctx: hdd context
6730 *
6731 * Return: none
6732 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006733void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006734{
6735 int i;
6736
6737#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006738 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306739 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006740 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006741 hdd_ctx->config->busBandwidthHighThreshold,
6742 hdd_ctx->config->busBandwidthMediumThreshold,
6743 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006744 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306745 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006746 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006747 hdd_ctx->config->tcpDelackThresholdHigh,
6748 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006749 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306750 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006751#endif
6752
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006753 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306754 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6755
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006756 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006757
6758 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006759 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006760 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006761 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006762 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6763 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006764 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006765 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6766 convert_level_to_string(
6767 hdd_ctx->hdd_txrx_hist[i].
6768 next_vote_level),
6769 convert_level_to_string(
6770 hdd_ctx->hdd_txrx_hist[i].
6771 next_rx_level),
6772 convert_level_to_string(
6773 hdd_ctx->hdd_txrx_hist[i].
6774 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775 }
Mohit Khannac68622e2017-01-31 21:07:12 -08006776
6777 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778}
6779
6780/**
6781 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6782 * @hdd_ctx: hdd context
6783 *
6784 * Return: none
6785 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006786void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006787{
6788 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306789 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6790 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006791}
6792
6793/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006794 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006795 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006796 *
6797 * Return: none
6798 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006799void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800{
6801
Jeff Johnson9d295242017-08-29 14:39:48 -07006802 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006803 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306804 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006805 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306806 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807
6808 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306809 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006810 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006811
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006812 hdd_debug("Netif queue operation statistics:");
6813 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306814 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006815 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306816 curr_time = qdf_system_ticks();
6817 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306818 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306819 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306820 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306821 unpause = adapter->total_unpause_time;
6822 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306823 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306824 pause = adapter->total_pause_time;
6825 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006826 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306827 qdf_system_ticks_to_msecs(total),
6828 qdf_system_ticks_to_msecs(pause),
6829 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006830 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006831
Nirav Shahda008342016-05-17 18:50:40 +05306832 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6833 qdf_time_t pause_delta = 0;
6834
6835 if (adapter->pause_map & (1 << i))
6836 pause_delta = delta;
6837
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006838 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006839 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006840 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006841 hdd_reason_type_to_string(i),
6842 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306843 adapter->queue_oper_stats[i].unpause_count,
6844 qdf_system_ticks_to_msecs(
6845 adapter->queue_oper_stats[i].total_pause_time +
6846 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006847 }
6848
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006849 hdd_debug("Netif queue operation history:");
6850 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306851 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6852
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006853 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006854
6855 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006856 /* using hdd_log to avoid printing function name */
6857 if (adapter->queue_oper_history[i].time == 0)
6858 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006859 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006860 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306861 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862 adapter->queue_oper_history[i].time),
6863 hdd_action_type_to_string(
6864 adapter->queue_oper_history[i].netif_action),
6865 hdd_reason_type_to_string(
6866 adapter->queue_oper_history[i].netif_reason),
6867 adapter->queue_oper_history[i].pause_map);
6868 }
6869
6870 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6871 adapter_node = next;
6872 }
6873
6874
6875}
6876
6877/**
6878 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6879 * @hdd_ctx: hdd context
6880 *
6881 * Return: none
6882 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006883void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006884{
Jeff Johnson9d295242017-08-29 14:39:48 -07006885 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006886 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306887 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888
6889 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306890 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006891 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006892
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306893 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006894 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306895 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006896 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306897 adapter->history_index = 0;
6898 adapter->start_time = adapter->last_time = qdf_system_ticks();
6899 adapter->total_pause_time = 0;
6900 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006901 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6902 adapter_node = next;
6903 }
6904}
6905
6906/**
6907 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6908 * @halHandle: Hal handle
6909 * @pContext: Pointer to the context
6910 * @sessionId: Session ID
6911 * @scanId: Scan ID
6912 * @status: Status
6913 *
6914 * This is the callback to be executed when 11d scan is completed to flush out
6915 * the scan results
6916 *
6917 * 11d scan is done during driver load and is a passive scan on all
6918 * channels supported by the device, 11d scans may find some APs on
6919 * frequencies which are forbidden to be used in the regulatory domain
6920 * the device is operating in. If these APs are notified to the supplicant
6921 * it may try to connect to these APs, thus flush out all the scan results
6922 * which are present in SME after 11d scan is done.
6923 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306924 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006925 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306926static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006927 uint8_t sessionId, uint32_t scanId,
6928 eCsrScanStatus status)
6929{
6930 ENTER();
6931
6932 sme_scan_flush_result(halHandle);
6933
6934 EXIT();
6935
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306936 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006937}
6938
6939#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6940/**
6941 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6942 * @hdd_ctx: hdd global context
6943 *
6944 * Return: none
6945 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006946static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006947{
6948 uint8_t i;
6949
6950 mutex_init(&hdd_ctx->op_ctx.op_lock);
6951 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6952 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6953 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6954 }
6955}
6956#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006957static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006958{
6959}
6960#endif
6961
Yingying Tang95409972016-10-20 15:16:15 +08006962#ifdef WLAN_FEATURE_WOW_PULSE
6963/**
6964 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006965 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006966 * @enable: enable or disable this behaviour
6967 *
6968 * Return: int
6969 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006970static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006971{
6972 struct hdd_config *pcfg_ini = phddctx->config;
6973 struct wow_pulse_mode wow_pulse_set_info;
6974 QDF_STATUS status;
6975
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006976 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006977
6978 if (false == phddctx->config->wow_pulse_support)
6979 return 0;
6980
6981 /* prepare the request to send to SME */
6982 if (enable == true) {
6983 wow_pulse_set_info.wow_pulse_enable = true;
6984 wow_pulse_set_info.wow_pulse_pin =
6985 pcfg_ini->wow_pulse_pin;
6986 wow_pulse_set_info.wow_pulse_interval_low =
6987 pcfg_ini->wow_pulse_interval_low;
6988 wow_pulse_set_info.wow_pulse_interval_high =
6989 pcfg_ini->wow_pulse_interval_high;
6990 } else {
6991 wow_pulse_set_info.wow_pulse_enable = false;
6992 wow_pulse_set_info.wow_pulse_pin = 0;
6993 wow_pulse_set_info.wow_pulse_interval_low = 0;
6994 wow_pulse_set_info.wow_pulse_interval_high = 0;
6995 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006996 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006997 wow_pulse_set_info.wow_pulse_enable,
6998 wow_pulse_set_info.wow_pulse_pin,
6999 wow_pulse_set_info.wow_pulse_interval_low,
7000 wow_pulse_set_info.wow_pulse_interval_high);
7001
7002 status = sme_set_wow_pulse(&wow_pulse_set_info);
7003 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007004 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007005 return -EIO;
7006 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007007 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007008 return 0;
7009}
7010#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007011static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007012{
7013 return 0;
7014}
7015#endif
7016
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007017#ifdef WLAN_FEATURE_FASTPATH
7018/**
7019 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7020 * @hdd_cfg: hdd config
7021 * @context: lower layer context
7022 *
7023 * Return: none
7024 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307025void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007026 void *context)
7027{
7028 if (hdd_cfg->fastpath_enable)
7029 hif_enable_fastpath(context);
7030}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007031#endif
7032
Yuanyuan Liu13738502016-04-06 17:41:37 -07007033#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007034/**
7035 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007036 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007037 * @level: thermal level
7038 *
7039 * Change IPA data path to SW path when the thermal throttle level greater
7040 * than 0, and restore the original data path when throttle level is 0
7041 *
7042 * Return: none
7043 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007044static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007045{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007046 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007047
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007048 /* Change IPA to SW path when throttle level greater than 0 */
7049 if (level > THROTTLE_LEVEL_0)
7050 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7051 else
7052 /* restore original concurrency mode */
7053 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7054}
7055
7056/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307057 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7058 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307059 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007060 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307061 * Get a safe channel to restart SAP. PCL already takes into account the
7062 * unsafe channels. So, the PCL is validated with the ACS range to provide
7063 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007064 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307065 * Return: Channel number to restart SAP in case of success. In case of any
7066 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007067 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307068static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007069 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007070{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307071 struct sir_pcl_list pcl;
7072 QDF_STATUS status;
7073 uint32_t i, j;
7074 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007075 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307076 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007077
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307078 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7079 if (!hdd_ctx) {
7080 hdd_err("invalid HDD context");
7081 return INVALID_CHANNEL_ID;
7082 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007083
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307084 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7085 if (!hal_handle) {
7086 hdd_err("invalid HAL handle");
7087 return INVALID_CHANNEL_ID;
7088 }
7089
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007090 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7091 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007092 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7093 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307094 if (QDF_IS_STATUS_ERROR(status)) {
7095 hdd_err("Get PCL failed");
7096 return INVALID_CHANNEL_ID;
7097 }
7098
Frank Liudc2cefb2017-06-21 15:38:18 +08007099 /*
7100 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7101 * channel is unsafe channel, the pcl may be empty, instead of return,
7102 * try to choose a safe channel from acs range.
7103 */
7104 if (!pcl.pcl_len)
7105 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307106
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007107 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307108 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7109 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7110
7111 /* PCL already takes unsafe channel into account */
7112 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007113 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307114 if ((pcl.pcl_list[i] >=
7115 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7116 (pcl.pcl_list[i] <=
7117 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007118 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307119 return pcl.pcl_list[i];
7120 }
7121 }
7122
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007123 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307124
7125 /* Try for safe channel from all valid channel */
7126 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007127 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307128 &pcl.pcl_len);
7129 if (QDF_IS_STATUS_ERROR(status)) {
7130 hdd_err("error in getting valid channel list");
7131 return INVALID_CHANNEL_ID;
7132 }
7133
7134 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007135 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307136 found = false;
7137 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007138 if (pcl.pcl_list[i] ==
7139 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007140 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307141 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007142 break;
7143 }
7144 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307145
7146 if (found)
7147 continue;
7148
7149 if ((pcl.pcl_list[i] >=
7150 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7151 (pcl.pcl_list[i] <=
7152 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007153 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307154 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007155 }
7156 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307157
7158 return INVALID_CHANNEL_ID;
7159}
7160
7161/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007162 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307163 * @adapter: AP adapter
7164 * @channel: Channel
7165 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007166 * Moves the SAP interface by invoking the function which
7167 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307168 *
7169 * Return: None
7170 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007171void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307172{
Jeff Johnson87251032017-08-29 13:31:11 -07007173 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307174 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007175 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307176
7177 if (!adapter) {
7178 hdd_err("invalid adapter");
7179 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007180 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307181
7182 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7183
7184 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7185 if (!hal_handle) {
7186 hdd_err("invalid HAL handle");
7187 return;
7188 }
7189
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007190 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7191
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307192 hdd_ap_ctx->sapConfig.channel = channel;
7193 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7194 hdd_ap_ctx->sapConfig.ch_width_orig;
7195
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007196 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307197 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7198
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007199 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7200 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307201 hdd_ap_ctx->sapConfig.sec_ch,
7202 &hdd_ap_ctx->sapConfig.ch_params);
7203
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007204 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7205 adapter->sessionId, channel,
7206 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007207}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307208
Jeff Johnson9d295242017-08-29 14:39:48 -07007209int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307210{
7211 struct hdd_external_acs_timer_context *timer_context;
7212
7213 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7214
7215 if (QDF_TIMER_STATE_RUNNING ==
7216 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7217 ap.vendor_acs_timer)) {
7218 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7219 }
7220 timer_context = (struct hdd_external_acs_timer_context *)
7221 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7222 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307223 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307224 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307225 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7226 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307227 hdd_notice("Updated ACS config to nl with reason %d", reason);
7228
7229 return 0;
7230}
7231
Agrawal Ashish467dde42016-09-08 18:44:22 +05307232/**
7233 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7234 * @hdd_ctx: hdd context pointer
7235 *
7236 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7237 * and if ACS is enabled, driver will ask userspace to restart the
7238 * sap. User space on LTE coex indication restart driver.
7239 *
7240 * Return - none
7241 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007242void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307243{
7244 QDF_STATUS status;
7245 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007246 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307247 uint32_t i;
7248 bool found = false;
7249 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007250
Agrawal Ashish467dde42016-09-08 18:44:22 +05307251 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7252 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007253 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307254
7255 if (!adapter_temp) {
7256 hdd_err("adapter is NULL, moving to next one");
7257 goto next_adapater;
7258 }
7259
7260 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7261 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007262 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307263 adapter_temp->device_mode,
7264 adapter_temp->sessionCtx.ap.sapConfig.
7265 acs_cfg.acs_mode);
7266 goto next_adapater;
7267 }
7268
7269 found = false;
7270 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007271 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307272 hdd_ctxt->unsafe_channel_list[i]) {
7273 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007274 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307275 adapter_temp->sessionCtx.ap.operatingChannel);
7276 break;
7277 }
7278 }
7279
7280 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007281 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307282 adapter_temp->sessionCtx.ap.operatingChannel);
7283 goto next_adapater;
7284 }
7285
Kapil Gupta8878ad92017-02-13 11:56:04 +05307286 if (hdd_ctxt->config->vendor_acs_support &&
7287 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7288 hdd_update_acs_timer_reason(adapter_temp,
7289 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7290 goto next_adapater;
7291 } else
7292 restart_chan =
7293 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307294 adapter_temp);
7295 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007296 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307297 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007298 /*
7299 * SAP restart due to unsafe channel. While
7300 * restarting the SAP, make sure to clear
7301 * acs_channel, channel to reset to
7302 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307303 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007304 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307305 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7306 adapter_temp->sessionCtx.ap.sapConfig.channel =
7307 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007308 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307309 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7310 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007311 hdd_debug("driver to start sap: %d",
7312 hdd_ctxt->config->sap_internal_restart);
7313 if (hdd_ctxt->config->sap_internal_restart)
7314 hdd_switch_sap_channel(adapter_temp, restart_chan);
7315 else
7316 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307317 }
7318
7319next_adapater:
7320 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7321 adapter_node = next;
7322 }
7323}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307324
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007325/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007326 * hdd_init_channel_avoidance() - Initialize channel avoidance
7327 * @hdd_ctx: HDD global context
7328 *
7329 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007330 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007331 * down to the lower layers. Then subscribe to subsequent channel
7332 * avoidance events.
7333 *
7334 * Return: None
7335 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007336static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007337{
7338 uint16_t unsafe_channel_count;
7339 int index;
7340
Yuanyuan Liu13738502016-04-06 17:41:37 -07007341 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7342 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007343 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007344 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007345
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007346 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007347 hdd_ctx->unsafe_channel_count);
7348
Anurag Chouhan6d760662016-02-20 16:05:43 +05307349 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007350 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007351
7352 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007353 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007354 hdd_ctx->unsafe_channel_list[index]);
7355
7356 }
7357
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007358}
Dustin Brown676a2322017-08-15 13:16:13 -07007359
Jeff Johnson9d295242017-08-29 14:39:48 -07007360static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007361 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007362{
7363 uint8_t restart_chan;
7364
7365 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7366 if (!restart_chan) {
7367 hdd_alert("fail to restart SAP");
7368 return;
7369 }
7370
7371 /* SAP restart due to unsafe channel. While restarting
7372 * the SAP, make sure to clear acs_channel, channel to
7373 * reset to 0. Otherwise these settings will override
7374 * the ACS while restart.
7375 */
7376 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7377 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7378
7379 hdd_debug("sending coex indication");
7380
7381 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7382 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7383 hdd_switch_sap_channel(adapter, restart_chan);
7384}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007385
7386int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7387 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7388{
7389 uint32_t size;
7390 uint16_t *unsafe_list;
7391 uint16_t chan_count;
7392
7393 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7394 return -EINVAL;
7395
7396 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7397 NUM_CHANNELS);
7398 if (chan_count) {
7399 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7400 unsafe_list = qdf_mem_malloc(size);
7401 if (!unsafe_list) {
7402 hdd_err("No memory for unsafe chan list size%d",
7403 size);
7404 return -ENOMEM;
7405 }
7406 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7407 } else {
7408 unsafe_list = NULL;
7409 }
7410
7411 *local_unsafe_list = unsafe_list;
7412 *local_unsafe_list_count = chan_count;
7413
7414 return 0;
7415}
7416
7417bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7418 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7419{
7420 int i, j;
7421
7422 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7423 return true;
7424 if (local_unsafe_list_count == 0)
7425 return false;
7426 for (i = 0; i < local_unsafe_list_count; i++) {
7427 for (j = 0; j < local_unsafe_list_count; j++)
7428 if (local_unsafe_list[i] ==
7429 hdd_ctx->unsafe_channel_list[j])
7430 break;
7431 if (j >= local_unsafe_list_count)
7432 break;
7433 }
7434 if (i >= local_unsafe_list_count) {
7435 hdd_info("unsafe chan list same");
7436 return false;
7437 }
7438
7439 return true;
7440}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007441#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007442static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007443{
7444}
Dustin Brown676a2322017-08-15 13:16:13 -07007445
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007446static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007447{
7448}
Dustin Brown676a2322017-08-15 13:16:13 -07007449
Jeff Johnson9d295242017-08-29 14:39:48 -07007450static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007451 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007452{
7453 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7454}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007455#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007456
7457/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007458 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7459 * user space
7460 * @frame_ind: Management frame data to be informed.
7461 *
7462 * This function is used to indicate management frame to
7463 * user space
7464 *
7465 * Return: None
7466 *
7467 */
7468void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7469{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007470 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007471 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007472 int i;
7473
Rajeev Kumard004abc2016-02-17 12:09:56 -08007474 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007475 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007476
7477 if (0 != wlan_hdd_validate_context(hdd_ctx))
7478 return;
7479
7480 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7481 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7482 adapter =
7483 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7484 if (adapter)
7485 break;
7486 }
7487 } else {
7488 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7489 frame_ind->sessionId);
7490 }
7491
7492 if ((NULL != adapter) &&
7493 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7494 __hdd_indicate_mgmt_frame(adapter,
7495 frame_ind->frame_len,
7496 frame_ind->frameBuf,
7497 frame_ind->frameType,
7498 frame_ind->rxChan,
7499 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007500}
7501
Kapil Gupta8878ad92017-02-13 11:56:04 +05307502void hdd_acs_response_timeout_handler(void *context)
7503{
7504 struct hdd_external_acs_timer_context *timer_context =
7505 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007506 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007507 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307508 uint8_t reason;
7509
7510 ENTER();
7511 if (!timer_context) {
7512 hdd_err("invlaid timer context");
7513 return;
7514 }
7515 adapter = timer_context->adapter;
7516 reason = timer_context->reason;
7517
7518
7519 if ((!adapter) ||
7520 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7521 hdd_err("invalid adapter or adapter has invalid magic");
7522 return;
7523 }
7524 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7525 if (wlan_hdd_validate_context(hdd_ctx))
7526 return;
7527
7528 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7529 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7530 else
7531 return;
7532
7533 hdd_err("ACS timeout happened for %s reason %d",
7534 adapter->dev->name, reason);
7535 switch (reason) {
7536 /* SAP init case */
7537 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7538 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7539 false);
7540 wlan_hdd_cfg80211_start_acs(adapter);
7541 break;
7542 /* DFS detected on current channel */
7543 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7544 wlan_sap_update_next_channel(
7545 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7546 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7547 adapter->sessionId);
7548 break;
7549 /* LTE coex event on current channel */
7550 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7551 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7552 break;
7553 default:
7554 hdd_info("invalid reason for timer invoke");
7555
7556 }
7557}
7558
Rajeev Kumard004abc2016-02-17 12:09:56 -08007559/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007560 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7561 * @hdd_ctx: HDD context
7562 *
7563 * Disables all the dual mac features like DBS, Agile DFS etc.
7564 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307565 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007566 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007567static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007568{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007569 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307570 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007571
7572 if (!hdd_ctx) {
7573 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307574 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007575 }
7576
7577 cfg.scan_config = 0;
7578 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007579 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007580
7581 hdd_debug("Disabling all dual mac features...");
7582
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007583 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307584 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007585 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7586 return status;
7587 }
7588
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307589 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007590}
7591
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007592static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007593wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007594{
7595 struct policy_mgr_dual_mac_config cfg = {0};
7596 QDF_STATUS status;
7597
7598 if (!hdd_ctx) {
7599 hdd_err("HDD context is NULL");
7600 return QDF_STATUS_E_FAILURE;
7601 }
7602
7603 cfg.scan_config = 0;
7604 cfg.fw_mode_config = 0;
7605 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7606 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7607 hdd_ctx->hdd_psoc, &cfg.scan_config,
7608 &cfg.fw_mode_config,
7609 hdd_ctx->config->dual_mac_feature_disable);
7610
7611 if (status != QDF_STATUS_SUCCESS) {
7612 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7613 status);
7614 return status;
7615 }
7616
7617 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7618 cfg.scan_config, cfg.fw_mode_config);
7619
7620 status = sme_soc_set_dual_mac_config(cfg);
7621 if (status != QDF_STATUS_SUCCESS) {
7622 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7623 return status;
7624 }
7625
7626 return QDF_STATUS_SUCCESS;
7627}
7628
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007629/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007630 * hdd_override_ini_config - Override INI config
7631 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007632 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007633 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007634 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007635 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007636 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007637static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007638{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007639
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007640 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7641 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007642 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007643 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007644 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007645 if (0 == enable_11d || 1 == enable_11d) {
7646 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007647 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007648 }
Leo Chang11545d62016-10-17 14:53:50 -07007649
7650 if (!hdd_ipa_is_present(hdd_ctx))
7651 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007652}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007653
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007654/**
7655 * hdd_set_trace_level_for_each - Set trace level for each INI config
7656 * @hdd_ctx - HDD context
7657 *
7658 * Set trace level for each module based on INI config.
7659 *
7660 * Return: None
7661 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007662static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007663{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307664 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7665 hdd_ctx->config->qdf_trace_enable_wdi);
7666 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7667 hdd_ctx->config->qdf_trace_enable_hdd);
7668 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7669 hdd_ctx->config->qdf_trace_enable_sme);
7670 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7671 hdd_ctx->config->qdf_trace_enable_pe);
7672 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7673 hdd_ctx->config->qdf_trace_enable_wma);
7674 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7675 hdd_ctx->config->qdf_trace_enable_sys);
7676 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7677 hdd_ctx->config->qdf_trace_enable_qdf);
7678 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7679 hdd_ctx->config->qdf_trace_enable_sap);
7680 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7681 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7682 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7683 hdd_ctx->config->qdf_trace_enable_bmi);
7684 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7685 hdd_ctx->config->qdf_trace_enable_cfg);
7686 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7687 hdd_ctx->config->qdf_trace_enable_epping);
7688 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7689 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7690 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007691 hdd_ctx->config->qdf_trace_enable_txrx);
7692 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7693 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307694 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7695 hdd_ctx->config->qdf_trace_enable_htc);
7696 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7697 hdd_ctx->config->qdf_trace_enable_hif);
7698 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7699 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7700 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7701 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007702 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7703 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007704 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7705 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007706 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7707 hdd_ctx->config->qdf_trace_enable_regulatory);
7708
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007709 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007710}
7711
7712/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007713 * hdd_context_init() - Initialize HDD context
7714 * @hdd_ctx: HDD context.
7715 *
7716 * Initialize HDD context along with all the feature specific contexts.
7717 *
7718 * return: 0 on success and errno on failure.
7719 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007720static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007721{
7722 int ret;
7723
7724 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7725 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7726
7727 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307728 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007729
7730 init_completion(&hdd_ctx->mc_sus_event_var);
7731 init_completion(&hdd_ctx->ready_to_suspend);
7732
7733 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307734 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007735 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307736
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007737 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7738
7739 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7740
7741 ret = hdd_scan_context_init(hdd_ctx);
7742 if (ret)
7743 goto list_destroy;
7744
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007745 hdd_rx_wake_lock_create(hdd_ctx);
7746
7747 ret = hdd_sap_context_init(hdd_ctx);
7748 if (ret)
7749 goto scan_destroy;
7750
7751 ret = hdd_roc_context_init(hdd_ctx);
7752 if (ret)
7753 goto sap_destroy;
7754
7755 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7756
7757 hdd_init_offloaded_packets_ctx(hdd_ctx);
7758
7759 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7760 hdd_ctx->config);
7761 if (ret)
7762 goto roc_destroy;
7763
7764 return 0;
7765
7766roc_destroy:
7767 hdd_roc_context_destroy(hdd_ctx);
7768
7769sap_destroy:
7770 hdd_sap_context_destroy(hdd_ctx);
7771
7772scan_destroy:
7773 hdd_scan_context_destroy(hdd_ctx);
7774 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007775list_destroy:
7776 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007777
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007778 return ret;
7779}
7780
7781/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307782 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7783 * @hdd_ctx: pointer to hdd context
7784 *
7785 * Return: status of initialization
7786 * 0 - success
7787 * negative value - failure
7788 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007789static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307790{
7791 int ret;
7792
7793 if (!hdd_ctx->config->probe_req_ie_whitelist)
7794 return 0;
7795
7796 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7797 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7798 hdd_ctx->config->probe_req_ie_whitelist = false;
7799 return -EINVAL;
7800 }
7801
7802 /* parse ini string probe req oui */
7803 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7804 if (ret) {
7805 hdd_err("parsing error: disable ie whitelisting");
7806 hdd_ctx->config->probe_req_ie_whitelist = false;
7807 }
7808
7809 return ret;
7810}
7811
7812/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007813 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307814 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007815 *
7816 * Allocate and initialize HDD context. HDD context is allocated as part of
7817 * wiphy allocation and then context is initialized.
7818 *
7819 * Return: HDD context on success and ERR_PTR on failure
7820 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007821static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007822{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307823 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007824 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007825 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007826
7827 ENTER();
7828
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007829 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007830 if (hdd_ctx == NULL) {
7831 ret = -ENOMEM;
7832 goto err_out;
7833 }
7834
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007835 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307836 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007837
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307838 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007839 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007840 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007841 ret = -ENOMEM;
7842 goto err_free_hdd_context;
7843 }
7844
7845 /* Read and parse the qcom_cfg.ini file */
7846 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307847 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307848 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007849 WLAN_INI_FILE);
7850 ret = -EINVAL;
7851 goto err_free_config;
7852 }
7853
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307854 ie_whitelist_attrs_init(hdd_ctx);
7855
Dustin Brown7f939932017-05-18 15:02:17 -07007856 hdd_debug("setting timer multiplier: %u",
7857 hdd_ctx->config->timer_multiplier);
7858 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7859
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007860
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307861 if (hdd_ctx->config->fhostNSOffload)
7862 hdd_ctx->ns_offload_enable = true;
7863
Abhishek Singh5ea86532016-04-27 14:10:53 +05307864 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7865
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007866 hdd_override_ini_config(hdd_ctx);
7867
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007868 ret = hdd_context_init(hdd_ctx);
7869
7870 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007871 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007872
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007873 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307874 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007875
Anurag Chouhan6d760662016-02-20 16:05:43 +05307876 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007877 goto skip_multicast_logging;
7878
7879 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7880
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007881 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7882 if (ret)
7883 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307884
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007885 ret = hdd_init_netlink_services(hdd_ctx);
7886 if (ret)
7887 goto err_deinit_txrx_histogram;
7888
Dustin Brown7b3dea22017-07-10 13:02:47 -07007889 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7890 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307891
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007892skip_multicast_logging:
7893 hdd_set_trace_level_for_each(hdd_ctx);
7894
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007895 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7896
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007897 EXIT();
7898
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007899 return hdd_ctx;
7900
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007901err_deinit_txrx_histogram:
7902 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7903
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007904err_deinit_hdd_context:
7905 hdd_context_deinit(hdd_ctx);
7906
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007907err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307908 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007909
7910err_free_hdd_context:
7911 wiphy_free(hdd_ctx->wiphy);
7912
7913err_out:
7914 return ERR_PTR(ret);
7915}
7916
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007917#ifdef WLAN_OPEN_P2P_INTERFACE
7918/**
7919 * hdd_open_p2p_interface - Open P2P interface
7920 * @hdd_ctx: HDD context
7921 * @rtnl_held: True if RTNL lock held
7922 *
7923 * Open P2P interface during probe. This function called to open the P2P
7924 * interface at probe along with STA interface.
7925 *
7926 * Return: 0 on success and errno on failure
7927 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007928static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007929{
Jeff Johnson9d295242017-08-29 14:39:48 -07007930 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007931 uint8_t *p2p_dev_addr;
7932
7933 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7934 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307935 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007936 hdd_ctx->config->intfMacAddr[0].bytes,
7937 sizeof(tSirMacAddr));
7938
7939 /*
7940 * Generate the P2P Device Address. This consists of
7941 * the device's primary MAC address with the locally
7942 * administered bit set.
7943 */
7944 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7945 } else {
7946 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7947 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007948 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007949 return -ENOSPC;
7950 }
7951
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307952 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307953 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007954 }
7955
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007956 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007957 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007958 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007959
7960 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007961 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007962 return -ENOSPC;
7963 }
7964
7965 return 0;
7966}
7967#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007968static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007969 bool rtnl_held)
7970{
7971 return 0;
7972}
7973#endif
7974
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007975static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007976{
Jeff Johnson9d295242017-08-29 14:39:48 -07007977 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007978 int ret = 0;
7979
7980 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7981 wlan_hdd_get_intf_addr(hdd_ctx),
7982 NET_NAME_UNKNOWN, rtnl_held);
7983 if (adapter == NULL) {
7984 hdd_err("Failed to open 802.11p interface");
7985 ret = -ENOSPC;
7986 }
7987
7988 return ret;
7989}
7990
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007991/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307992 * hdd_start_station_adapter()- Start the Station Adapter
7993 * @adapter: HDD adapter
7994 *
7995 * This function initializes the adapter for the station mode.
7996 *
7997 * Return: 0 on success or errno on failure.
7998 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007999int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308000{
8001 QDF_STATUS status;
8002
8003 ENTER_DEV(adapter->dev);
8004
8005 status = hdd_init_station_mode(adapter);
8006
8007 if (QDF_STATUS_SUCCESS != status) {
8008 hdd_err("Error Initializing station mode: %d", status);
8009 return qdf_status_to_os_return(status);
8010 }
8011
Arun Khandavallifae92942016-08-01 13:31:08 +05308012 hdd_register_tx_flow_control(adapter,
8013 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008014 hdd_tx_resume_cb,
8015 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308016
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308017 EXIT();
8018 return 0;
8019}
8020
8021/**
8022 * hdd_start_ap_adapter()- Start AP Adapter
8023 * @adapter: HDD adapter
8024 *
8025 * This function initializes the adapter for the AP mode.
8026 *
8027 * Return: 0 on success errno on failure.
8028 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008029int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308030{
8031 QDF_STATUS status;
8032
8033 ENTER();
8034
Arun Khandavallicc544b32017-01-30 19:52:16 +05308035 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308036
8037 if (QDF_STATUS_SUCCESS != status) {
8038 hdd_err("Error Initializing the AP mode: %d", status);
8039 return qdf_status_to_os_return(status);
8040 }
8041
Arun Khandavallifae92942016-08-01 13:31:08 +05308042 hdd_register_tx_flow_control(adapter,
8043 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008044 hdd_softap_tx_resume_cb,
8045 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308046
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308047 EXIT();
8048 return 0;
8049}
8050
8051/**
8052 * hdd_start_ftm_adapter()- Start FTM adapter
8053 * @adapter: HDD adapter
8054 *
8055 * This function initializes the adapter for the FTM mode.
8056 *
8057 * Return: 0 on success or errno on failure.
8058 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008059int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308060{
8061 QDF_STATUS qdf_status;
8062
8063 ENTER_DEV(adapter->dev);
8064
8065 qdf_status = hdd_init_tx_rx(adapter);
8066
8067 if (QDF_STATUS_SUCCESS != qdf_status) {
8068 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8069 return qdf_status_to_os_return(qdf_status);
8070 }
8071
8072 return 0;
8073 EXIT();
8074}
8075
8076/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008077 * hdd_open_interfaces - Open all required interfaces
8078 * hdd_ctx: HDD context
8079 * rtnl_held: True if RTNL lock is held
8080 *
8081 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8082 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008083 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008084 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008085static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008086{
Jeff Johnson9d295242017-08-29 14:39:48 -07008087 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008088 int ret;
8089
Ravi Joshia307f632017-07-17 23:41:41 -07008090 /* open monitor mode adapter if con_mode is monitor mode */
8091 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8092 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8093 wlan_hdd_get_intf_addr(hdd_ctx),
8094 NET_NAME_UNKNOWN, rtnl_held);
8095 if (!adapter) {
8096 hdd_err("open adapter failed");
8097 return -ENOSPC;
8098 }
8099 return 0;
8100 }
8101
Jeff Johnson957bc272017-02-02 08:54:48 -08008102 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308103 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008104 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008105
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008106 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008107 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008108 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008109
8110 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008111 return -ENOSPC;
8112
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008113 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8114 adapter->fast_roaming_allowed = true;
8115
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008116 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8117 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008118 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008119
8120 /* Open 802.11p Interface */
8121 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008122 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8123 if (ret)
8124 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008125 }
8126
Jeff Johnson957bc272017-02-02 08:54:48 -08008127 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008128
Jeff Johnson957bc272017-02-02 08:54:48 -08008129err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008130 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008131 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008132}
8133
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008134/**
8135 * hdd_update_country_code - Update country code
8136 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008137 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008138 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008139 *
8140 * Return: 0 on success and errno on failure
8141 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008142static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008143{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008144 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008145 return 0;
8146
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008147 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008148}
8149
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308150#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8151/**
8152 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8153 * @cds_cfg: CDS Configuration
8154 * @hdd_ctx: Pointer to hdd context
8155 *
8156 * Return: none
8157 */
8158static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8159 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008160 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308161{
8162 cds_cfg->tx_flow_stop_queue_th =
8163 hdd_ctx->config->TxFlowStopQueueThreshold;
8164 cds_cfg->tx_flow_start_queue_offset =
8165 hdd_ctx->config->TxFlowStartQueueOffset;
8166}
8167#else
8168static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8169 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008170 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308171{
8172}
8173#endif
8174
8175#ifdef FEATURE_WLAN_RA_FILTERING
8176/**
8177 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8178 * @cds_cfg: CDS Configuration
8179 * @hdd_ctx: Pointer to hdd context
8180 *
8181 * Return: none
8182 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308183static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008184 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308185{
8186 cds_cfg->ra_ratelimit_interval =
8187 hdd_ctx->config->RArateLimitInterval;
8188 cds_cfg->is_ra_ratelimit_enabled =
8189 hdd_ctx->config->IsRArateLimitEnabled;
8190}
8191#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308192static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008193 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308194{
8195}
8196#endif
8197
8198/**
8199 * hdd_update_cds_config() - API to update cds configuration parameters
8200 * @hdd_ctx: HDD Context
8201 *
8202 * Return: 0 for Success, errno on failure
8203 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008204static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308205{
8206 struct cds_config_info *cds_cfg;
8207
8208 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8209 if (!cds_cfg) {
8210 hdd_err("failed to allocate cds config");
8211 return -ENOMEM;
8212 }
8213
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008214 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008215 if (!hdd_ctx->config->nMaxPsPoll ||
8216 !hdd_ctx->config->enablePowersaveOffload) {
8217 cds_cfg->powersave_offload_enabled =
8218 hdd_ctx->config->enablePowersaveOffload;
8219 } else {
8220 if ((hdd_ctx->config->enablePowersaveOffload ==
8221 PS_QPOWER_NODEEPSLEEP) ||
8222 (hdd_ctx->config->enablePowersaveOffload ==
8223 PS_LEGACY_NODEEPSLEEP))
8224 cds_cfg->powersave_offload_enabled =
8225 PS_LEGACY_NODEEPSLEEP;
8226 else
8227 cds_cfg->powersave_offload_enabled =
8228 PS_LEGACY_DEEPSLEEP;
8229 hdd_info("Qpower disabled in cds config, %d",
8230 cds_cfg->powersave_offload_enabled);
8231 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308232 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8233 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8234 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8235 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8236 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8237
8238 /* Here ol_ini_info is used to store ini status of arp offload
8239 * ns offload and others. Currently 1st bit is used for arp
8240 * off load and 2nd bit for ns offload currently, rest bits are unused
8241 */
8242 if (hdd_ctx->config->fhostArpOffload)
8243 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8244 if (hdd_ctx->config->fhostNSOffload)
8245 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8246
8247 /*
8248 * Copy the DFS Phyerr Filtering Offload status.
8249 * This parameter reflects the value of the
8250 * dfs_phyerr_filter_offload flag as set in the ini.
8251 */
8252 cds_cfg->dfs_phyerr_filter_offload =
8253 hdd_ctx->config->fDfsPhyerrFilterOffload;
8254 if (hdd_ctx->config->ssdp)
8255 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8256
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308257 cds_cfg->force_target_assert_enabled =
8258 hdd_ctx->config->crash_inject_enabled;
8259
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308260 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8261 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8262
8263 cds_cfg->ap_maxoffload_reorderbuffs =
8264 hdd_ctx->config->apMaxOffloadReorderBuffs;
8265
8266 cds_cfg->ap_disable_intrabss_fwd =
8267 hdd_ctx->config->apDisableIntraBssFwd;
8268
8269 cds_cfg->dfs_pri_multiplier =
8270 hdd_ctx->config->dfsRadarPriMultiplier;
8271 cds_cfg->reorder_offload =
8272 hdd_ctx->config->reorderOffloadSupport;
8273
8274 /* IPA micro controller data path offload resource config item */
8275 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008276 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8277 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008278 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008279 hdd_ctx->config->IpaUcTxBufCount);
8280 hdd_ctx->config->IpaUcTxBufCount =
8281 rounddown_pow_of_two(
8282 hdd_ctx->config->IpaUcTxBufCount);
8283 if (!hdd_ctx->config->IpaUcTxBufCount) {
8284 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308285 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008286 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008287 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008288 hdd_ctx->config->IpaUcTxBufCount);
8289 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308290 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8291 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008292 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8293 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008294 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008295 hdd_ctx->config->IpaUcRxIndRingCount);
8296 hdd_ctx->config->IpaUcRxIndRingCount =
8297 rounddown_pow_of_two(
8298 hdd_ctx->config->IpaUcRxIndRingCount);
8299 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8300 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308301 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008302 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008303 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008304 hdd_ctx->config->IpaUcRxIndRingCount);
8305 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308306 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008307 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308308 cds_cfg->uc_tx_partition_base =
8309 hdd_ctx->config->IpaUcTxPartitionBase;
8310 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8311
8312 cds_cfg->ip_tcp_udp_checksum_offload =
8313 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308314 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308315 cds_cfg->ce_classify_enabled =
8316 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008317 cds_cfg->bpf_packet_filter_enable =
8318 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308319 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8320 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8321 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008322 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008323 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008324 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008325 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308326 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8327 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308328 cds_cfg->auto_power_save_fail_mode =
8329 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308330
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308331 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
8332
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308333 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8334 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8335 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008336 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308337 cds_init_ini_config(cds_cfg);
8338 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308339
8340exit:
8341 qdf_mem_free(cds_cfg);
8342 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308343}
8344
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008345/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008346 * hdd_update_user_config() - API to update user configuration
8347 * parameters to obj mgr which are used by multiple components
8348 * @hdd_ctx: HDD Context
8349 *
8350 * Return: 0 for Success, errno on failure
8351 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008352static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008353{
8354 struct wlan_objmgr_psoc_user_config *user_config;
8355
8356 user_config = qdf_mem_malloc(sizeof(*user_config));
8357 if (user_config == NULL) {
8358 hdd_alert("Failed to alloc memory for user_config!");
8359 return -ENOMEM;
8360 }
8361
8362 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8363 user_config->dual_mac_feature_disable =
8364 hdd_ctx->config->dual_mac_feature_disable;
8365 user_config->indoor_channel_support =
8366 hdd_ctx->config->indoor_channel_support;
8367 user_config->is_11d_support_enabled =
8368 hdd_ctx->config->Is11dSupportEnabled;
8369 user_config->is_11h_support_enabled =
8370 hdd_ctx->config->Is11hSupportEnabled;
8371 user_config->optimize_chan_avoid_event =
8372 hdd_ctx->config->goptimize_chan_avoid_event;
8373 user_config->skip_dfs_chnl_in_p2p_search =
8374 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008375 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008376 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8377
8378 qdf_mem_free(user_config);
8379 return 0;
8380}
8381
8382/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008383 * hdd_init_thermal_info - Initialize thermal level
8384 * @hdd_ctx: HDD context
8385 *
8386 * Initialize thermal level at SME layer and set the thermal level callback
8387 * which would be called when a configured thermal threshold is hit.
8388 *
8389 * Return: 0 on success and errno on failure
8390 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008391static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008392{
8393 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308394 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008395
8396 thermal_param.smeThermalMgmtEnabled =
8397 hdd_ctx->config->thermalMitigationEnable;
8398 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8399
Poddar, Siddarth83905022016-04-16 17:56:08 -07008400 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8401 hdd_ctx->config->throttle_dutycycle_level0;
8402 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8403 hdd_ctx->config->throttle_dutycycle_level1;
8404 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8405 hdd_ctx->config->throttle_dutycycle_level2;
8406 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8407 hdd_ctx->config->throttle_dutycycle_level3;
8408
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008409 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8410 hdd_ctx->config->thermalTempMinLevel0;
8411 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8412 hdd_ctx->config->thermalTempMaxLevel0;
8413 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8414 hdd_ctx->config->thermalTempMinLevel1;
8415 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8416 hdd_ctx->config->thermalTempMaxLevel1;
8417 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8418 hdd_ctx->config->thermalTempMinLevel2;
8419 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8420 hdd_ctx->config->thermalTempMaxLevel2;
8421 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8422 hdd_ctx->config->thermalTempMinLevel3;
8423 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8424 hdd_ctx->config->thermalTempMaxLevel3;
8425
8426 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8427
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308428 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308429 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008430
8431 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8432 hdd_set_thermal_level_cb);
8433
8434 return 0;
8435
8436}
8437
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008438#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8439/**
8440 * hdd_hold_rtnl_lock - Hold RTNL lock
8441 *
8442 * Hold RTNL lock
8443 *
8444 * Return: True if held and false otherwise
8445 */
8446static inline bool hdd_hold_rtnl_lock(void)
8447{
8448 rtnl_lock();
8449 return true;
8450}
8451
8452/**
8453 * hdd_release_rtnl_lock - Release RTNL lock
8454 *
8455 * Release RTNL lock
8456 *
8457 * Return: None
8458 */
8459static inline void hdd_release_rtnl_lock(void)
8460{
8461 rtnl_unlock();
8462}
8463#else
8464static inline bool hdd_hold_rtnl_lock(void) { return false; }
8465static inline void hdd_release_rtnl_lock(void) { }
8466#endif
8467
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008468#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008469
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308470/* MAX iwpriv command support */
8471#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308472#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308473#define MAX_PKTLOG_SIZE 16
8474
8475/**
8476 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8477 * @hdd_ctx: hdd context
8478 * @set_value2: pktlog buffer size value
8479 *
8480 *
8481 * Return: 0 for success or error.
8482 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008483static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308484{
8485 struct sir_wifi_start_log start_log = { 0 };
8486 QDF_STATUS status;
8487
8488 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8489 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8490 start_log.ini_triggered = cds_is_packet_log_enabled();
8491 start_log.user_triggered = 1;
8492 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308493 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308494
8495 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8496 if (!QDF_IS_STATUS_SUCCESS(status)) {
8497 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8498 EXIT();
8499 return -EINVAL;
8500 }
8501
8502 return 0;
8503}
8504
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008505/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308506 * hdd_pktlog_clear_buff() - clear pktlog buffer
8507 * @hdd_ctx: hdd context
8508 *
8509 * Return: 0 for success or error.
8510 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008511static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308512{
8513 struct sir_wifi_start_log start_log;
8514 QDF_STATUS status;
8515
8516 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8517 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8518 start_log.ini_triggered = cds_is_packet_log_enabled();
8519 start_log.user_triggered = 1;
8520 start_log.size = 0;
8521 start_log.is_pktlog_buff_clear = true;
8522
8523 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8524 if (!QDF_IS_STATUS_SUCCESS(status)) {
8525 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8526 EXIT();
8527 return -EINVAL;
8528 }
8529
8530 return 0;
8531}
8532
8533
8534/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008535 * hdd_process_pktlog_command() - process pktlog command
8536 * @hdd_ctx: hdd context
8537 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308538 * @set_value2: pktlog buffer size value
8539 *
8540 * This function process pktlog command.
8541 * set_value2 only matters when set_value is 3 (set buff size)
8542 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008543 *
8544 * Return: 0 for success or error.
8545 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008546int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308547 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008548{
8549 int ret;
8550 bool enable;
8551 uint8_t user_triggered = 0;
8552
8553 ret = wlan_hdd_validate_context(hdd_ctx);
8554 if (0 != ret)
8555 return ret;
8556
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008557 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008558
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308559 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008560 hdd_err("invalid pktlog value %d", set_value);
8561 return -EINVAL;
8562 }
8563
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308564 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8565 if (set_value2 <= 0) {
8566 hdd_err("invalid pktlog size %d", set_value2);
8567 return -EINVAL;
8568 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8569 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8570 return -EINVAL;
8571 }
8572 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308573 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8574 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308575 }
8576
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008577 /*
8578 * set_value = 0 then disable packetlog
8579 * set_value = 1 enable packetlog forcefully
8580 * set_vlaue = 2 then disable packetlog if disabled through ini or
8581 * enable packetlog with AUTO type.
8582 */
8583 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8584 true : false;
8585
8586 if (1 == set_value) {
8587 enable = true;
8588 user_triggered = 1;
8589 }
8590
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308591 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008592}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008593/**
8594 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8595 * @hdd_ctx: HDD context
8596 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308597 * @user_triggered: triggered through iwpriv
8598 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008599 *
8600 * Return: 0 on success; error number otherwise
8601 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008602int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308603 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008604{
8605 struct sir_wifi_start_log start_log;
8606 QDF_STATUS status;
8607
8608 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8609 start_log.verbose_level =
8610 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008611 start_log.ini_triggered = cds_is_packet_log_enabled();
8612 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308613 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308614 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308615 /*
8616 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8617 * commands. Host uses this flag to decide whether to send pktlog
8618 * disable command to fw without sending pktlog enable command
8619 * previously. For eg, If vendor sends pktlog disable command without
8620 * sending pktlog enable command, then host discards the packet
8621 * but for iwpriv command, host will send it to fw.
8622 */
8623 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008624 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8625 if (!QDF_IS_STATUS_SUCCESS(status)) {
8626 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8627 EXIT();
8628 return -EINVAL;
8629 }
8630
8631 return 0;
8632}
8633#endif /* REMOVE_PKT_LOG */
8634
Komal Seelam92fff912016-03-24 11:51:41 +05308635/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008636 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8637 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308638 * @dev: Device Pointer
8639 * @num: Number of Valid Mac address
8640 *
8641 * Return: Pointer to MAC address buffer
8642 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008643static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8644 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308645{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008646 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308647}
Komal Seelam92fff912016-03-24 11:51:41 +05308648
8649/**
8650 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8651 * @hdd_ctx: HDD Context
8652 * @num: Number of random mac addresses needed
8653 *
8654 * Generate random addresses using bit manipulation on the base mac address
8655 *
8656 * Return: None
8657 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008658void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308659{
8660 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8661 uint32_t iter;
8662 struct hdd_config *ini = hdd_ctx->config;
8663 uint8_t *buf = NULL;
8664 uint8_t macaddr_b3, tmp_br3;
8665 uint8_t *src = ini->intfMacAddr[0].bytes;
8666
8667 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8668 buf = ini->intfMacAddr[iter].bytes;
8669 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8670 macaddr_b3 = buf[3];
8671 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8672 INTF_MACADDR_MASK;
8673 macaddr_b3 += tmp_br3;
8674 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8675 buf[0] |= 0x02;
8676 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008677 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308678 }
8679}
8680
8681/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008682 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308683 * @hdd_ctx: HDD Context
8684 *
8685 * API to get mac addresses from platform driver and update the driver
8686 * structures and configure FW with the base mac address.
8687 * Return: int
8688 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008689static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308690{
8691 uint32_t no_of_mac_addr, iter;
8692 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8693 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8694 uint8_t *addr, *buf;
8695 struct device *dev = hdd_ctx->parent_dev;
8696 struct hdd_config *ini = hdd_ctx->config;
8697 tSirMacAddr mac_addr;
8698 QDF_STATUS status;
8699
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008700 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308701
8702 if (no_of_mac_addr == 0 || !addr) {
8703 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8704 return -EINVAL;
8705 }
8706
8707 if (no_of_mac_addr > max_mac_addr)
8708 no_of_mac_addr = max_mac_addr;
8709
8710 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8711
8712 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8713 buf = ini->intfMacAddr[iter].bytes;
8714 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008715 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308716 }
8717
8718 status = sme_set_custom_mac_addr(mac_addr);
8719
8720 if (!QDF_IS_STATUS_SUCCESS(status))
8721 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008722
Komal Seelam92fff912016-03-24 11:51:41 +05308723 if (no_of_mac_addr < max_mac_addr)
8724 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8725 no_of_mac_addr);
8726 return 0;
8727}
8728
8729/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008730 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8731 * @hdd_ctx: HDD Context
8732 *
8733 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8734 * will generate its own MAC and update it to FW.
8735 *
8736 * Return: 0 for success
8737 * Non-zero error code for failure
8738 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008739static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008740{
8741 tSirMacAddr customMacAddr;
8742 QDF_STATUS status;
8743
8744 qdf_mem_copy(&customMacAddr,
8745 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8746 sizeof(tSirMacAddr));
8747 status = sme_set_custom_mac_addr(customMacAddr);
8748 if (!QDF_IS_STATUS_SUCCESS(status))
8749 return -EAGAIN;
8750 return 0;
8751}
8752
8753/**
Komal Seelam92fff912016-03-24 11:51:41 +05308754 * hdd_initialize_mac_address() - API to get wlan mac addresses
8755 * @hdd_ctx: HDD Context
8756 *
8757 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8758 * is provisioned with mac addresses, driver uses it, else it will use
8759 * wlan_mac.bin to update HW MAC addresses.
8760 *
8761 * Return: None
8762 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008763static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308764{
8765 QDF_STATUS status;
8766 int ret;
8767
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008768 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308769 if (ret == 0)
8770 return;
8771
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008772 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8773 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308774
8775 status = hdd_update_mac_config(hdd_ctx);
8776
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008777 if (QDF_IS_STATUS_SUCCESS(status))
8778 return;
8779
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008780 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8781 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008782
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008783 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008784 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008785 if (ret != 0) {
8786 hdd_err("MAC address out-of-sync, ret:%d", ret);
8787 QDF_ASSERT(ret);
8788 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008789 }
Komal Seelam92fff912016-03-24 11:51:41 +05308790}
8791
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008792static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008793{
8794 int vdev_id = 0;
8795 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8796 int value = hdd_ctx->config->smart_chainmask_enabled;
8797 int vpdev = PDEV_CMD;
8798 int ret;
8799
Naveen Rawat247a8682017-06-05 15:00:31 -07008800 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008801 if (ret)
8802 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8803
8804 return ret;
8805}
8806
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008807static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008808{
8809 int vdev_id = 0;
8810 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8811 int value = hdd_ctx->config->alternative_chainmask_enabled;
8812 int vpdev = PDEV_CMD;
8813 int ret;
8814
Naveen Rawat247a8682017-06-05 15:00:31 -07008815 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008816 if (ret)
8817 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8818 ret);
8819
8820 return ret;
8821}
8822
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008823static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008824{
8825 int vdev_id = 0;
8826 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8827 int value = hdd_ctx->config->ani_enabled;
8828 int vpdev = PDEV_CMD;
8829 int ret;
8830
Naveen Rawat247a8682017-06-05 15:00:31 -07008831 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008832 if (ret)
8833 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8834
8835 return ret;
8836}
8837
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008838/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008839 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8840 * @hdd_ctx: HDD context
8841 *
8842 * Pre configurations to be done at lower layer before calling cds enable.
8843 *
8844 * Return: 0 on success and errno on failure.
8845 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008846static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008847{
8848 int ret;
8849 QDF_STATUS status;
8850 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008851 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008852
Leo Changfdb45c32016-10-28 11:09:23 -07008853 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008854 /*
8855 * Set 802.11p config
8856 * TODO-OCB: This has been temporarily added here to ensure this
8857 * parameter is set in CSR when we init the channel list. This should
8858 * be removed once the 5.9 GHz channels are added to the regulatory
8859 * domain.
8860 */
8861 hdd_set_dot11p_config(hdd_ctx);
8862
8863 /*
8864 * Note that the cds_pre_enable() sequence triggers the cfg download.
8865 * The cfg download must occur before we update the SME config
8866 * since the SME config operation must access the cfg database
8867 */
8868 status = hdd_set_sme_config(hdd_ctx);
8869
8870 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008871 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008872 ret = qdf_status_to_os_return(status);
8873 goto out;
8874 }
8875
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008876 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8877 if (QDF_STATUS_SUCCESS != status) {
8878 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8879 ret = qdf_status_to_os_return(status);
8880 goto out;
8881 }
8882
Naveen Rawat247a8682017-06-05 15:00:31 -07008883 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008884 hdd_ctx->config->tx_chain_mask_1ss,
8885 PDEV_CMD);
8886 if (0 != ret) {
8887 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8888 goto out;
8889 }
8890
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008891 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8892 if (ret)
8893 goto out;
8894
8895 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8896 if (ret)
8897 goto out;
8898
Jeff Johnson12a744b2017-04-04 08:19:37 -07008899 ret = hdd_set_ani_enabled(hdd_ctx);
8900 if (ret)
8901 goto out;
8902
Naveen Rawat247a8682017-06-05 15:00:31 -07008903 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008904 hdd_ctx->config->arp_ac_category,
8905 PDEV_CMD);
8906 if (0 != ret) {
8907 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8908 hdd_ctx->config->arp_ac_category, ret);
8909 goto out;
8910 }
8911
8912
Prashanth Bhatta07998752016-04-28 12:35:33 -07008913 status = hdd_set_sme_chan_list(hdd_ctx);
8914 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008915 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008916 ret = qdf_status_to_os_return(status);
8917 goto out;
8918 }
8919
8920 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008921 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008922 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008923 ret = -EINVAL;
8924 goto out;
8925 }
8926
Prashanth Bhatta07998752016-04-28 12:35:33 -07008927 /*
8928 * Set the MAC Address Currently this is used by HAL to add self sta.
8929 * Remove this once self sta is added as part of session open.
8930 */
8931 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8932 hdd_ctx->config->intfMacAddr[0].bytes,
8933 sizeof(hdd_ctx->config->intfMacAddr[0]));
8934
8935 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8936 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8937 hal_status, hal_status);
8938 ret = -EINVAL;
8939 goto out;
8940 }
8941
8942 hdd_init_channel_avoidance(hdd_ctx);
8943
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308944 /* update enable sap mandatory chan list */
8945 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8946 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008947out:
8948 return ret;
8949}
8950
8951/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008952 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8953 * @context_ptr - hdd context pointer
8954 * @event_ptr - event structure pointer
8955 *
8956 * This is the p2p listen offload stop event handler, it sends vendor
8957 * event back to supplicant to notify the stop reason.
8958 *
8959 * Return: None
8960 */
8961static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8962 void *event_ptr)
8963{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008964 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008965 struct sir_p2p_lo_event *evt = event_ptr;
8966 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008967 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008968
8969 ENTER();
8970
8971 if (hdd_ctx == NULL) {
8972 hdd_err("Invalid HDD context pointer");
8973 return;
8974 }
8975
Peng Xu5c682812017-08-06 07:39:13 -07008976 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8977 if (!adapter) {
8978 hdd_err("Cannot find adapter by vdev_id = %d",
8979 evt->vdev_id);
8980 return;
8981 }
8982
Peng Xu8fdaa492016-06-22 10:20:47 -07008983 vendor_event =
8984 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008985 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008986 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8987 GFP_KERNEL);
8988
8989 if (!vendor_event) {
8990 hdd_err("cfg80211_vendor_event_alloc failed");
8991 return;
8992 }
8993
8994 if (nla_put_u32(vendor_event,
8995 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8996 evt->reason_code)) {
8997 hdd_err("nla put failed");
8998 kfree_skb(vendor_event);
8999 return;
9000 }
9001
9002 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009003 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9004 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009005}
9006
9007/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309008 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9009 * @hdd_ctx: HDD context
9010 *
9011 * This function sends the adaptive dwell time config configuration to the
9012 * firmware via WMA
9013 *
9014 * Return: 0 - success, < 0 - failure
9015 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009016static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309017{
9018 QDF_STATUS status;
9019 struct adaptive_dwelltime_params dwelltime_params;
9020
9021 dwelltime_params.is_enabled =
9022 hdd_ctx->config->adaptive_dwell_mode_enabled;
9023 dwelltime_params.dwelltime_mode =
9024 hdd_ctx->config->global_adapt_dwelltime_mode;
9025 dwelltime_params.lpf_weight =
9026 hdd_ctx->config->adapt_dwell_lpf_weight;
9027 dwelltime_params.passive_mon_intval =
9028 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9029 dwelltime_params.wifi_act_threshold =
9030 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9031
9032 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9033 &dwelltime_params);
9034
9035 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9036 if (!QDF_IS_STATUS_SUCCESS(status)) {
9037 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9038 return -EAGAIN;
9039 }
9040 return 0;
9041}
9042
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009043int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309044{
9045 QDF_STATUS status;
9046 struct wmi_dbs_scan_sel_params dbs_scan_params;
9047 uint32_t i = 0;
9048 uint8_t count = 0, numentries = 0;
9049 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9050 * CDS_DBS_SCAN_CLIENTS_MAX];
9051
9052 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009053 if (hdd_ctx->config->dual_mac_feature_disable ==
9054 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309055 return -EINVAL;
9056
9057 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9058 dbs_scan_config, &numentries,
9059 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9060 * CDS_DBS_SCAN_CLIENTS_MAX));
9061
9062 hdd_info("numentries %hu", numentries);
9063 if (!numentries) {
9064 hdd_info("Donot send scan_selection_config");
9065 return 0;
9066 }
9067
9068 /* hdd_set_fw_log_params */
9069 dbs_scan_params.num_clients = 0;
9070 while (count < (numentries - 2)) {
9071 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9072 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9073 dbs_scan_params.num_non_dbs_scans[i] =
9074 dbs_scan_config[count + 2];
9075 dbs_scan_params.num_clients++;
9076 hdd_debug("module:%d NDS:%d NNDS:%d",
9077 dbs_scan_params.module_id[i],
9078 dbs_scan_params.num_dbs_scans[i],
9079 dbs_scan_params.num_non_dbs_scans[i]);
9080 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9081 i++;
9082 }
9083
9084 dbs_scan_params.pdev_id = 0;
9085
9086 hdd_debug("clients:%d pdev:%d",
9087 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9088
9089 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9090 &dbs_scan_params);
9091 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9092 if (!QDF_IS_STATUS_SUCCESS(status)) {
9093 hdd_err("Failed to send DBS Scan selection configuration!");
9094 return -EAGAIN;
9095 }
9096 return 0;
9097}
9098
Arun Khandavallid4349a92016-07-25 11:10:43 +05309099#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9100/**
9101 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9102 * @hdd_ctx: HDD context
9103 *
9104 * Set auto shutdown callback to get indications from firmware to indicate
9105 * userspace to shutdown WLAN after a configured amount of inactivity.
9106 *
9107 * Return: 0 on success and errno on failure.
9108 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009109static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309110{
9111 QDF_STATUS status;
9112
9113 if (!hdd_ctx->config->WlanAutoShutdown)
9114 return 0;
9115
9116 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9117 wlan_hdd_auto_shutdown_cb);
9118 if (status != QDF_STATUS_SUCCESS)
9119 hdd_err("Auto shutdown feature could not be enabled: %d",
9120 status);
9121
9122 return qdf_status_to_os_return(status);
9123}
9124#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009125static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309126{
9127 return 0;
9128}
9129#endif
9130
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009131static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009132{
9133 QDF_STATUS status = QDF_STATUS_SUCCESS;
9134
9135 switch (hdd_ctx->config->dual_mac_feature_disable) {
9136 case DISABLE_DBS_CXN_AND_SCAN:
9137 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9138 if (status != QDF_STATUS_SUCCESS)
9139 hdd_err("Failed to disable dual mac features");
9140 break;
9141 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9142 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9143 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9144 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9145 if (status != QDF_STATUS_SUCCESS)
9146 hdd_err("Failed to set dbs scan and fw mode config");
9147 break;
9148 default:
9149 break;
9150 }
9151
9152 return status;
9153}
9154
Arun Khandavallid4349a92016-07-25 11:10:43 +05309155/**
9156 * hdd_features_init() - Init features
9157 * @hdd_ctx: HDD context
9158 * @adapter: Primary adapter context
9159 *
9160 * Initialize features and their feature context after WLAN firmware is up.
9161 *
9162 * Return: 0 on success and errno on failure.
9163 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009164static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309165{
9166 tSirTxPowerLimit hddtxlimit;
9167 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309168 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309169 int ret;
9170
9171 ENTER();
9172
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009173 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309174 if (ret) {
9175 hdd_err("Failed to update country code: %d", ret);
9176 goto out;
9177 }
9178
9179 /* FW capabilities received, Set the Dot11 mode */
9180 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009181 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9182 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309183
Arun Khandavallid4349a92016-07-25 11:10:43 +05309184
9185 if (hdd_ctx->config->fIsImpsEnabled)
9186 hdd_set_idle_ps_config(hdd_ctx, true);
9187 else
9188 hdd_set_idle_ps_config(hdd_ctx, false);
9189
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309190 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009191 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309192
Arun Khandavallid4349a92016-07-25 11:10:43 +05309193 if (hdd_lro_init(hdd_ctx))
9194 hdd_err("Unable to initialize LRO in fw");
9195
9196 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9197 hdd_err("Unable to send adaptive dwelltime setting to FW");
9198
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309199 if (hdd_dbs_scan_selection_init(hdd_ctx))
9200 hdd_err("Unable to send DBS scan selection setting to FW");
9201
Arun Khandavallid4349a92016-07-25 11:10:43 +05309202 ret = hdd_init_thermal_info(hdd_ctx);
9203 if (ret) {
9204 hdd_err("Error while initializing thermal information");
9205 goto deregister_frames;
9206 }
9207
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309208 if (cds_is_packet_log_enabled())
9209 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9210
Arun Khandavallid4349a92016-07-25 11:10:43 +05309211 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9212 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9213 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9214 if (!QDF_IS_STATUS_SUCCESS(status))
9215 hdd_err("Error setting txlimit in sme: %d", status);
9216
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009217 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309218
Arun Khandavallid4349a92016-07-25 11:10:43 +05309219 ret = hdd_register_cb(hdd_ctx);
9220 if (ret) {
9221 hdd_err("Failed to register HDD callbacks!");
9222 goto deregister_frames;
9223 }
9224
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009225 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9226 if (!QDF_IS_STATUS_SUCCESS(status)) {
9227 hdd_err("Failed to set dbs scan and fw mode cfg");
9228 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309229 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009230
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309231 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9232 status = sme_enable_disable_chanavoidind_event(
9233 hdd_ctx->hHal, 0);
9234 if (!QDF_IS_STATUS_SUCCESS(status)) {
9235 hdd_err("Failed to disable Chan Avoidance Indication");
9236 goto deregister_cb;
9237 }
9238 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309239
Manjeet Singha9cae432017-02-28 11:58:22 +05309240 if (hdd_ctx->config->enable_5g_band_pref) {
9241 band_pref_params.rssi_boost_threshold_5g =
9242 hdd_ctx->config->rssi_boost_threshold_5g;
9243 band_pref_params.rssi_boost_factor_5g =
9244 hdd_ctx->config->rssi_boost_factor_5g;
9245 band_pref_params.max_rssi_boost_5g =
9246 hdd_ctx->config->max_rssi_boost_5g;
9247 band_pref_params.rssi_penalize_threshold_5g =
9248 hdd_ctx->config->rssi_penalize_threshold_5g;
9249 band_pref_params.rssi_penalize_factor_5g =
9250 hdd_ctx->config->rssi_penalize_factor_5g;
9251 band_pref_params.max_rssi_penalize_5g =
9252 hdd_ctx->config->max_rssi_penalize_5g;
9253 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9254 }
9255
Arun Khandavallid4349a92016-07-25 11:10:43 +05309256 /* register P2P Listen Offload event callback */
9257 if (wma_is_p2p_lo_capable())
9258 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9259 wlan_hdd_p2p_lo_event_callback);
9260
9261 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9262
9263 if (ret)
9264 goto deregister_cb;
9265
9266 EXIT();
9267 return 0;
9268
9269deregister_cb:
9270 hdd_deregister_cb(hdd_ctx);
9271deregister_frames:
9272 wlan_hdd_cfg80211_deregister_frames(adapter);
9273out:
9274 return -EINVAL;
9275
9276}
9277
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009278/**
9279 * hdd_features_deinit() - Deinit features
9280 * @hdd_ctx: HDD context
9281 *
9282 * De-Initialize features and their feature context.
9283 *
9284 * Return: none.
9285 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009286static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009287{
9288 wlan_hdd_tsf_deinit(hdd_ctx);
9289}
9290
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309291/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009292 * hdd_register_bcn_cb() - register scan beacon callback
9293 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309294 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009295 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309296 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009297static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309298{
9299 QDF_STATUS status;
9300
9301 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9302 wlan_cfg80211_inform_bss_frame,
9303 SCAN_CB_TYPE_INFORM_BCN);
9304 if (!QDF_IS_STATUS_SUCCESS(status)) {
9305 hdd_err("failed with status code %08d [x%08x]",
9306 status, status);
9307 return status;
9308 }
9309
9310 return QDF_STATUS_SUCCESS;
9311}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309312
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309313/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309314 * hdd_configure_cds() - Configure cds modules
9315 * @hdd_ctx: HDD context
9316 * @adapter: Primary adapter context
9317 *
9318 * Enable Cds modules after WLAN firmware is up.
9319 *
9320 * Return: 0 on success and errno on failure.
9321 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009322int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309323{
9324 int ret;
9325 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309326 int set_value;
9327 uint32_t num_abg_tx_chains = 0;
9328 uint32_t num_11b_tx_chains = 0;
9329 uint32_t num_11ag_tx_chains = 0;
9330
9331 if (hdd_ctx->config->sifs_burst_duration) {
9332 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9333 hdd_ctx->config->sifs_burst_duration;
9334
9335 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9336 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9337 set_value, PDEV_CMD);
9338 }
9339
9340 if (hdd_ctx->config->is_force_1x1)
9341 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9342 1, PDEV_CMD);
9343 /* set chip power save failure detected callback */
9344 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9345 hdd_chip_pwr_save_fail_detected_cb);
9346
9347 if (hdd_ctx->config->max_mpdus_inampdu) {
9348 set_value = hdd_ctx->config->max_mpdus_inampdu;
9349 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9350 set_value, PDEV_CMD);
9351 }
9352
9353 if (hdd_ctx->config->enable_rts_sifsbursting) {
9354 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9355 sme_cli_set_command(0,
9356 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9357 set_value, PDEV_CMD);
9358 }
9359
9360 if (hdd_ctx->config->sap_get_peer_info) {
9361 set_value = hdd_ctx->config->sap_get_peer_info;
9362 sme_cli_set_command(0,
9363 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9364 set_value, PDEV_CMD);
9365 }
9366
9367 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9368 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9369 if (!hdd_ctx->config->enable2x2) {
9370 if (num_11b_tx_chains > 1)
9371 num_11b_tx_chains = 1;
9372 if (num_11ag_tx_chains > 1)
9373 num_11ag_tx_chains = 1;
9374 }
9375 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9376 num_11b_tx_chains);
9377 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9378 num_11ag_tx_chains);
9379 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9380 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309381
9382 ret = hdd_pre_enable_configure(hdd_ctx);
9383 if (ret) {
9384 hdd_err("Failed to pre-configure cds");
9385 goto out;
9386 }
9387
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009388 /* Always get latest IPA resources allocated from cds_open and configure
9389 * IPA module before configuring them to FW. Sequence required as crash
9390 * observed otherwise.
9391 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009392 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9393 hdd_err("Failed to setup pipes");
9394 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009395 }
9396
Arun Khandavallifae92942016-08-01 13:31:08 +05309397 /*
9398 * Start CDS which starts up the SME/MAC/HAL modules and everything
9399 * else
9400 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009401 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309402
9403 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009404 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309405 goto out;
9406 }
9407
9408 status = hdd_post_cds_enable_config(hdd_ctx);
9409 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009410 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009411 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309412 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309413 status = hdd_register_bcn_cb(hdd_ctx);
9414 if (!QDF_IS_STATUS_SUCCESS(status)) {
9415 hdd_alert("hdd_post_cds_enable_config failed");
9416 goto cds_disable;
9417 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309418
9419 ret = hdd_features_init(hdd_ctx, adapter);
9420 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009421 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309422
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309423 if (hdd_enable_egap(hdd_ctx))
9424 hdd_debug("enhance green ap is not enabled");
9425
Nachiket Kukadedd302662017-07-13 17:31:44 +05309426 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9427 hdd_debug("Failed to set wow pulse");
9428
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309429 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9430 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9431
Arun Khandavallifae92942016-08-01 13:31:08 +05309432 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009433
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009434cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009435 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009436
Arun Khandavallifae92942016-08-01 13:31:08 +05309437out:
9438 return -EINVAL;
9439}
9440
9441/**
9442 * hdd_deconfigure_cds() -De-Configure cds
9443 * @hdd_ctx: HDD context
9444 *
9445 * Deconfigure Cds modules before WLAN firmware is down.
9446 *
9447 * Return: 0 on success and errno on failure.
9448 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009449static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309450{
9451 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009452 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309453
9454 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009455
9456 /* De-init features */
9457 hdd_features_deinit(hdd_ctx);
9458
Arun Khandavallifae92942016-08-01 13:31:08 +05309459 /* De-register the SME callbacks */
9460 hdd_deregister_cb(hdd_ctx);
9461
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009462 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309463 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9464 hdd_err("Failed to Disable the CDS Modules! :%d",
9465 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009466 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309467 }
9468
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309469 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9470 hdd_err("Failed to disconnect pipes");
9471 ret = -EINVAL;
9472 }
9473
Arun Khandavallifae92942016-08-01 13:31:08 +05309474 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009475 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309476}
9477
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009478#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9479static void hdd_deregister_policy_manager_callback(
9480 struct wlan_objmgr_psoc *psoc)
9481{
9482 if (QDF_STATUS_SUCCESS !=
9483 policy_mgr_deregister_hdd_cb(psoc)) {
9484 hdd_err("HDD callback deregister with policy manager failed");
9485 }
9486}
9487#else
9488static void hdd_deregister_policy_manager_callback(
9489 struct wlan_objmgr_psoc *psoc)
9490{
9491}
9492#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309493
9494/**
9495 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9496 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009497 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309498 *
9499 * This function maintains the driver state machine it will be invoked from
9500 * exit, shutdown and con_mode change handler. Depending on the driver state
9501 * shall perform the stopping/closing of the modules.
9502 *
9503 * Return: 0 for success; non-zero for failure
9504 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009505int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309506{
9507 void *hif_ctx;
9508 qdf_device_t qdf_ctx;
9509 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309510 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009511 bool is_idle_stop = !cds_is_driver_unloading() &&
9512 !cds_is_driver_recovering();
9513 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309514
9515 ENTER();
9516
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009517 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9518
Arun Khandavallifae92942016-08-01 13:31:08 +05309519 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9520 if (!qdf_ctx) {
9521 hdd_err("QDF device context NULL");
9522 return -EINVAL;
9523 }
9524
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309525 mutex_lock(&hdd_ctx->iface_change_lock);
9526 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309527
Dustin Brown70111822017-03-30 15:31:40 -07009528 active_threads = cds_return_external_threads_count();
9529 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009530 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009531 active_threads, hdd_ctx->isWiphySuspended);
9532
9533 cds_print_external_threads();
9534
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009535 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009536 mutex_unlock(&hdd_ctx->iface_change_lock);
9537 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009538 hdd_ctx->config->iface_change_wait_time);
9539 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009540 return 0;
9541 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009542 }
9543
Arun Khandavallifae92942016-08-01 13:31:08 +05309544 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9545
9546 switch (hdd_ctx->driver_status) {
9547 case DRIVER_MODULES_UNINITIALIZED:
9548 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309549 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309550 case DRIVER_MODULES_CLOSED:
9551 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309552 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309553 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309554 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309555 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009556 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309557 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309558 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309559 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009560 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309561 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9562 break;
9563 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009564 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309565 break;
9566 default:
9567 hdd_err("Trying to stop wlan in a wrong state: %d",
9568 hdd_ctx->driver_status);
9569 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309570 ret = -EINVAL;
9571 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309572 }
9573
Rajeev Kumarbe021242017-02-16 16:12:23 -08009574 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309575 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9576 hdd_err("Failed to process post CDS disable Modules! :%d",
9577 qdf_status);
9578 ret = -EINVAL;
9579 QDF_ASSERT(0);
9580 }
Jeff Johnsone4b14592017-09-13 14:23:33 -07009581 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309582 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009583 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309584 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309585 QDF_ASSERT(0);
9586 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009587
Arun Khandavallifae92942016-08-01 13:31:08 +05309588 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9589 if (!hif_ctx) {
9590 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309591 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309592 }
9593
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309594 hdd_runtime_suspend_context_deinit(hdd_ctx);
9595
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309596 if (hdd_ctx->target_hw_name) {
9597 qdf_mem_free(hdd_ctx->target_hw_name);
9598 hdd_ctx->target_hw_name = NULL;
9599 }
9600
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309601 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309602
9603 ol_cds_free();
9604
Dustin Brown70111822017-03-30 15:31:40 -07009605 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309606 ret = pld_power_off(qdf_ctx->dev);
9607 if (ret)
9608 hdd_err("CNSS power down failed put device into Low power mode:%d",
9609 ret);
9610 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309611
9612 /* Once the firmware sequence is completed reset this flag */
9613 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309614 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009615 /*
9616 * Reset total mac phy during module stop such that during
9617 * next module start same psoc is used to populate new service
9618 * ready data
9619 */
9620 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309621
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309622done:
9623 hdd_ctx->stop_modules_in_progress = false;
9624 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309625 EXIT();
9626
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309627 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309628
9629}
9630
9631/**
9632 * hdd_iface_change_callback() - Function invoked when stop modules expires
9633 * @priv: pointer to hdd context
9634 *
9635 * This function is invoked when the timer waiting for the interface change
9636 * expires, it shall cut-down the power to wlan and stop all the modules.
9637 *
9638 * Return: void
9639 */
9640static void hdd_iface_change_callback(void *priv)
9641{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009642 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309643 int ret;
9644 int status = wlan_hdd_validate_context(hdd_ctx);
9645
9646 if (status)
9647 return;
9648
9649 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009650 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009651 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309652 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009653 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309654 EXIT();
9655}
9656
9657/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309658 * hdd_state_info_dump() - prints state information of hdd layer
9659 * @buf: buffer pointer
9660 * @size: size of buffer to be filled
9661 *
9662 * This function is used to dump state information of hdd layer
9663 *
9664 * Return: None
9665 */
9666static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9667{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009668 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309669 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9670 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009671 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009672 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309673 uint16_t len = 0;
9674 char *buf = *buf_ptr;
9675
9676 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9677 if (!hdd_ctx) {
9678 hdd_err("Failed to get hdd context ");
9679 return;
9680 }
9681
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009682 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309683
9684 len += scnprintf(buf + len, *size - len,
9685 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9686 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009687 "\n is_scheduler_suspended %d",
9688 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309689
9690 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9691
9692 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009693 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309694 if (adapter->dev)
9695 len += scnprintf(buf + len, *size - len,
9696 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009697 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309698 "\n device_mode: %d", adapter->device_mode);
9699 switch (adapter->device_mode) {
9700 case QDF_STA_MODE:
9701 case QDF_P2P_CLIENT_MODE:
9702 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9703 len += scnprintf(buf + len, *size - len,
9704 "\n connState: %d",
9705 hdd_sta_ctx->conn_info.connState);
9706 break;
9707
9708 default:
9709 break;
9710 }
9711 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9712 adapter_node = next;
9713 }
9714
9715 *size -= len;
9716 *buf_ptr += len;
9717}
9718
9719/**
9720 * hdd_register_debug_callback() - registration function for hdd layer
9721 * to print hdd state information
9722 *
9723 * Return: None
9724 */
9725static void hdd_register_debug_callback(void)
9726{
9727 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9728}
9729
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309730/*
9731 * wlan_init_bug_report_lock() - Initialize bug report lock
9732 *
9733 * This function is used to create bug report lock
9734 *
9735 * Return: None
9736 */
9737static void wlan_init_bug_report_lock(void)
9738{
9739 p_cds_contextType p_cds_context;
9740
9741 p_cds_context = cds_get_global_context();
9742 if (!p_cds_context) {
9743 hdd_err("cds context is NULL");
9744 return;
9745 }
9746
9747 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9748}
9749
Mohit Khannaf8f96822017-05-17 17:11:59 -07009750void hdd_dp_trace_init(struct hdd_config *config)
9751{
9752
9753 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9754 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9755 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9756 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9757 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9758 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9759 uint8_t num_entries = 0;
9760
9761 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9762 &num_entries, sizeof(config_params));
9763
9764 /* calculating, num bw timer intervals in a second (1000ms) */
9765 if (config->busBandwidthComputeInterval)
9766 thresh_time_limit =
9767 (1000 / config->busBandwidthComputeInterval);
9768 else
9769 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9770
9771 switch (num_entries) {
9772 case 4:
9773 proto_bitmap = config_params[3];
9774 case 3:
9775 verbosity = config_params[2];
9776 case 2:
9777 thresh = config_params[1];
9778 case 1:
9779 live_mode = config_params[0];
9780 default:
9781 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9782 live_mode, thresh, thresh_time_limit,
9783 verbosity, proto_bitmap);
9784 };
9785
9786 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9787 verbosity, proto_bitmap);
9788
9789}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309790/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009791 * hdd_wlan_startup() - HDD init function
9792 * @dev: Pointer to the underlying device
9793 *
9794 * This is the driver startup code executed once a WLAN device has been detected
9795 *
9796 * Return: 0 for success, < 0 for failure
9797 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309798int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009799{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309800 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009801 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009802 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009803 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009804
9805 ENTER();
9806
Arun Khandavallifae92942016-08-01 13:31:08 +05309807 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009808
9809 if (IS_ERR(hdd_ctx))
9810 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009811
Abhishek Singhe9068f12017-03-31 14:14:52 +05309812 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9813 DEFAULT_PSOC_ID);
9814 if (ret) {
9815 hdd_err("Psoc creation fails!");
9816 QDF_BUG(0);
9817 goto err_hdd_free_context;
9818 }
9819
Arun Khandavallifae92942016-08-01 13:31:08 +05309820 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9821 hdd_iface_change_callback, (void *)hdd_ctx);
9822
9823 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309824#ifdef FEATURE_WLAN_CH_AVOID
9825 mutex_init(&hdd_ctx->avoid_freq_lock);
9826#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309827
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009828 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009829 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309830
Jeff Johnson957bc272017-02-02 08:54:48 -08009831 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309832 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009833 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009834 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009835 }
9836
Yingying Tang80e15f32016-09-27 18:23:01 +08009837 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009838
Anurag Chouhan6d760662016-02-20 16:05:43 +05309839 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009840
9841 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009842 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309843 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009844 }
9845
Prashanth Bhatta07998752016-04-28 12:35:33 -07009846 ret = hdd_wiphy_init(hdd_ctx);
9847 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009848 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309849 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009850 }
9851
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309852 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009853 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309854
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309855 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009856 goto err_wiphy_unregister;
9857
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309858 wlan_hdd_init_chan_info(hdd_ctx);
9859
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009860 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009861
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309862 ret = hdd_register_notifiers(hdd_ctx);
9863 if (ret)
9864 goto err_ipa_cleanup;
9865
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009866 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009867
Jeff Johnson957bc272017-02-02 08:54:48 -08009868 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9869 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009870 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009871 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009872 }
9873
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009874 hdd_release_rtnl_lock();
9875 rtnl_held = false;
9876
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009877 wlan_hdd_update_11n_mode(hdd_ctx->config);
9878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009879#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309880 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309881 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009882 hdd_skip_acs_scan_timer_handler,
9883 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309884 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009885 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009886 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009887#endif
9888
Prashanth Bhattaab004382016-10-11 16:08:11 -07009889 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009890
Jeff Johnson9afc5012016-09-23 13:56:27 -07009891 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009892
Nirav Shahbd36b062016-07-18 11:12:59 +05309893 if (hdd_ctx->rps)
9894 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009895
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309896 status = wlansap_global_init();
9897 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009898 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009899
Komal Seelam8634b772016-09-29 12:12:24 +05309900 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009901 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309902 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009903
Arun Khandavallifae92942016-08-01 13:31:08 +05309904 if (hdd_ctx->config->fIsImpsEnabled)
9905 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309906
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309907 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9908 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309909 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309910
Sachin Ahujadddd2632017-03-07 19:07:24 +05309911 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009912 goto success;
9913
Jeff Johnson957bc272017-02-02 08:54:48 -08009914err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009915 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009916
Jeff Johnson46bde382017-02-01 15:31:16 -08009917err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309918 if (rtnl_held)
9919 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009920
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309921 unregister_netdevice_notifier(&hdd_netdev_notifier);
9922
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309923err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309924 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009925
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009926err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009927 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009928
Arun Khandavallifae92942016-08-01 13:31:08 +05309929err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009930 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309931
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009932err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309933 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009934 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309935 if (!QDF_IS_STATUS_SUCCESS(status)) {
9936 hdd_err("Failed to close CDS Scheduler");
9937 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9938 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009939 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009940
Houston Hoffman47a4a052016-11-14 23:22:44 -08009941 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009942 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009943 hdd_exit_netlink_services(hdd_ctx);
9944
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309945 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009946
Dustin Brown20912462017-06-07 13:48:25 -07009947 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9948
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009949err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309950 if (cds_is_fw_down())
9951 hdd_err("Not setting the complete event as fw is down");
9952 else
9953 hdd_start_complete(ret);
9954
Arun Khandavallifae92942016-08-01 13:31:08 +05309955 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9956 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009957 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009958 return -EIO;
9959
9960success:
9961 EXIT();
9962 return 0;
9963}
9964
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009965/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309966 * hdd_wlan_update_target_info() - update target type info
9967 * @hdd_ctx: HDD context
9968 * @context: hif context
9969 *
9970 * Update target info received from firmware in hdd context
9971 * Return:None
9972 */
9973
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009974void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309975{
9976 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9977
9978 if (!tgt_info) {
9979 hdd_err("Target info is Null");
9980 return;
9981 }
9982
9983 hdd_ctx->target_type = tgt_info->target_type;
9984}
9985
9986/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05309987 * hdd_get_nud_stats_cb() - callback api to update the stats
9988 * received from the firmware
9989 * @data: pointer to adapter.
9990 * @rsp: pointer to data received from FW.
9991 *
9992 * This is called when wlan driver received response event for
9993 * get arp stats to firmware.
9994 *
9995 * Return: None
9996 */
9997static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
9998{
9999 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10000 struct hdd_nud_stats_context *context;
10001 int status;
10002 struct hdd_adapter *adapter = NULL;
10003
10004 ENTER();
10005
10006 if (!rsp) {
10007 hdd_err("data is null");
10008 return;
10009 }
10010
10011 status = wlan_hdd_validate_context(hdd_ctx);
10012 if (0 != status)
10013 return;
10014
10015 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10016 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10017 hdd_err("Invalid adapter or adapter has invalid magic");
10018 return;
10019 }
10020
10021 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10022 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10023 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10024 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10025 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10026 rsp->out_of_order_arp_rsp_drop_cnt);
10027 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10028 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10029 hdd_notice("rsp->ba_session_establishment_status :%x",
10030 rsp->ba_session_establishment_status);
10031
10032 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10033 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10034 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10035 adapter->dad |= rsp->dad_detected;
10036 adapter->con_status = rsp->connect_status;
10037
10038 spin_lock(&hdd_context_lock);
10039 context = &hdd_ctx->nud_stats_context;
10040 complete(&context->response_event);
10041 spin_unlock(&hdd_context_lock);
10042
10043 EXIT();
10044
10045 return;
10046}
10047
10048/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010049 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010050 * @hdd_ctx: HDD context
10051 *
10052 * Register the HDD callbacks to CDS/SME.
10053 *
10054 * Return: 0 for success or Error code for failure
10055 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010056int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010057{
10058 QDF_STATUS status;
10059 int ret = 0;
10060
10061 ENTER();
10062
10063 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10064
10065 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10066 hdd_send_oem_data_rsp_msg);
10067
10068 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10069 wlan_hdd_cfg80211_fw_mem_dump_cb);
10070 if (!QDF_IS_STATUS_SUCCESS(status)) {
10071 hdd_err("Failed to register memdump callback");
10072 ret = -EINVAL;
10073 return ret;
10074 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010075 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10076 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010077 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10078 sme_nan_register_callback(hdd_ctx->hHal,
10079 wlan_hdd_cfg80211_nan_callback);
10080 sme_stats_ext_register_callback(hdd_ctx->hHal,
10081 wlan_hdd_cfg80211_stats_ext_callback);
10082
10083 sme_ext_scan_register_callback(hdd_ctx->hHal,
10084 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010085 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10086 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010087
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010088 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10089 hdd_rssi_threshold_breached);
10090
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010091 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10092
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010093 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10094 wlan_hdd_cfg80211_link_layer_stats_callback);
10095
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010096 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10097
Zhang Qianca38fb12016-12-23 11:10:48 +080010098 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10099 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10100
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010101 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10102 hdd_lost_link_info_cb);
10103 /* print error and not block the startup process */
10104 if (!QDF_IS_STATUS_SUCCESS(status))
10105 hdd_err("set lost link info callback failed");
10106
Poddar, Siddarth34872782017-08-10 14:08:51 +053010107 ret = hdd_register_data_stall_detect_cb();
10108 if (ret) {
10109 hdd_err("Register data stall detect detect callback failed.");
10110 return ret;
10111 }
10112
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010113 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10114
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010115 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010116 hdd_set_connection_in_progress,
10117 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010118
10119 status = sme_congestion_register_callback(hdd_ctx->hHal,
10120 hdd_update_cca_info_cb);
10121 if (!QDF_IS_STATUS_SUCCESS(status))
10122 hdd_err("set congestion callback failed");
10123
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010124 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10125 hdd_bt_activity_cb);
10126 if (!QDF_IS_STATUS_SUCCESS(status))
10127 hdd_err("set bt activity info callback failed");
10128
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010129 EXIT();
10130
10131 return ret;
10132}
10133
10134/**
10135 * hdd_deregister_cb() - De-Register HDD callbacks.
10136 * @hdd_ctx: HDD context
10137 *
10138 * De-Register the HDD callbacks to CDS/SME.
10139 *
10140 * Return: void
10141 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010142void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010143{
10144 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010145 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010146
10147 ENTER();
10148
10149 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10150 if (!QDF_IS_STATUS_SUCCESS(status))
10151 hdd_err("De-register of dcc stats callback failed: %d",
10152 status);
10153
10154 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010155 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10156
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010157 sme_stats_ext_register_callback(hdd_ctx->hHal,
10158 wlan_hdd_cfg80211_stats_ext_callback);
10159
10160 sme_nan_deregister_callback(hdd_ctx->hHal);
10161 status = sme_reset_tsfcb(hdd_ctx->hHal);
10162 if (!QDF_IS_STATUS_SUCCESS(status))
10163 hdd_err("Failed to de-register tsfcb the callback:%d",
10164 status);
10165 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10166 if (!QDF_IS_STATUS_SUCCESS(status))
10167 hdd_err("Failed to de-register the fw mem dump callback: %d",
10168 status);
10169
Poddar, Siddarth34872782017-08-10 14:08:51 +053010170 ret = hdd_deregister_data_stall_detect_cb();
10171 if (ret)
10172 hdd_err("Failed to de-register data stall detect event callback");
10173
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010174 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10175 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10176
10177 EXIT();
10178}
10179
10180/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010181 * hdd_softap_sta_deauth() - handle deauth req from HDD
10182 * @adapter: Pointer to the HDD
10183 * @enable: bool value
10184 *
10185 * This to take counter measure to handle deauth req from HDD
10186 *
10187 * Return: None
10188 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010189QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010190 struct tagCsrDelStaParams *pDelStaParams)
10191{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010192 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010193
10194 ENTER();
10195
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010196 /* Ignore request to deauth bcmc station */
10197 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010198 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010199
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010200 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010201 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10202 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010203
10204 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010205 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010206}
10207
10208/**
10209 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10210 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010211 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010212 *
10213 * This to take counter measure to handle deauth req from HDD
10214 *
10215 * Return: None
10216 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010217void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010218 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010219{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010220 ENTER();
10221
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010222 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010223 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010224 return;
10225
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010226 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010227 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010228}
10229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010230/**
10231 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10232 * @hdd_ctx: HDD Context
10233 *
10234 * API to find if there is any STA or P2P-Client is connected
10235 *
10236 * Return: true if connected; false otherwise
10237 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010238QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010239{
10240 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10241}
10242
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010243/**
10244 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10245 * @adapter: HDD adapter pointer
10246 *
10247 * This function loop through each adapter and disable roaming on each STA
10248 * device mode except the input adapter.
10249 *
10250 * Note: On the input adapter roaming is not enabled yet hence no need to
10251 * disable.
10252 *
10253 * Return: None
10254 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010255void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010256{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010257 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010258 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010259 hdd_adapter_list_node_t *adapterNode = NULL;
10260 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010261 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010262
10263 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010264 hdd_ctx->config->isRoamOffloadScanEnabled &&
10265 QDF_STA_MODE == adapter->device_mode &&
10266 policy_mgr_is_sta_active_connection_exists(
10267 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010268 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010269 adapter->sessionId);
10270 /*
10271 * Loop through adapter and disable roaming for each STA device
10272 * mode except the input adapter.
10273 */
10274 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10275
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010276 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010277 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010278
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010279 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010280 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010281 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010282 adapterIdx->sessionId);
10283 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10284 (adapterIdx),
10285 adapterIdx->sessionId, 0);
10286 }
10287
10288 status = hdd_get_next_adapter(hdd_ctx,
10289 adapterNode,
10290 &pNext);
10291 adapterNode = pNext;
10292 }
10293 }
10294}
10295
10296/**
10297 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10298 * @adapter: HDD adapter pointer
10299 *
10300 * This function loop through each adapter and enable roaming on each STA
10301 * device mode except the input adapter.
10302 * Note: On the input adapter no need to enable roaming because link got
10303 * disconnected on this.
10304 *
10305 * Return: None
10306 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010307void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010308{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010309 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010310 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010311 hdd_adapter_list_node_t *adapterNode = NULL;
10312 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010313 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010314
10315 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010316 hdd_ctx->config->isRoamOffloadScanEnabled &&
10317 QDF_STA_MODE == adapter->device_mode &&
10318 policy_mgr_is_sta_active_connection_exists(
10319 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010320 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010321 adapter->sessionId);
10322 /*
10323 * Loop through adapter and enable roaming for each STA device
10324 * mode except the input adapter.
10325 */
10326 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10327
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010328 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010329 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010330
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010331 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010332 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010333 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010334 adapterIdx->sessionId);
10335 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10336 (adapterIdx),
10337 adapterIdx->sessionId,
10338 REASON_CONNECT);
10339 }
10340
10341 status = hdd_get_next_adapter(hdd_ctx,
10342 adapterNode,
10343 &pNext);
10344 adapterNode = pNext;
10345 }
10346 }
10347}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010348
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010349/**
10350 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10351 * @skb: sk buffer pointer
10352 *
10353 * Sends the bcast message to SVC multicast group with generic nl socket
10354 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10355 *
10356 * Return: None
10357 */
10358static void nl_srv_bcast_svc(struct sk_buff *skb)
10359{
10360#ifdef CNSS_GENL
10361 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10362#else
10363 nl_srv_bcast(skb);
10364#endif
10365}
10366
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010367void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010368{
10369 struct sk_buff *skb;
10370 struct nlmsghdr *nlh;
10371 tAniMsgHdr *ani_hdr;
10372 void *nl_data = NULL;
10373 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010374 struct radio_index_tlv *radio_info;
10375 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010376
10377 if (in_interrupt() || irqs_disabled() || in_atomic())
10378 flags = GFP_ATOMIC;
10379
10380 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10381
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010382 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010383 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010384
10385 nlh = (struct nlmsghdr *)skb->data;
10386 nlh->nlmsg_pid = 0; /* from kernel */
10387 nlh->nlmsg_flags = 0;
10388 nlh->nlmsg_seq = 0;
10389 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10390
10391 ani_hdr = NLMSG_DATA(nlh);
10392 ani_hdr->type = type;
10393
10394 switch (type) {
10395 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010396 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010397 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010398 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010399 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010400 ani_hdr->length = 0;
10401 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010402 break;
10403 case WLAN_SVC_WLAN_STATUS_IND:
10404 case WLAN_SVC_WLAN_VERSION_IND:
10405 case WLAN_SVC_DFS_CAC_START_IND:
10406 case WLAN_SVC_DFS_CAC_END_IND:
10407 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10408 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10409 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010410 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010411 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010412 ani_hdr->length = len;
10413 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10414 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10415 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010416 break;
10417
10418 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010419 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010420 type);
10421 kfree_skb(skb);
10422 return;
10423 }
10424
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010425 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010426 * Add radio index at the end of the svc event in TLV format
10427 * to maintain the backward compatibility with userspace
10428 * applications.
10429 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010430
10431 tlv_len = 0;
10432
10433 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10434 < WLAN_NL_MAX_PAYLOAD) {
10435 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10436 sizeof(*ani_hdr) + len);
10437 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10438 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10439 radio_info->radio = radio;
10440 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010441 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010442 "Added radio index tlv - radio index %d",
10443 radio_info->radio);
10444 }
10445
10446 nlh->nlmsg_len += tlv_len;
10447 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10448
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010449 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010450}
10451
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010452#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10453void wlan_hdd_auto_shutdown_cb(void)
10454{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010455 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010456
10457 if (!hdd_ctx)
10458 return;
10459
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010460 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010461 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10462 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010463}
10464
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010465void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010466{
10467 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010468 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010469 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010470 bool ap_connected = false, sta_connected = false;
10471 tHalHandle hal_handle;
10472
10473 hal_handle = hdd_ctx->hHal;
10474 if (hal_handle == NULL)
10475 return;
10476
10477 if (hdd_ctx->config->WlanAutoShutdown == 0)
10478 return;
10479
10480 if (enable == false) {
10481 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010482 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010483 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010484 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010485 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010486 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010487 return;
10488 }
10489
10490 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010491 if (policy_mgr_concurrent_open_sessions_running(
10492 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010493 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10494
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010495 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010496 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010497 if (adapter
10498 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010499 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010500 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10501 conn_info.connState ==
10502 eConnectionState_Associated) {
10503 sta_connected = true;
10504 break;
10505 }
10506 }
10507 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010508 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010509 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10510 bApActive == true) {
10511 ap_connected = true;
10512 break;
10513 }
10514 }
10515 status = hdd_get_next_adapter(hdd_ctx,
10516 adapterNode,
10517 &pNext);
10518 adapterNode = pNext;
10519 }
10520 }
10521
10522 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010523 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010524 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010525 }
Jeff Johnson68755312017-02-10 11:46:55 -080010526
10527 if (sme_set_auto_shutdown_timer(hal_handle,
10528 hdd_ctx->config->WlanAutoShutdown)
10529 != QDF_STATUS_SUCCESS)
10530 hdd_err("Failed to start wlan auto shutdown timer");
10531 else
10532 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10533 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010534}
10535#endif
10536
Jeff Johnson9d295242017-08-29 14:39:48 -070010537struct hdd_adapter *hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010538 bool check_start_bss)
10539{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010540 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010541 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010542 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010543 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10544
10545 con_sap_adapter = NULL;
10546
10547 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010548 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010549 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010550 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10551 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010552 adapter != this_sap_adapter) {
10553 if (check_start_bss) {
10554 if (test_bit(SOFTAP_BSS_STARTED,
10555 &adapter->event_flags)) {
10556 con_sap_adapter = adapter;
10557 break;
10558 }
10559 } else {
10560 con_sap_adapter = adapter;
10561 break;
10562 }
10563 }
10564 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10565 adapterNode = pNext;
10566 }
10567
10568 return con_sap_adapter;
10569}
10570
10571#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010572static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010573{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010574 return adapter->device_mode == QDF_STA_MODE ||
10575 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010576}
10577
Jeff Johnson9d295242017-08-29 14:39:48 -070010578static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010579{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010580 return adapter->device_mode == QDF_SAP_MODE ||
10581 adapter->device_mode == QDF_P2P_GO_MODE;
10582}
10583
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010584static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010585{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010586 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010587 hdd_adapter_list_node_t *node;
10588
10589 status = hdd_get_front_adapter(hdd_ctx, &node);
10590 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010591 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010592
10593 if (adapter &&
10594 hdd_adapter_is_sta(adapter) &&
10595 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10596 conn_info.connState == eConnectionState_Associated) {
10597 return true;
10598 }
10599
10600 if (adapter &&
10601 hdd_adapter_is_ap(adapter) &&
10602 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10603 return true;
10604 }
10605
10606 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10607 }
10608
10609 return false;
10610}
10611
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010612static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010613{
10614 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010615
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010616 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010617 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010618 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010619
Dustin Brown5ec6b552017-03-31 12:11:40 -070010620 return is_running;
10621}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010622
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010623static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010624{
10625 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10626 hdd_ctx->bus_bw_timer_running = true;
10627 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10628 hdd_ctx->config->busBandwidthComputeInterval);
10629 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10630}
10631
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010632void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010633{
10634 ENTER();
10635
10636 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10637 hdd_debug("Bandwidth compute timer already started");
10638 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010639 }
10640
Dustin Brown5ec6b552017-03-31 12:11:40 -070010641 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10642
10643 EXIT();
10644}
10645
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010646void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010647{
10648 ENTER();
10649
10650 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10651 hdd_debug("Bandwidth compute timer already started");
10652 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010653 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010654
10655 if (hdd_any_adapter_is_assoc(hdd_ctx))
10656 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10657
10658 EXIT();
10659}
10660
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010661static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010662{
10663 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10664
10665 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10666 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10667 hdd_ctx->bus_bw_timer_running = false;
10668 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10669
10670 hdd_reset_tcp_delack(hdd_ctx);
10671}
10672
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010673void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010674{
10675 ENTER();
10676
10677 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10678 hdd_debug("Bandwidth compute timer already stopped");
10679 return;
10680 }
10681
10682 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10683
10684 EXIT();
10685}
10686
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010687void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010688{
10689 ENTER();
10690
10691 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10692 hdd_debug("Bandwidth compute timer already stopped");
10693 return;
10694 }
10695
10696 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10697 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10698
10699 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010700}
10701#endif
10702
10703/**
10704 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10705 * and sta's operating channel.
10706 * @sta_adapter: Describe the first argument to foobar.
10707 * @ap_adapter: Describe the second argument to foobar.
10708 * @roam_profile: Roam profile of AP to which STA wants to connect.
10709 * @concurrent_chnl_same: If both SAP and STA channels are same then
10710 * set this flag to true else false.
10711 *
10712 * This function checks the sap's operating channel and sta's operating channel.
10713 * if both are same then it will return false else it will restart the sap in
10714 * sta's channel and return true.
10715 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010716 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010717 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010718QDF_STATUS wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10719 struct hdd_adapter *ap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010720 tCsrRoamProfile *roam_profile,
10721 tScanResultHandle *scan_cache,
10722 bool *concurrent_chnl_same)
10723{
Jeff Johnson87251032017-08-29 13:31:11 -070010724 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010725 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010726 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010727 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010728 *concurrent_chnl_same = true;
10729
10730 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10731 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010732 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010733 scan_cache,
10734 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010735 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010736 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010737 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10738 if (hdd_ap_ctx->operatingChannel != channel_id) {
10739 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010740 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010741 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010742 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010743 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10744 if (hdd_ap_ctx->operatingChannel != channel_id) {
10745 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010746 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010747 }
10748 }
10749 } else {
10750 /*
10751 * Lets handle worst case scenario here, Scan cache lookup is
10752 * failed so we have to stop the SAP to avoid any channel
10753 * discrepancy between SAP's channel and STA's channel.
10754 * Return the status as failure so caller function could know
10755 * that scan look up is failed.
10756 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010757 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010758 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010759 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010760 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010761}
10762
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010763/**
10764 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10765 * @ap_adapter: SAP adapter
10766 *
10767 * This function will process the stopping of sap adapter.
10768 *
10769 * Return: None
10770 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010771void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010772{
Jeff Johnson87251032017-08-29 13:31:11 -070010773 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010774 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010775 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010776 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010777
10778 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010779 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010780 return;
10781 }
10782
10783 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10784 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010785 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010786 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010787
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010788 mutex_lock(&hdd_ctx->sap_lock);
10789 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010790 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010791 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10792 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010793 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010794 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010795 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010796 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010797 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010798 qdf_stop_bss_event,
10799 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010800 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010801 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010802 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010803 return;
10804 }
10805 }
10806 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010807 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10808 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010809 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010810 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010811 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010812 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010813 }
10814 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010815}
10816
10817/**
10818 * wlan_hdd_start_sap() - this function starts bss of SAP.
10819 * @ap_adapter: SAP adapter
10820 *
10821 * This function will process the starting of sap adapter.
10822 *
10823 * Return: None
10824 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010825void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010826{
Jeff Johnson87251032017-08-29 13:31:11 -070010827 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010828 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010829 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010830 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010831 tsap_Config_t *sap_config;
10832
10833 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010834 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010835 return;
10836 }
10837
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010838 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010839 hdd_err("SoftAp role has not been enabled");
10840 return;
10841 }
10842
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010843 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10844 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10845 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10846 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10847
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010848 mutex_lock(&hdd_ctx->sap_lock);
10849 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10850 goto end;
10851
10852 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010853 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010854 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10855 goto end;
10856 }
10857
Wei Song2f76f642016-11-18 16:32:53 +080010858 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010859 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10860 &hdd_ap_ctx->sapConfig,
10861 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010862 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010863 goto end;
10864
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010865 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010866 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010867 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010868 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010869 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010870 goto end;
10871 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010872 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010873 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010874 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010875 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10876 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010877 ap_adapter->sessionId);
10878 hostapd_state->bCommit = true;
10879
10880end:
10881 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010882 /* SAP context and beacon cleanup will happen during driver unload
10883 * in hdd_stop_adapter
10884 */
10885 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10886
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010887}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010888
10889/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010890 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10891 * mac scan config
10892 * @status: Status of set antenna mode
10893 *
10894 * Callback on setting the dual mac configuration
10895 *
10896 * Return: None
10897 */
10898void wlan_hdd_soc_set_antenna_mode_cb(
10899 enum set_antenna_mode_status status)
10900{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010901 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010902
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010903 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010904
10905 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10906 if (0 != wlan_hdd_validate_context(hdd_ctx))
10907 return;
10908
10909 /* Signal the completion of set dual mac config */
10910 complete(&hdd_ctx->set_antenna_mode_cmpl);
10911}
10912
10913/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010914 * hdd_get_fw_version() - Get FW version
10915 * @hdd_ctx: pointer to HDD context.
10916 * @major_spid: FW version - major spid.
10917 * @minor_spid: FW version - minor spid
10918 * @ssid: FW version - ssid
10919 * @crmid: FW version - crmid
10920 *
10921 * This function is called to get the firmware build version stored
10922 * as part of the HDD context
10923 *
10924 * Return: None
10925 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010926void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010927 uint32_t *major_spid, uint32_t *minor_spid,
10928 uint32_t *siid, uint32_t *crmid)
10929{
10930 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10931 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10932 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10933 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10934}
10935
10936#ifdef QCA_CONFIG_SMP
10937/**
10938 * wlan_hdd_get_cpu() - get cpu_index
10939 *
10940 * Return: cpu_index
10941 */
10942int wlan_hdd_get_cpu(void)
10943{
10944 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010945
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010946 put_cpu();
10947 return cpu_index;
10948}
10949#endif
10950
10951/**
10952 * hdd_get_fwpath() - get framework path
10953 *
10954 * This function is used to get the string written by
10955 * userspace to start the wlan driver
10956 *
10957 * Return: string
10958 */
10959const char *hdd_get_fwpath(void)
10960{
10961 return fwpath.string;
10962}
10963
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010964static int hdd_qdf_print_init(void)
10965{
10966 int qdf_print_idx;
10967 QDF_STATUS status;
10968
10969 status = qdf_print_setup();
10970 if (status != QDF_STATUS_SUCCESS) {
10971 pr_err("qdf_print_setup failed\n");
10972 return -EINVAL;
10973 }
10974
10975 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10976
10977 if (qdf_print_idx < 0) {
10978 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10979 qdf_print_idx);
10980 return -EINVAL;
10981 }
10982
10983 qdf_set_pidx(qdf_print_idx);
10984
10985 return 0;
10986}
10987
10988static void hdd_qdf_print_deinit(void)
10989{
10990 int qdf_print_idx;
10991
10992 qdf_print_idx = qdf_get_pidx();
10993 qdf_print_ctrl_cleanup(qdf_print_idx);
10994}
10995
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010996/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010997 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010998 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010999 * This function initilizes CDS global context with the help of cds_init. This
11000 * has to be the first function called after probe to get a valid global
11001 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011002 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011003 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011004 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011005int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011006{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011007 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011008 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011009
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011010 status = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011011
11012 wlan_init_bug_report_lock();
11013
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011014#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11015 wlan_logging_sock_init_svc();
11016#endif
11017
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011018 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011019 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011020 ret = -ENOMEM;
11021 goto err_out;
11022 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011023
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011024 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11025 (void *)hdd_drv_ops_inactivity_handler, NULL,
11026 QDF_TIMER_TYPE_SW);
11027
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011028 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011029 hdd_qdf_print_init();
11030
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011031 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011032
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011033err_out:
11034 return ret;
11035}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011036
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011037/**
11038 * hdd_deinit() - Deinitialize Driver
11039 *
11040 * This function frees CDS global context with the help of cds_deinit. This
11041 * has to be the last function call in remove callback to free the global
11042 * context.
11043 */
11044void hdd_deinit(void)
11045{
Dustin Brownedce4a52017-05-10 11:59:15 -070011046 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011047 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011048
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011049 hdd_qdf_print_deinit();
11050
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011051#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11052 wlan_logging_sock_deinit_svc();
11053#endif
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011054
11055 wlan_destroy_bug_report_lock();
11056 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011057}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011058
Yue Ma6e7b1a02017-04-03 14:17:46 -070011059#ifdef QCA_WIFI_NAPIER_EMULATION
11060#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11061#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011062#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011063#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011064
Sachin Ahujadddd2632017-03-07 19:07:24 +053011065static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11066 struct file *file)
11067{
11068 return 0;
11069}
11070
11071static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11072 const char __user *user_buf,
11073 size_t count,
11074 loff_t *f_pos)
11075{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011076 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011077 static const char wlan_off_str[] = "OFF";
11078 static const char wlan_on_str[] = "ON";
11079 int ret;
11080 unsigned long rc;
11081
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011082 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011083 pr_err("Failed to read buffer\n");
11084 return -EINVAL;
11085 }
11086
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011087 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011088 pr_debug("Wifi turning off from UI\n");
11089 goto exit;
11090 }
11091
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011092 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011093 pr_err("Invalid value received from framework");
11094 goto exit;
11095 }
11096
11097 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011098 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011099 rc = wait_for_completion_timeout(&wlan_start_comp,
11100 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11101 if (!rc) {
11102 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11103 ret = -EINVAL;
11104 hdd_start_complete(ret);
11105 return ret;
11106 }
11107
11108 hdd_start_complete(0);
11109 }
11110
11111exit:
11112 return count;
11113}
11114
11115
11116const struct file_operations wlan_hdd_state_fops = {
11117 .owner = THIS_MODULE,
11118 .open = wlan_hdd_state_ctrl_param_open,
11119 .write = wlan_hdd_state_ctrl_param_write,
11120};
11121
11122static int wlan_hdd_state_ctrl_param_create(void)
11123{
11124 unsigned int wlan_hdd_state_major = 0;
11125 int ret;
11126 struct device *dev;
11127
11128 device = MKDEV(wlan_hdd_state_major, 0);
11129
11130 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11131 if (ret) {
11132 pr_err("Failed to register qcwlanstate");
11133 goto dev_alloc_err;
11134 }
11135 wlan_hdd_state_major = MAJOR(device);
11136
11137 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11138 if (IS_ERR(class)) {
11139 pr_err("wlan_hdd_state class_create error");
11140 goto class_err;
11141 }
11142
11143 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11144 if (IS_ERR(dev)) {
11145 pr_err("wlan_hdd_statedevice_create error");
11146 goto err_class_destroy;
11147 }
11148
11149 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11150 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11151 if (ret) {
11152 pr_err("Failed to add cdev error");
11153 goto cdev_add_err;
11154 }
11155
11156 pr_info("wlan_hdd_state %s major(%d) initialized",
11157 WLAN_MODULE_NAME, wlan_hdd_state_major);
11158
11159 return 0;
11160
11161cdev_add_err:
11162 device_destroy(class, device);
11163err_class_destroy:
11164 class_destroy(class);
11165class_err:
11166 unregister_chrdev_region(device, dev_num);
11167dev_alloc_err:
11168 return -ENODEV;
11169}
11170
11171static void wlan_hdd_state_ctrl_param_destroy(void)
11172{
11173 cdev_del(&wlan_hdd_state_cdev);
11174 device_destroy(class, device);
11175 class_destroy(class);
11176 unregister_chrdev_region(device, dev_num);
11177
11178 pr_info("Device node unregistered");
11179}
11180
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011181/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011182 * component_init - API to init cld component's
11183 *
11184 * Return: None
11185 */
11186static void component_init(void)
11187{
11188 pmo_init();
11189}
11190
11191/**
11192 * component_deinit - API to deinit cld component's
11193 *
11194 * Return: None
11195 */
11196static void component_deinit(void)
11197{
11198 pmo_deinit();
11199}
11200
11201/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011202 * __hdd_module_init - Module init helper
11203 *
11204 * Module init helper function used by both module and static driver.
11205 *
11206 * Return: 0 for success, errno on failure
11207 */
11208static int __hdd_module_init(void)
11209{
11210 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011211
Dustin Brownab482ac2017-06-09 17:00:44 -070011212 pr_err("%s: Loading driver v%s (%s)%s\n",
11213 WLAN_MODULE_NAME,
11214 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011215 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011216 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011217
Sachin Ahujadddd2632017-03-07 19:07:24 +053011218 ret = wlan_hdd_state_ctrl_param_create();
11219 if (ret) {
11220 pr_err("wlan_hdd_state_create:%x\n", ret);
11221 goto err_dev_state;
11222 }
11223
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011224 pld_init();
11225
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011226 ret = hdd_init();
11227 if (ret) {
11228 pr_err("hdd_init failed %x\n", ret);
11229 goto err_hdd_init;
11230 }
11231
Rajeev Kumar97767a02016-11-30 11:20:40 -080011232 dispatcher_init();
11233
Mukul Sharmad75a6672017-06-22 15:40:53 +053011234 /* Ensure to call post objmgr init */
11235 component_init();
11236
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011237 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011238
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011239 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011240
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011241 ret = wlan_hdd_register_driver();
11242 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011243 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11244 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011245 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011246 }
11247
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011248 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011249
11250 return 0;
11251out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011252 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011253 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011254 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011255
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011256err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011257 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011258 wlan_hdd_state_ctrl_param_destroy();
11259err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011260 return ret;
11261}
11262
11263/**
11264 * __hdd_module_exit - Module exit helper
11265 *
11266 * Module exit helper function used by both module and static driver.
11267 */
11268static void __hdd_module_exit(void)
11269{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011270
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011271 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11272 QWLAN_VERSIONSTR);
11273
bings6028ee82017-03-29 07:51:40 +080011274 cds_set_unload_in_progress(true);
11275
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011276 hdd_wait_for_recovery_completion();
11277
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011278 wlan_hdd_unregister_driver();
11279
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011280 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011281
Mukul Sharmad75a6672017-06-22 15:40:53 +053011282 /* Ensure to call prior to objmgr deinit */
11283 component_deinit();
11284
Rajeev Kumar97767a02016-11-30 11:20:40 -080011285 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011286 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011287 pld_deinit();
11288
Sachin Ahujadddd2632017-03-07 19:07:24 +053011289 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011290}
11291
Arun Khandavallifae92942016-08-01 13:31:08 +053011292#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011293/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011294 * wlan_boot_cb() - Wlan boot callback
11295 * @kobj: object whose directory we're creating the link in.
11296 * @attr: attribute the user is interacting with
11297 * @buff: the buffer containing the user data
11298 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011299 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011300 * This callback is invoked when the fs is ready to start the
11301 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011302 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011303 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011304 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011305static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011306 struct kobj_attribute *attr,
11307 const char *buf,
11308 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011309{
Arun Khandavallifae92942016-08-01 13:31:08 +053011310
Arun Khandavallifae92942016-08-01 13:31:08 +053011311 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011312 pr_err("%s: wlan driver already initialized\n", __func__);
11313 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011314 }
11315
Arun Khandavallifae92942016-08-01 13:31:08 +053011316 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011317 pr_err("%s: wlan driver initialization failed\n", __func__);
11318 return -EIO;
11319 }
11320
11321 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011322
11323 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011324}
Arun Khandavallifae92942016-08-01 13:31:08 +053011325
11326/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011327 * hdd_sysfs_cleanup() - cleanup sysfs
11328 *
11329 * Return: None
11330 *
11331 */
11332static void hdd_sysfs_cleanup(void)
11333{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011334 /* remove from group */
11335 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11336 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11337 wlan_loader->attr_group);
11338
11339 /* unlink the object from parent */
11340 kobject_del(wlan_loader->boot_wlan_obj);
11341
11342 /* free the object */
11343 kobject_put(wlan_loader->boot_wlan_obj);
11344
11345 kfree(wlan_loader->attr_group);
11346 kfree(wlan_loader);
11347
11348 wlan_loader = NULL;
11349}
11350
11351/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011352 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11353 * ready
11354 *
11355 * This is creates the syfs entry boot_wlan. Which shall be invoked
11356 * when the filesystem is ready.
11357 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011358 * QDF API cannot be used here since this function is called even before
11359 * initializing WLAN driver.
11360 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011361 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011362 */
11363static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011364{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011365 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011366
11367 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011368 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011369 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011370
11371 wlan_loader->boot_wlan_obj = NULL;
11372 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11373 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011374 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011375 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011376
11377 wlan_loader->loaded_state = 0;
11378 wlan_loader->attr_group->attrs = attrs;
11379
11380 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11381 kernel_kobj);
11382 if (!wlan_loader->boot_wlan_obj) {
11383 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011384 goto error_return;
11385 }
11386
11387 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11388 wlan_loader->attr_group);
11389 if (ret) {
11390 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11391 goto error_return;
11392 }
11393
11394 return 0;
11395
11396error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011397 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011398
11399 return ret;
11400}
11401
11402/**
11403 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11404 *
11405 * Return: 0 on success or errno on failure
11406 */
11407static int wlan_deinit_sysfs(void)
11408{
Arun Khandavallifae92942016-08-01 13:31:08 +053011409 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011410 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011411 return -EINVAL;
11412 }
11413
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011414 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011415 return 0;
11416}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011417
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011418#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011419
11420#ifdef MODULE
11421/**
11422 * __hdd_module_init - Module init helper
11423 *
11424 * Module init helper function used by both module and static driver.
11425 *
11426 * Return: 0 for success, errno on failure
11427 */
11428static int hdd_module_init(void)
11429{
Arun Khandavallifae92942016-08-01 13:31:08 +053011430 if (__hdd_module_init()) {
11431 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011432 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011433 }
11434
Dustin Brownab482ac2017-06-09 17:00:44 -070011435 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011436}
11437#else
11438static int __init hdd_module_init(void)
11439{
11440 int ret = -EINVAL;
11441
11442 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011443 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011444 pr_err("Failed to create sysfs entry for loading wlan");
11445
11446 return ret;
11447}
11448#endif
11449
11450
11451#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011452/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011453 * hdd_module_exit() - Exit function
11454 *
11455 * This is the driver exit point (invoked when module is unloaded using rmmod)
11456 *
11457 * Return: None
11458 */
11459static void __exit hdd_module_exit(void)
11460{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011461 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011462}
Arun Khandavallifae92942016-08-01 13:31:08 +053011463#else
11464static void __exit hdd_module_exit(void)
11465{
11466 __hdd_module_exit();
11467 wlan_deinit_sysfs();
11468}
11469#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011470
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011471static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11472{
11473 return param_set_copystring(kmessage, kp);
11474}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011475
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011476/**
11477 * is_con_mode_valid() check con mode is valid or not
11478 * @mode: global con mode
11479 *
11480 * Return: TRUE on success FALSE on failure
11481 */
11482static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11483{
11484 switch (mode) {
11485 case QDF_GLOBAL_MONITOR_MODE:
11486 case QDF_GLOBAL_FTM_MODE:
11487 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011488 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011489 return true;
11490 default:
11491 return false;
11492 }
11493}
11494
11495/**
11496 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11497 * @mode: global con mode
11498 *
11499 * Return: adapter mode
11500 */
11501static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11502 enum tQDF_GLOBAL_CON_MODE mode)
11503{
11504
11505 switch (mode) {
11506 case QDF_GLOBAL_MISSION_MODE:
11507 return QDF_STA_MODE;
11508 case QDF_GLOBAL_MONITOR_MODE:
11509 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011510 case QDF_GLOBAL_EPPING_MODE:
11511 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011512 case QDF_GLOBAL_FTM_MODE:
11513 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011514 case QDF_GLOBAL_QVIT_MODE:
11515 return QDF_QVIT_MODE;
11516 default:
11517 return QDF_MAX_NO_OF_MODE;
11518 }
11519}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011520
Dustin Brown27cd9942017-09-27 16:11:44 -070011521static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11522 enum tQDF_GLOBAL_CON_MODE curr_mode)
11523{
11524 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11525 return;
11526
11527 switch (curr_mode) {
11528 case QDF_GLOBAL_MISSION_MODE:
11529 case QDF_GLOBAL_MONITOR_MODE:
11530 case QDF_GLOBAL_FTM_MODE:
11531 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11532 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11533
11534 /* re-use the existing session */
11535 hdd_stop_all_adapters(hdd_ctx, false);
11536 break;
11537 default:
11538 break;
11539 }
11540}
11541
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011542static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011543 enum tQDF_GLOBAL_CON_MODE curr_mode)
11544{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011545 int driver_status;
11546
11547 driver_status = hdd_ctx->driver_status;
11548
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011549 switch (curr_mode) {
11550 case QDF_GLOBAL_MISSION_MODE:
11551 case QDF_GLOBAL_MONITOR_MODE:
11552 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011553 hdd_deinit_all_adapters(hdd_ctx, false);
11554 hdd_close_all_adapters(hdd_ctx, false);
11555 break;
11556 case QDF_GLOBAL_EPPING_MODE:
11557 epping_disable();
11558 epping_close();
11559 break;
11560 default:
11561 return;
11562 }
11563}
11564
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011565static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011566 enum tQDF_GLOBAL_CON_MODE mode)
11567{
Jeff Johnson9d295242017-08-29 14:39:48 -070011568 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011569 int ret = 0;
11570 bool rtnl_held;
11571 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11572 QDF_STATUS status;
11573
11574 if (!qdf_dev) {
11575 hdd_err("qdf device context is Null return!");
11576 return -EINVAL;
11577 }
11578
11579 rtnl_held = hdd_hold_rtnl_lock();
11580 switch (mode) {
11581 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011582 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11583 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011584 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011585 break;
11586 case QDF_GLOBAL_FTM_MODE:
11587 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11588 wlan_hdd_get_intf_addr(hdd_ctx),
11589 NET_NAME_UNKNOWN, rtnl_held);
11590 if (adapter == NULL)
11591 ret = -EINVAL;
11592 break;
11593 case QDF_GLOBAL_MONITOR_MODE:
11594 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11595 wlan_hdd_get_intf_addr(hdd_ctx),
11596 NET_NAME_UNKNOWN, rtnl_held);
11597 if (adapter == NULL)
11598 ret = -EINVAL;
11599 break;
11600 case QDF_GLOBAL_EPPING_MODE:
11601 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011602 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011603 hdd_err("Failed to open in eeping mode: %d", status);
11604 ret = -EINVAL;
11605 break;
11606 }
11607 ret = epping_enable(qdf_dev->dev);
11608 if (ret) {
11609 hdd_err("Failed to enable in epping mode : %d", ret);
11610 epping_close();
11611 }
11612 break;
11613 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011614 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011615 ret = -ENOTSUPP;
11616 break;
11617 }
11618 hdd_release_rtnl_lock();
11619 rtnl_held = false;
11620 return ret;
11621}
11622
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011623/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011624 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011625 * @kmessage: con mode name on which driver to be bring up
11626 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011627 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011628 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011629 * This function is invoked when user updates con mode using sys entry,
11630 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011631 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011632 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011633 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011634static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011635 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011636{
11637 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011638 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011639 enum tQDF_GLOBAL_CON_MODE curr_mode;
11640 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011641
Dustin Brownab6029b2017-05-24 13:04:19 -070011642 hdd_info("con_mode handler: %s", kmessage);
11643
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011644 ret = wlan_hdd_validate_context(hdd_ctx);
11645 if (ret)
11646 return ret;
11647
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011648 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011649
11650 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011651
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011652 if (!(is_con_mode_valid(con_mode))) {
11653 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011654 ret = -EINVAL;
11655 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011656 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011657
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011658 curr_mode = hdd_get_conparam();
11659 if (curr_mode == con_mode) {
11660 hdd_err("curr mode: %d is same as user triggered mode %d",
11661 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011662 ret = 0;
11663 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011664 }
11665
Dustin Brown27cd9942017-09-27 16:11:44 -070011666 /* ensure adapters are stopped */
11667 hdd_stop_present_mode(hdd_ctx, curr_mode);
11668
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011669 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011670 if (ret) {
11671 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011672 goto reset_flags;
11673 }
11674
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011675 /* Cleanup present mode before switching to new mode */
11676 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11677
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011678 hdd_set_conparam(con_mode);
11679
11680 /* Register for new con_mode & then kick_start modules again */
11681 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11682 if (ret) {
11683 hdd_err("Failed to register for new mode");
11684 goto reset_flags;
11685 }
11686
11687 adapter_mode = hdd_get_adpter_mode(con_mode);
11688 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11689 hdd_err("invalid adapter");
11690 ret = -EINVAL;
11691 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011692 }
11693
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011694 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011695 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011696 hdd_err("Failed to get adapter:%d", adapter_mode);
11697 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011698 }
11699
11700 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11701 if (ret) {
11702 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011703 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011704 }
11705
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011706 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011707 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011708 if (hdd_start_adapter(adapter)) {
11709 hdd_err("Failed to start %s adapter", kmessage);
11710 ret = -EINVAL;
11711 goto reset_flags;
11712 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011713 }
11714
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011715 hdd_info("Mode successfully changed to %s", kmessage);
11716 ret = 0;
11717
11718reset_flags:
11719 cds_set_load_in_progress(false);
11720 return ret;
11721}
11722
11723
11724static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11725{
11726 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011727 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011728
11729 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11730 ret = wlan_hdd_validate_context(hdd_ctx);
11731 if (ret)
11732 return ret;
11733
11734 cds_ssr_protect(__func__);
11735 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11736 cds_ssr_unprotect(__func__);
11737
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011738 return ret;
11739}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011740
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011741static int con_mode_handler_ftm(const char *kmessage,
11742 struct kernel_param *kp)
11743{
11744 int ret;
11745
11746 ret = param_set_int(kmessage, kp);
11747
11748 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11749 pr_err("Only FTM mode supported!");
11750 return -ENOTSUPP;
11751 }
11752
11753 hdd_set_conparam(con_mode_ftm);
11754 con_mode = con_mode_ftm;
11755
11756 return ret;
11757}
11758
Ravi Joshia307f632017-07-17 23:41:41 -070011759static int con_mode_handler_monitor(const char *kmessage,
11760 struct kernel_param *kp)
11761{
11762 int ret;
11763
11764 ret = param_set_int(kmessage, kp);
11765
11766 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11767 pr_err("Only Monitor mode supported!");
11768 return -ENOTSUPP;
11769 }
11770
11771 hdd_set_conparam(con_mode_monitor);
11772 con_mode = con_mode_monitor;
11773
11774 return ret;
11775}
11776
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011777/**
11778 * hdd_get_conparam() - driver exit point
11779 *
11780 * This is the driver exit point (invoked when module is unloaded using rmmod)
11781 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011782 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011783 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011784enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011785{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011786 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011787}
11788
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011789void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011790{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011791 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011792}
11793
Komal Seelamc11bb222016-01-27 18:57:10 +053011794/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011795 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11796 * @hdd_ctx: HDD context
11797 *
11798 * Cleans up the pre cac interface, if it exists
11799 *
11800 * Return: None
11801 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011802void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011803{
11804 uint8_t session_id;
11805 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011806 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011807
11808 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11809 if (QDF_IS_STATUS_ERROR(status)) {
11810 hdd_err("failed to get pre cac vdev id");
11811 return;
11812 }
11813
11814 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11815 if (!precac_adapter) {
11816 hdd_err("invalid pre cac adapater");
11817 return;
11818 }
11819
11820 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11821 wlan_hdd_sap_pre_cac_failure,
11822 (void *)precac_adapter);
11823 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11824
11825}
11826
11827/**
Komal Seelamec702b02016-02-24 18:42:16 +053011828 * hdd_update_ol_config - API to update ol configuration parameters
11829 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011830 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011831 * Return: void
11832 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011833static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011834{
Komal Seelamec702b02016-02-24 18:42:16 +053011835 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011836 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011837
Komal Seelamec702b02016-02-24 18:42:16 +053011838 if (!ol_ctx)
11839 return;
11840
11841 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11842 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11843 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11844 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011845 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011846
11847 ol_init_ini_config(ol_ctx, &cfg);
11848}
11849
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011850#ifdef FEATURE_RUNTIME_PM
11851/**
11852 * hdd_populate_runtime_cfg() - populate runtime configuration
11853 * @hdd_ctx: hdd context
11854 * @cfg: pointer to the configuration memory being populated
11855 *
11856 * Return: void
11857 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011858static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011859 struct hif_config_info *cfg)
11860{
11861 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11862 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11863}
11864#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011865static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011866 struct hif_config_info *cfg)
11867{
11868}
11869#endif
11870
Komal Seelamec702b02016-02-24 18:42:16 +053011871/**
11872 * hdd_update_hif_config - API to update HIF configuration parameters
11873 * @hdd_ctx: HDD Context
11874 *
11875 * Return: void
11876 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011877static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011878{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011879 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011880 struct hif_config_info cfg;
11881
11882 if (!scn)
11883 return;
11884
11885 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011886 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011887 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011888
11889 if (hdd_ctx->config->prevent_link_down)
11890 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011891}
11892
11893/**
11894 * hdd_update_config() - Initialize driver per module ini parameters
11895 * @hdd_ctx: HDD Context
11896 *
11897 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011898 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011899 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011900int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011901{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011902 int ret;
11903
Komal Seelamec702b02016-02-24 18:42:16 +053011904 hdd_update_ol_config(hdd_ctx);
11905 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011906 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11907 ret = hdd_update_cds_config_ftm(hdd_ctx);
11908 else
11909 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011910 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011911
11912 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011913}
11914
Mukul Sharma9d797a02017-01-05 20:26:03 +053011915#ifdef FEATURE_WLAN_RA_FILTERING
11916/**
11917 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11918 * @psoc_cfg: pmo psoc Configuration
11919 * @hdd_ctx: Pointer to hdd context
11920 *
11921 * Return: none
11922 */
11923static inline void hdd_ra_populate_pmo_config(
11924 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011925 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011926{
11927 psoc_cfg->ra_ratelimit_interval =
11928 hdd_ctx->config->RArateLimitInterval;
11929 psoc_cfg->ra_ratelimit_enable =
11930 hdd_ctx->config->IsRArateLimitEnabled;
11931}
11932#else
11933static inline void hdd_ra_populate_pmo_config(
11934 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011935 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011936{
11937}
11938#endif
11939/**
11940 * hdd_update_pmo_config - API to update pmo configuration parameters
11941 * @hdd_ctx: HDD context
11942 *
11943 * Return: void
11944 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011945static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011946{
11947 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11948 struct pmo_psoc_cfg psoc_cfg;
11949 QDF_STATUS status;
11950
11951 /*
11952 * Value of hdd_ctx->wowEnable can be,
11953 * 0 - Disable both magic pattern match and pattern byte match.
11954 * 1 - Enable magic pattern match on all interfaces.
11955 * 2 - Enable pattern byte match on all interfaces.
11956 * 3 - Enable both magic patter and pattern byte match on
11957 * all interfaces.
11958 */
11959 psoc_cfg.magic_ptrn_enable =
11960 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11961 psoc_cfg.ptrn_match_enable_all_vdev =
11962 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080011963 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
11964 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011965 psoc_cfg.bpf_enable =
11966 hdd_ctx->config->bpf_packet_filter_enable;
11967 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011968 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011969 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11970 if (hdd_ctx->config->fhostNSOffload)
11971 psoc_cfg.ns_offload_enable_dynamic = true;
11972 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11973 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11974 psoc_cfg.active_mode_offload =
11975 hdd_ctx->config->active_mode_offload;
11976 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11977 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011978 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11979 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11980 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11981 psoc_cfg.power_save_mode =
11982 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011983 psoc_cfg.auto_power_save_fail_mode =
11984 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011985
11986 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011987 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11988 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011989 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11990 if (status != QDF_STATUS_SUCCESS) {
11991 hdd_err("failed pmo psoc configuration");
11992 return -EINVAL;
11993 }
11994
11995 return 0;
11996}
11997
Abhishek Singhb20db962017-03-03 21:28:46 +053011998#ifdef FEATURE_WLAN_SCAN_PNO
11999static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12000 struct hdd_config *cfg)
12001{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012002 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12003
Abhishek Singhb20db962017-03-03 21:28:46 +053012004 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12005 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12006 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12007 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12008 pno_cfg->channel_prediction_full_scan =
12009 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012010 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12011 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12012 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12013 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012014}
12015#else
12016static inline void
12017hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12018 struct hdd_config *cfg)
12019{
12020 return;
12021}
12022#endif
12023
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012024void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12025 struct hdd_config *cfg)
12026{
12027 uint8_t i = 0;
12028
12029 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12030 if (!ie_whitelist->white_list)
12031 return;
12032
12033 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12034 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12035 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12036 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12037 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12038 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12039 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12040 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12041
12042 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12043 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12044 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12045}
12046
Abhishek Singh257a9482017-03-06 16:52:39 +053012047/**
12048 * hdd_update_scan_config - API to update scan configuration parameters
12049 * @hdd_ctx: HDD context
12050 *
12051 * Return: 0 if success else err
12052 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012053static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012054{
12055 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12056 struct scan_user_cfg scan_cfg;
12057 struct hdd_config *cfg = hdd_ctx->config;
12058 QDF_STATUS status;
12059
12060 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12061 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12062 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12063 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12064 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12065 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12066 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012067 /* convert to ms */
12068 scan_cfg.scan_cache_aging_time =
12069 cfg->scanAgingTimeout * 1000;
12070 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12071 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12072 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12073 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012074 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012075 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012076 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Abhishek Singh257a9482017-03-06 16:52:39 +053012077
Abhishek Singhb20db962017-03-03 21:28:46 +053012078 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012079 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012080
Abhishek Singh257a9482017-03-06 16:52:39 +053012081 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12082 if (status != QDF_STATUS_SUCCESS) {
12083 hdd_err("failed pmo psoc configuration");
12084 return -EINVAL;
12085 }
12086
12087 return 0;
12088}
Abhishek Singh257a9482017-03-06 16:52:39 +053012089
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012090static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012091{
12092 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12093 struct tdls_start_params tdls_cfg;
12094 struct tdls_user_config *config = &tdls_cfg.config;
12095 struct hdd_config *cfg = hdd_ctx->config;
12096 QDF_STATUS status;
12097
12098 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12099 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12100 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12101 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12102 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12103 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12104 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12105 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12106 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12107 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12108 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12109 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12110 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12111 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12112 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12113 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12114 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12115 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12116 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12117 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12118 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12119 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12120 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12121 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12122 (cfg->fEnableTDLSImplicitTrigger ?
12123 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12124 (cfg->fTDLSExternalControl ?
12125 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12126
12127 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12128 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12129 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12130 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012131 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012132 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012133 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12134 tdls_cfg.tdls_evt_cb_data = psoc;
12135 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12136 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12137 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012138 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12139 tdls_cfg.tdls_wmm_cb_data = psoc;
12140 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12141 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012142 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012143
12144 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12145 if (status != QDF_STATUS_SUCCESS) {
12146 hdd_err("failed pmo psoc configuration");
12147 return -EINVAL;
12148 }
12149
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012150 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012151 /* enable napier specific tdls data path */
12152 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012153
Frank Liud4b2fa02017-03-29 11:46:48 +080012154 return 0;
12155}
Frank Liud4b2fa02017-03-29 11:46:48 +080012156
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012157int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012158{
12159 int ret;
12160
12161 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012162 if (ret)
12163 return ret;
12164 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012165 if (ret)
12166 return ret;
12167 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012168
12169 return ret;
12170}
12171
Agrawal Ashish65634612016-08-18 13:24:32 +053012172/**
12173 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12174 * @mode : cfg80211 DFS mode
12175 *
12176 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12177 */
12178enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12179{
12180 switch (mode) {
12181 case DFS_MODE_ENABLE:
12182 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012183 case DFS_MODE_DISABLE:
12184 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012185 case DFS_MODE_DEPRIORITIZE:
12186 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012187 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012188 hdd_debug("ACS dfs mode is NONE");
12189 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012190 }
12191}
12192
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012193/**
12194 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12195 * @hddctx: pointer to hdd context
12196 * @set_value: enable/disable
12197 *
12198 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12199 * Host(even though it is duplicate). When Host send vendor command
12200 * disable,FW doesn't perform any action. Whenever any change in
12201 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12202 *
12203 * return - 0 on success, appropriate error values on failure.
12204 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012205int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012206{
12207 QDF_STATUS status;
12208
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012209 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012210 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012211
12212 if (!hddctx->config->goptimize_chan_avoid_event) {
12213 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12214 return -EINVAL;
12215 }
12216
12217 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12218 if (!QDF_IS_STATUS_SUCCESS(status)) {
12219 hdd_err("Failed to send chan avoid command to SME");
12220 return -EINVAL;
12221 }
12222 return 0;
12223}
Agrawal Ashish65634612016-08-18 13:24:32 +053012224
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012225/**
12226 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12227 * @value: value to set
12228 *
12229 * This function will set the passed value to roaming in progress flag.
12230 *
12231 * Return: None
12232 */
12233void hdd_set_roaming_in_progress(bool value)
12234{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012235 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012236
12237 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12238 if (!hdd_ctx) {
12239 hdd_err("HDD context is NULL");
12240 return;
12241 }
12242
12243 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012244 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012245}
12246
12247/**
12248 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012249 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012250 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012251 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012252 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012253bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012254{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012255 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012256 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012257
12258 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12259 if (!hdd_ctx) {
12260 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012261 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012262 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012263 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12264 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012265 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12266 hdd_ctx->roaming_in_progress);
12267
12268 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012269}
12270
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012271/**
12272 * hdd_is_connection_in_progress() - check if connection is in
12273 * progress
12274 * @session_id: session id
12275 * @reason: scan reject reason
12276 *
12277 * Go through each adapter and check if Connection is in progress
12278 *
12279 * Return: true if connection is in progress else false
12280 */
12281bool hdd_is_connection_in_progress(uint8_t *session_id,
12282 enum scan_reject_states *reason)
12283{
12284 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012285 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012286 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012287 QDF_STATUS status = 0;
12288 uint8_t sta_id = 0;
12289 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012290 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012291
12292 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12293 if (!hdd_ctx) {
12294 hdd_err("HDD context is NULL");
12295 return false;
12296 }
12297
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012298 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12299 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012300 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012301 if (!adapter)
12302 goto end;
12303
12304 hdd_info("Adapter with device mode %s(%d) exists",
12305 hdd_device_mode_to_string(adapter->device_mode),
12306 adapter->device_mode);
12307 if (((QDF_STA_MODE == adapter->device_mode)
12308 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12309 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12310 && (eConnectionState_Connecting ==
12311 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12312 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012313 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012314 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12315 adapter->sessionId);
12316 if (session_id && reason) {
12317 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012318 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012319 }
12320 return true;
12321 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012322 /*
12323 * sme_neighbor_middle_of_roaming is for LFR2
12324 * hdd_is_roaming_in_progress is for LFR3
12325 */
12326 if (((QDF_STA_MODE == adapter->device_mode) &&
12327 sme_neighbor_middle_of_roaming(
12328 WLAN_HDD_GET_HAL_CTX(adapter),
12329 adapter->sessionId)) ||
12330 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012331 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012332 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12333 adapter->sessionId);
12334 if (session_id && reason) {
12335 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012336 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012337 }
12338 return true;
12339 }
12340 if ((QDF_STA_MODE == adapter->device_mode) ||
12341 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12342 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12343 hdd_sta_ctx =
12344 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12345 if ((eConnectionState_Associated ==
12346 hdd_sta_ctx->conn_info.connState)
12347 && (false ==
12348 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12349 sta_mac = (uint8_t *)
12350 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012351 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012352 " is in middle of WPS/EAPOL exchange.",
12353 MAC_ADDR_ARRAY(sta_mac));
12354 if (session_id && reason) {
12355 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012356 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012357 }
12358 return true;
12359 }
12360 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12361 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12362 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12363 sta_id++) {
12364 if (!((adapter->aStaInfo[sta_id].isUsed)
12365 && (OL_TXRX_PEER_STATE_CONN ==
12366 adapter->aStaInfo[sta_id].tlSTAState)))
12367 continue;
12368
12369 sta_mac = (uint8_t *)
12370 &(adapter->aStaInfo[sta_id].
12371 macAddrSTA.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012372 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012373 " of SAP/GO is in middle of WPS/EAPOL exchange",
12374 MAC_ADDR_ARRAY(sta_mac));
12375 if (session_id && reason) {
12376 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012377 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012378 }
12379 return true;
12380 }
12381 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012382 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012383 return true;
12384 }
12385 }
12386end:
12387 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12388 adapter_node = next;
12389 }
12390 return false;
12391}
12392
12393/**
12394 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012395 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012396 *
12397 * Return: None
12398 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012399void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012400{
Jeff Johnson87251032017-08-29 13:31:11 -070012401 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012402 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012403 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012404 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012405 tsap_Config_t *sap_config;
12406 void *sap_ctx;
12407
12408 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12409 sap_config = &hdd_ap_ctx->sapConfig;
12410 sap_ctx = hdd_ap_ctx->sapContext;
12411
12412 mutex_lock(&hdd_ctx->sap_lock);
12413 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12414 wlan_hdd_del_station(ap_adapter);
12415 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12416 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12417 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12418 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12419 qdf_status =
12420 qdf_wait_single_event(&hostapd_state->
12421 qdf_stop_bss_event,
12422 SME_CMD_TIMEOUT_VALUE);
12423
12424 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012425 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012426 goto end;
12427 }
12428 }
12429 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012430 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012431 ap_adapter->device_mode, ap_adapter->sessionId);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012432 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012433
12434 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012435 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012436 wlansap_reset_sap_config_add_ie(sap_config,
12437 eUPDATE_IE_ALL);
12438 goto end;
12439 }
12440
12441 qdf_event_reset(&hostapd_state->qdf_event);
12442 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12443 sap_config,
12444 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012445 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012446 wlansap_reset_sap_config_add_ie(sap_config,
12447 eUPDATE_IE_ALL);
12448 goto end;
12449 }
12450
Jeff Johnson6867ec32017-09-29 20:30:20 -070012451 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012452 qdf_status =
12453 qdf_wait_single_event(&hostapd_state->qdf_event,
12454 SME_CMD_TIMEOUT_VALUE);
12455 wlansap_reset_sap_config_add_ie(sap_config,
12456 eUPDATE_IE_ALL);
12457 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012458 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012459 goto end;
12460 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012461 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012462 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12463 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012464 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12465 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012466 ap_adapter->sessionId);
12467 hostapd_state->bCommit = true;
12468 }
12469end:
12470 mutex_unlock(&hdd_ctx->sap_lock);
12471 return;
12472}
12473
12474/**
12475 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12476 * with non dfs acs
12477 *
12478 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12479 *
12480 * Return: None
12481 */
12482void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12483{
Jeff Johnson9d295242017-08-29 14:39:48 -070012484 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012485 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012486 cds_context_type *cds_ctx;
12487
12488 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12489 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012490 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012491 return;
12492 }
12493
12494 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12495 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012496 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012497 return;
12498 }
12499
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012500 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12501 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012502 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012503 return;
12504 }
12505
12506 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012507 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12508 &ap_adapter->event_flags) &&
12509 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12510 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012511
Jeff Johnson6867ec32017-09-29 20:30:20 -070012512 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012513 ap_adapter->sessionCtx.ap.sapConfig.channel =
12514 AUTO_CHANNEL_SELECT;
12515 ap_adapter->sessionCtx.ap.sapConfig.
12516 acs_cfg.acs_mode = true;
12517
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012518 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012519 }
12520}
12521
12522/**
12523 * hdd_set_connection_in_progress() - to set the connection in
12524 * progress flag
12525 * @value: value to set
12526 *
12527 * This function will set the passed value to connection in progress flag.
12528 * If value is previously being set to true then no need to set it again.
12529 *
12530 * Return: true if value is being set correctly and false otherwise.
12531 */
12532bool hdd_set_connection_in_progress(bool value)
12533{
12534 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012535 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012536
12537 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12538 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012539 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012540 return false;
12541 }
12542
12543 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12544 /*
12545 * if the value is set to true previously and if someone is
12546 * trying to make it true again then it could be some race
12547 * condition being triggered. Avoid this situation by returning
12548 * false
12549 */
12550 if (hdd_ctx->connection_in_progress && value)
12551 status = false;
12552 else
12553 hdd_ctx->connection_in_progress = value;
12554 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12555 return status;
12556}
12557
Jeff Johnson9d295242017-08-29 14:39:48 -070012558int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012559{
12560 if (!adapter) {
12561 hdd_err("Invalid adapter");
12562 return -EINVAL;
12563 }
12564 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012565 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012566 WMA_VDEV_MCC_SET_TIME_QUOTA,
12567 set_value, VDEV_CMD);
12568 return 0;
12569
12570}
12571
Jeff Johnson9d295242017-08-29 14:39:48 -070012572int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012573{
12574 if (!adapter) {
12575 hdd_err("Invalid adapter");
12576 return -EINVAL;
12577 }
12578
12579 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012580 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012581 WMA_VDEV_MCC_SET_TIME_LATENCY,
12582 set_value, VDEV_CMD);
12583 return 0;
12584}
12585
Jeff Johnson9d295242017-08-29 14:39:48 -070012586struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012587 *psoc, uint8_t vdev_id)
12588{
Jeff Johnson9d295242017-08-29 14:39:48 -070012589 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012590 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012591
12592 /*
12593 * Currently PSOC is not being used. But this logic will
12594 * change once we have the converged implementation of
12595 * HDD context per PSOC in place. This would break if
12596 * multiple vdev objects reuse the vdev id.
12597 */
12598 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12599 if (!adapter)
12600 hdd_err("Get adapter by vdev id failed");
12601
12602 return adapter;
12603}
12604
Jeff Johnson9d295242017-08-29 14:39:48 -070012605int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012606 int8_t *rssi, int8_t *snr)
12607{
12608 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012609 struct hdd_wext_state *wext_state =
12610 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012611 tCsrRoamProfile *profile = &wext_state->roamProfile;
12612
12613 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12614 profile, bssid, rssi, snr);
12615 if (QDF_STATUS_SUCCESS != status) {
12616 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12617 return -EINVAL;
12618 }
12619
12620 return 0;
12621}
12622
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012623/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012624 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12625 * @adapter - HDD adapter
12626 * @tos - type of service
12627 * @status - status of the traffic
12628 *
12629 * Return: 0 on success and non zero value on failure
12630 */
12631
12632int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12633 bool is_tos_active)
12634{
12635 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012636 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012637 uint32_t max_off_chan_time = 0;
12638 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012639 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012640 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012641
12642 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12643 ret = wlan_hdd_validate_context(hdd_ctx);
12644
12645 if (ret < 0) {
12646 hdd_err("failed to set limit off chan params");
12647 return ret;
12648 }
12649
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012650 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12651
12652 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012653 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012654 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012655 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012656
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012657 if (adapter->active_ac) {
12658 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012659 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012660 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12661 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12662 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012663 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012664 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012665 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12666 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12667 PM_LATENCY);
12668 } else {
12669 /*ignore this command if only BE/BK is active */
12670 is_tos_active = false;
12671 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12672 hdd_ctx->config->conc_system_pref);
12673 }
12674 } else {
12675 /* No active tos */
12676 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12677 hdd_ctx->config->conc_system_pref);
12678 }
12679
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012680 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12681 is_tos_active, max_off_chan_time,
12682 hdd_ctx->config->nRestTimeConc, true);
12683 if (!QDF_IS_STATUS_SUCCESS(status)) {
12684 hdd_err("failed to set limit off chan params");
12685 ret = -EINVAL;
12686 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012687
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012688 return ret;
12689}
12690
12691/**
12692 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
12693 * @adapter - HDD adapter
12694 *
12695 * Return: 0 on success and non zero value on failure
12696 */
12697int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
12698{
12699 struct hdd_context *hdd_ctx;
12700 int ret;
12701 QDF_STATUS status;
12702 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
12703
12704 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12705 ret = wlan_hdd_validate_context(hdd_ctx);
12706 if (ret < 0)
12707 return ret;
12708
12709 /* set the system preferece to default */
12710 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12711 hdd_ctx->config->conc_system_pref);
12712
12713 /* clear the bitmap */
12714 adapter->active_ac = 0;
12715
12716 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
12717 adapter->sessionId, adapter->active_ac);
12718
12719 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12720 false, 0, 0, false);
12721 if (!QDF_IS_STATUS_SUCCESS(status)) {
12722 hdd_err("failed to reset limit off chan params");
12723 ret = -EINVAL;
12724 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012725
12726 return ret;
12727}
12728
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012729/**
12730 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12731 * @drv_op: Enum indicating driver op
12732 *
12733 * Return: none
12734 */
12735void hdd_start_driver_ops_timer(int drv_op)
12736{
12737 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12738 switch (drv_op) {
12739 case eHDD_DRV_OP_PROBE:
12740 memcpy(drv_ops_string, "probe", sizeof("probe"));
12741 break;
12742 case eHDD_DRV_OP_REMOVE:
12743 memcpy(drv_ops_string, "remove", sizeof("remove"));
12744 break;
12745 case eHDD_DRV_OP_SHUTDOWN:
12746 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12747 break;
12748 case eHDD_DRV_OP_REINIT:
12749 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12750 break;
12751 }
12752
12753 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12754 HDD_OPS_INACTIVITY_TIMEOUT);
12755}
12756
12757/**
12758 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12759 *
12760 * Return: none
12761 */
12762void hdd_stop_driver_ops_timer(void)
12763{
12764 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12765}
12766
12767/**
12768 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12769 * inactivity timer
12770 *
12771 * Return: None
12772 */
12773void hdd_drv_ops_inactivity_handler(void)
12774{
12775 hdd_err("%s: %d Sec timer expired while in .%s",
12776 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12777
12778 /* Driver shutdown is stuck, no recovery possible at this point */
12779 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12780 sizeof("shutdown")))
12781 QDF_BUG(0);
12782
12783 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012784 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012785 else
12786 QDF_BUG(0);
12787}
12788
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012789void hdd_pld_ipa_uc_shutdown_pipes(void)
12790{
12791 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12792
12793 if (!hdd_ctx)
12794 return;
12795
12796 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12797}
12798
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012799/* Register the module init/exit functions */
12800module_init(hdd_module_init);
12801module_exit(hdd_module_exit);
12802
12803MODULE_LICENSE("Dual BSD/GPL");
12804MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12805MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012807module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12808 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012809
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012810module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12811 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12812
Ravi Joshia307f632017-07-17 23:41:41 -070012813module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12814 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12815
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012816module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12817 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12818
12819module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12820
12821module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12822
12823module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);