blob: e7607e4b31abd15f8ec6ec6172097c763eb91dbc [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 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800513
514 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
515 hdd_err("%s: Driver module is closed", __func__);
516 return NOTIFY_DONE;
517 }
518
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530519 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800520 return NOTIFY_DONE;
521
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800522 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800523 dev->name, state);
524
525 switch (state) {
526 case NETDEV_REGISTER:
527 break;
528
529 case NETDEV_UNREGISTER:
530 break;
531
532 case NETDEV_UP:
533 sme_ch_avoid_update_req(hdd_ctx->hHal);
534 break;
535
536 case NETDEV_DOWN:
537 break;
538
539 case NETDEV_CHANGE:
540 if (true == adapter->isLinkUpSvcNeeded)
541 complete(&adapter->linkup_event_var);
542 break;
543
544 case NETDEV_GOING_DOWN:
545 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530546 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
547 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800548 } else {
hqueaa33ee2017-05-04 17:56:35 +0800549 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800550 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800551 }
552 break;
553
554 default:
555 break;
556 }
557
558 return NOTIFY_DONE;
559}
560
561/**
562 * hdd_netdev_notifier_call() - netdev notifier callback function
563 * @nb: pointer to notifier block
564 * @state: state
565 * @ndev: ndev pointer
566 *
567 * Return: 0 on success, error number otherwise.
568 */
569static int hdd_netdev_notifier_call(struct notifier_block *nb,
570 unsigned long state,
571 void *ndev)
572{
573 int ret;
574
575 cds_ssr_protect(__func__);
576 ret = __hdd_netdev_notifier_call(nb, state, ndev);
577 cds_ssr_unprotect(__func__);
578
579 return ret;
580}
581
582struct notifier_block hdd_netdev_notifier = {
583 .notifier_call = hdd_netdev_notifier_call,
584};
585
586/* variable to hold the insmod parameters */
587static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800588
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530589static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700590int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530591
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800592/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800593static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800594
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530595/**
596 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
597 * @ch_width: NL channel width
598 *
599 * Converts the NL channel width to the driver's internal representation
600 *
601 * Return: Converted channel width. In case of non matching NL channel width,
602 * CH_WIDTH_MAX will be returned.
603 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800604enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530605{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800606 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700607
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800608 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530609 switch (ch_width) {
610 case NL80211_CHAN_WIDTH_20_NOHT:
611 case NL80211_CHAN_WIDTH_20:
612 return CH_WIDTH_20MHZ;
613 case NL80211_CHAN_WIDTH_40:
614 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530615 case NL80211_CHAN_WIDTH_80:
616 return CH_WIDTH_80MHZ;
617 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800618 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
619 return CH_WIDTH_80P80MHZ;
620 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
621 return CH_WIDTH_160MHZ;
622 else
623 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530624 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800625 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
626 return CH_WIDTH_160MHZ;
627 else
628 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530629 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800630 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530631 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800632 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530633 default:
634 hdd_err("Invalid channel width %d, setting to default",
635 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800636 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530637 }
638}
639
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530640/* wlan_hdd_find_opclass() - Find operating class for a channel
641 * @hal: handler to HAL
642 * @channel: channel id
643 * @bw_offset: bandwidth offset
644 *
645 * Function invokes sme api to find the operating class
646 *
647 * Return: operating class
648 */
649uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
650 uint8_t bw_offset)
651{
652 uint8_t opclass = 0;
653
654 sme_get_opclass(hal, channel, bw_offset, &opclass);
655 return opclass;
656}
657
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800658/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530659 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530660 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800661 * @bitmask: Bitmask of log levels to be enabled
662 *
663 * Called immediately after the cfg.ini is read in order to configure
664 * the desired trace levels.
665 *
666 * Return: None
667 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530668int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800669{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530670 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530671 int qdf_print_idx = -1;
672 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800673 /*
674 * if the bitmask is the default value, then a bitmask was not
675 * specified in cfg.ini, so leave the logging level alone (it
676 * will remain at the "compiled in" default value)
677 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700678 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530679 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800680
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530681 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800682
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530683 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530684 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530685 QDF_TRACE_LEVEL_NONE, 0);
686
687 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530688 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800689 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530690 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 while (0 != bitmask) {
692 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530693 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530694 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530695 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530696 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800697 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700698
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800699 level++;
700 bitmask >>= 1;
701 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530702 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800703}
704
705/**
Chris Guo1751acf2017-07-03 14:09:01 +0800706 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
707 * @hdd_ctx: HDD context pointer
708 *
709 * Return: 0 if the context is valid. Error code otherwise
710 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700711int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800712{
713 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
714 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
715 return -ENODEV;
716 }
717
718 if (cds_is_driver_recovering()) {
719 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
720 (void *)_RET_IP_, cds_get_driver_state());
721 return -EAGAIN;
722 }
723
724 if (hdd_ctx->start_modules_in_progress ||
725 hdd_ctx->stop_modules_in_progress) {
726 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
727 (void *)_RET_IP_);
728 return -EAGAIN;
729 }
730
731 return 0;
732}
733
734
735/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736 * wlan_hdd_validate_context() - check the HDD context
737 * @hdd_ctx: HDD context pointer
738 *
739 * Return: 0 if the context is valid. Error code otherwise
740 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700741int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800742{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530744 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745 return -ENODEV;
746 }
747
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800748 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800749 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530750 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800751 return -EAGAIN;
752 }
753
Yue Ma9f275d92017-09-14 16:58:41 -0700754 if (cds_is_load_or_unload_in_progress()) {
755 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
756 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800757 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700758 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530759
760 if (hdd_ctx->start_modules_in_progress ||
761 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800762 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530763 (void *)_RET_IP_);
764 return -EAGAIN;
765 }
766
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530767 if (cds_is_driver_in_bad_state()) {
768 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
769 (void *)_RET_IP_, cds_get_driver_state());
770 return -ENODEV;
771 }
772
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800773 return 0;
774}
775
Jeff Johnson9d295242017-08-29 14:39:48 -0700776int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700777{
778 if (!adapter) {
779 hdd_err("adapter is null");
780 return -EINVAL;
781 }
782
783 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
784 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
785 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
786 return -EINVAL;
787 }
788
789 if (!adapter->dev) {
790 hdd_err("adapter net_device is null");
791 return -EINVAL;
792 }
793
794 if (!(adapter->dev->flags & IFF_UP)) {
795 hdd_info("adapter net_device is not up");
796 return -EAGAIN;
797 }
798
799 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
800 hdd_info("adapter session is not open");
801 return -EAGAIN;
802 }
803
804 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
805 hdd_err("bad adapter session Id: %u", adapter->sessionId);
806 return -EINVAL;
807 }
808
809 return 0;
810}
811
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530813 * wlan_hdd_validate_modules_state() - Check modules status
814 * @hdd_ctx: HDD context pointer
815 *
816 * Check's the driver module's state and returns true if the
817 * modules are enabled returns false if modules are closed.
818 *
819 * Return: True if modules are enabled or false.
820 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700821bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530822{
823 mutex_lock(&hdd_ctx->iface_change_lock);
824 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
825 mutex_unlock(&hdd_ctx->iface_change_lock);
826 hdd_notice("Modules not enabled, Present status: %d",
827 hdd_ctx->driver_status);
828 return false;
829 }
830 mutex_unlock(&hdd_ctx->iface_change_lock);
831 return true;
832}
833
834/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700836 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 *
838 * This function sets the IBSS power save config parameters to WMA
839 * which will send it to firmware if FW supports IBSS power save
840 * before vdev start.
841 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530842 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800843 * on failure.
844 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700845QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800846{
847 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700848 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800849
850 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700851 hdd_err("HDD context is null");
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_ATIM_WINDOW_SIZE,
857 hdd_ctx->config->ibssATIMWinSize,
858 VDEV_CMD);
859 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700860 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530861 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800862 }
863
Naveen Rawat247a8682017-06-05 15:00:31 -0700864 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800865 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
866 hdd_ctx->config->isIbssPowerSaveAllowed,
867 VDEV_CMD);
868 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700869 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
870 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530871 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872 }
873
Naveen Rawat247a8682017-06-05 15:00:31 -0700874 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
876 hdd_ctx->config->
877 isIbssPowerCollapseAllowed, VDEV_CMD);
878 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700879 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
880 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_AWAKE_ON_TX_RX,
886 hdd_ctx->config->isIbssAwakeOnTxRx,
887 VDEV_CMD);
888 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700889 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX 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_INACTIVITY_TIME,
895 hdd_ctx->config->ibssInactivityCount,
896 VDEV_CMD);
897 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700898 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530899 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800900 }
901
Naveen Rawat247a8682017-06-05 15:00:31 -0700902 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800903 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
904 hdd_ctx->config->ibssTxSpEndInactivityTime,
905 VDEV_CMD);
906 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700907 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
908 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530909 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800910 }
911
Naveen Rawat247a8682017-06-05 15:00:31 -0700912 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800913 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
914 hdd_ctx->config->ibssPsWarmupTime,
915 VDEV_CMD);
916 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700917 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
918 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530919 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 }
921
Naveen Rawat247a8682017-06-05 15:00:31 -0700922 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
924 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
925 VDEV_CMD);
926 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700927 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
928 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530929 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800930 }
931
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530932 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933}
934
Yue Macd359b72017-10-03 15:21:00 -0700935#ifdef FEATURE_RUNTIME_PM
936/**
937 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
938 * @hdd_ctx: HDD context
939 *
940 * Return: None
941 */
942static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
943{
944 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
945
946 qdf_runtime_lock_init(&ctx->roc);
947 qdf_runtime_lock_init(&ctx->dfs);
948
949 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
950}
951
952/**
953 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
954 * @hdd_ctx: HDD Context
955 *
956 * Return: None
957 */
958static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
959{
960 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
961
962 qdf_runtime_lock_deinit(&ctx->roc);
963 qdf_runtime_lock_deinit(&ctx->dfs);
964
965 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
966}
967
968static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
969{
970 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
971
972 qdf_runtime_lock_init(&ctx->connect);
973}
974
975static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
976{
977 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
978
979 qdf_runtime_lock_deinit(&ctx->connect);
980}
981#else /* FEATURE_RUNTIME_PM */
982static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
983static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
984static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
985static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
986#endif /* FEATURE_RUNTIME_PM */
987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988#define INTF_MACADDR_MASK 0x7
989
990/**
991 * hdd_update_macaddr() - update mac address
992 * @config: hdd configuration
993 * @hw_macaddr: mac address
994 *
995 * Mac address for multiple virtual interface is found as following
996 * i) The mac address of the first interface is just the actual hw mac address.
997 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
998 * define the mac address for the remaining interfaces and locally
999 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1000 * supported virtual interfaces, right now this is 0x07 (meaning 8
1001 * interface).
1002 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1003 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1004 *
1005 * Return: None
1006 */
1007void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301008 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009{
1010 int8_t i;
1011 uint8_t macaddr_b3, tmp_br3;
1012
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301013 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301014 QDF_MAC_ADDR_SIZE);
1015 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301016 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301017 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1019 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1020 INTF_MACADDR_MASK;
1021 macaddr_b3 += tmp_br3;
1022
1023 /* XOR-ing bit-24 of the mac address. This will give enough
1024 * mac address range before collision
1025 */
1026 macaddr_b3 ^= (1 << 7);
1027
1028 /* Set locally administered bit */
1029 config->intfMacAddr[i].bytes[0] |= 0x02;
1030 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001031 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001032 MAC_ADDRESS_STR, i,
1033 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1034 }
1035}
1036
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001037static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 struct wma_tgt_services *cfg)
1039{
1040 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001041
1042 /* Set up UAPSD */
1043 config->apUapsdEnabled &= cfg->uapsd;
1044
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001045 /* 11AX mode support */
1046 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1047 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1048 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1049
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050 /* 11AC mode support */
1051 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1052 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1053 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054
1055 /* ARP offload: override user setting if invalid */
1056 config->fhostArpOffload &= cfg->arp_offload;
1057
1058#ifdef FEATURE_WLAN_SCAN_PNO
1059 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001060 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061 if (cfg->pno_offload)
1062 config->PnoOffload = true;
1063#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064#ifdef FEATURE_WLAN_TDLS
1065 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301066 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1067 cfg->en_tdls_offchan;
1068 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1069 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001070 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001071 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001072 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001075#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1076 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1077#endif
Will Huang496b36c2017-07-11 16:38:50 +08001078 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001079 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080
1081}
1082
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001083/**
1084 * hdd_update_vdev_nss() - sets the vdev nss
1085 * @hdd_ctx: HDD context
1086 *
1087 * Sets the Nss per vdev type based on INI
1088 *
1089 * Return: None
1090 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001091static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001092{
1093 struct hdd_config *cfg_ini = hdd_ctx->config;
1094 uint8_t max_supp_nss = 1;
1095
Naveen Rawat10b1c152017-01-18 11:16:06 -08001096 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001097 max_supp_nss = 2;
1098
1099 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1100 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1101
1102 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1103 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1104}
1105
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301106/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301107 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1108 * @hdd_ctx: HDD context
1109 *
1110 * Updates wiphy vhtcap fields
1111 *
1112 * Return: None
1113 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001114static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301115{
1116 struct ieee80211_supported_band *band_5g =
1117 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1118 uint32_t val;
1119
1120 if (!band_5g) {
1121 hdd_debug("5GHz band disabled, skipping capability population");
1122 return;
1123 }
1124
1125 val = hdd_ctx->config->txBFCsnValue;
1126 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1127
1128 val = NUM_OF_SOUNDING_DIMENSIONS;
1129 band_5g->vht_cap.cap |=
1130 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1131
1132 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1133 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1134}
1135
1136/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301137 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1138 * @hdd_ctx: HDD context
1139 *
1140 * Sets the DBS capability as per INI and firmware capability
1141 *
1142 * Return: None
1143 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001144static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301145{
1146 struct hdd_config *cfg_ini = hdd_ctx->config;
1147 uint8_t hw_dbs_capable = 0;
1148
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001149 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1150 ((cfg_ini->dual_mac_feature_disable ==
1151 ENABLE_DBS_CXN_AND_SCAN) ||
1152 (cfg_ini->dual_mac_feature_disable ==
1153 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301154 hw_dbs_capable = 1;
1155
1156 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1157}
1158
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001159static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001160 struct wma_tgt_ht_cap *cfg)
1161{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301162 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163 uint32_t value, val32;
1164 uint16_t val16;
1165 struct hdd_config *pconfig = hdd_ctx->config;
1166 tSirMacHTCapabilityInfo *phtCapInfo;
1167 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1168 uint8_t enable_tx_stbc;
1169
1170 /* check and update RX STBC */
1171 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1172 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1173
1174 /* get the MPDU density */
1175 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1176
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301177 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001178 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001179 value = 0;
1180 }
1181
1182 /*
1183 * MPDU density:
1184 * override user's setting if value is larger
1185 * than the one supported by target
1186 */
1187 if (value > cfg->mpdu_density) {
1188 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1189 cfg->mpdu_density);
1190
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301191 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001192 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193 }
1194
1195 /* get the HT capability info */
1196 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301197 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001198 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199 return;
1200 }
1201 val16 = (uint16_t) val32;
1202 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1203
1204 /* Set the LDPC capability */
1205 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1206
1207 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1208 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1209
1210 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1211 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1212
1213 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1214 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1215
1216 enable_tx_stbc = pconfig->enableTxSTBC;
1217
1218 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1219 pconfig->enable2x2 = 1;
1220 } else {
1221 pconfig->enable2x2 = 0;
1222 enable_tx_stbc = 0;
1223
1224 /* 1x1 */
1225 /* Update Rx Highest Long GI data Rate */
1226 if (sme_cfg_set_int(hdd_ctx->hHal,
1227 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001228 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301229 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001230 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001231 }
1232
1233 /* Update Tx Highest Long GI data Rate */
1234 if (sme_cfg_set_int
1235 (hdd_ctx->hHal,
1236 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001237 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301238 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001239 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240 }
1241 }
1242 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1243 enable_tx_stbc = 0;
1244 phtCapInfo->txSTBC = enable_tx_stbc;
1245
1246 val32 = val16;
1247 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301248 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001249 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001250#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1251 value = SIZE_OF_SUPPORTED_MCS_SET;
1252 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301253 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001254 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001255
1256 if (pconfig->enable2x2) {
1257 for (value = 0; value < cfg->num_rf_chains; value++)
1258 mcs_set[value] =
1259 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1260
1261 status =
1262 sme_cfg_set_str(hdd_ctx->hHal,
1263 WNI_CFG_SUPPORTED_MCS_SET,
1264 mcs_set,
1265 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301266 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001267 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001268 }
1269 }
1270#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1271}
1272
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001273static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001274 struct wma_tgt_vht_cap *cfg)
1275{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301276 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001277 uint32_t value = 0;
1278 struct hdd_config *pconfig = hdd_ctx->config;
1279 struct wiphy *wiphy = hdd_ctx->wiphy;
1280 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001281 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001282 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001283 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001284 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001285
Dustin Brown5e06bd32016-10-04 12:49:10 -07001286 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001287 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001288 return;
1289 }
1290
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001291 /* Get the current MPDU length */
1292 status =
1293 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1294 &value);
1295
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301296 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001297 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001298 value = 0;
1299 }
1300
1301 /*
1302 * VHT max MPDU length:
1303 * override if user configured value is too high
1304 * that the target cannot support
1305 */
1306 if (value > cfg->vht_max_mpdu) {
1307 status = sme_cfg_set_int(hdd_ctx->hHal,
1308 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1309 cfg->vht_max_mpdu);
1310
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001311 if (status == QDF_STATUS_E_FAILURE)
1312 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313 }
1314
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001315 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1316 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1317
1318 if (pconfig->enable2x2)
1319 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1320
1321 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1322 QDF_STATUS_E_FAILURE) {
1323 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1324 }
1325
1326 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1327 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1328 if (pconfig->enable2x2)
1329 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1330
1331 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1332 QDF_STATUS_E_FAILURE) {
1333 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1334 }
1335
1336 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1337 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1338 if (pconfig->enable2x2)
1339 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1340
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001341 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001342 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1343
1344 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1345 QDF_STATUS_E_FAILURE) {
1346 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1347 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001348 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001349 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001350 &value);
1351
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301352 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001353 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 value = 0;
1355 }
1356
jiad4a7a33c2017-08-08 15:32:24 +08001357 /* Set HW RX LDPC capability */
1358 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1359 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 status = sme_cfg_set_int(hdd_ctx->hHal,
1361 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001362 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001364 if (status == QDF_STATUS_E_FAILURE)
1365 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366 }
1367
1368 /* Get current GI 80 value */
1369 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1370 &value);
1371
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301372 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001373 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 value = 0;
1375 }
1376
1377 /* set the Guard interval 80MHz */
1378 if (value && !cfg->vht_short_gi_80) {
1379 status = sme_cfg_set_int(hdd_ctx->hHal,
1380 WNI_CFG_VHT_SHORT_GI_80MHZ,
1381 cfg->vht_short_gi_80);
1382
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001383 if (status == QDF_STATUS_E_FAILURE)
1384 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385 }
1386
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387 /* Get VHT TX STBC cap */
1388 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1389
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301390 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001391 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001392 value = 0;
1393 }
1394
1395 /* VHT TX STBC cap */
1396 if (value && !cfg->vht_tx_stbc) {
1397 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1398 cfg->vht_tx_stbc);
1399
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001400 if (status == QDF_STATUS_E_FAILURE)
1401 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402 }
1403
1404 /* Get VHT RX STBC cap */
1405 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1406
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301407 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001408 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001409 value = 0;
1410 }
1411
1412 /* VHT RX STBC cap */
1413 if (value && !cfg->vht_rx_stbc) {
1414 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1415 cfg->vht_rx_stbc);
1416
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001417 if (status == QDF_STATUS_E_FAILURE)
1418 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001419 }
1420
1421 /* Get VHT SU Beamformer cap */
1422 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1423 &value);
1424
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301425 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001426 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001427 value = 0;
1428 }
1429
1430 /* set VHT SU Beamformer cap */
1431 if (value && !cfg->vht_su_bformer) {
1432 status = sme_cfg_set_int(hdd_ctx->hHal,
1433 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1434 cfg->vht_su_bformer);
1435
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001436 if (status == QDF_STATUS_E_FAILURE)
1437 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001438 }
1439
1440 /* check and update SU BEAMFORMEE capabality */
1441 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1442 pconfig->enableTxBF = cfg->vht_su_bformee;
1443
1444 status = sme_cfg_set_int(hdd_ctx->hHal,
1445 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1446 pconfig->enableTxBF);
1447
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001448 if (status == QDF_STATUS_E_FAILURE)
1449 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001450
1451 /* Get VHT MU Beamformer cap */
1452 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1453 &value);
1454
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301455 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001456 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001457 value = 0;
1458 }
1459
1460 /* set VHT MU Beamformer cap */
1461 if (value && !cfg->vht_mu_bformer) {
1462 status = sme_cfg_set_int(hdd_ctx->hHal,
1463 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1464 cfg->vht_mu_bformer);
1465
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001466 if (status == QDF_STATUS_E_FAILURE)
1467 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 }
1469
1470 /* Get VHT MU Beamformee cap */
1471 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1472 &value);
1473
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301474 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001475 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001476 value = 0;
1477 }
1478
1479 /* set VHT MU Beamformee cap */
1480 if (value && !cfg->vht_mu_bformee) {
1481 status = sme_cfg_set_int(hdd_ctx->hHal,
1482 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1483 cfg->vht_mu_bformee);
1484
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001485 if (status == QDF_STATUS_E_FAILURE)
1486 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001487 }
1488
1489 /* Get VHT MAX AMPDU Len exp */
1490 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1491 &value);
1492
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301493 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001494 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001495 value = 0;
1496 }
1497
1498 /*
1499 * VHT max AMPDU len exp:
1500 * override if user configured value is too high
1501 * that the target cannot support.
1502 * Even though Rome publish ampdu_len=7, it can
1503 * only support 4 because of some h/w bug.
1504 */
1505
1506 if (value > cfg->vht_max_ampdu_len_exp) {
1507 status = sme_cfg_set_int(hdd_ctx->hHal,
1508 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1509 cfg->vht_max_ampdu_len_exp);
1510
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001511 if (status == QDF_STATUS_E_FAILURE)
1512 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001513 }
1514
1515 /* Get VHT TXOP PS CAP */
1516 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1517
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301518 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001519 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001520 value = 0;
1521 }
1522
1523 /* set VHT TXOP PS cap */
1524 if (value && !cfg->vht_txop_ps) {
1525 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1526 cfg->vht_txop_ps);
1527
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001528 if (status == QDF_STATUS_E_FAILURE)
1529 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001530 }
1531
1532 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1533 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1534 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1535 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1536 else
1537 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1538
1539
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001540 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1541 status = sme_cfg_set_int(hdd_ctx->hHal,
1542 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1543 VHT_CAP_160_AND_80P80_SUPP);
1544 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001545 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001546 band_5g->vht_cap.cap |=
1547 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001548 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1549 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1550 status = sme_cfg_set_int(hdd_ctx->hHal,
1551 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1552 VHT_CAP_160_SUPP);
1553 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001554 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555 band_5g->vht_cap.cap |=
1556 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001557 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1558 }
1559 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1560 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301561 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001562 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301563 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001564 &value);
1565 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301566 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001567 value = 0;
1568 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301569 /* set the Guard interval 160MHz */
1570 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001571 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301572 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1573 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001574
1575 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301576 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001577 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001578
1579 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1580 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1581
1582 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1583 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1584 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1585 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1586
1587 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1588 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1589
1590 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1591 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1592 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1593 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1594 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1595 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1596
1597 band_5g->vht_cap.cap |=
1598 (cfg->vht_max_ampdu_len_exp <<
1599 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1600
1601 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1602 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1603 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1604 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1605 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1606 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1607 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1608 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1609
1610 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1611 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1612
1613}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001615/**
1616 * hdd_generate_macaddr_auto() - Auto-generate mac address
1617 * @hdd_ctx: Pointer to the HDD context
1618 *
1619 * Auto-generate mac address using device serial number.
1620 * Keep the first 3 bytes of OUI as before and replace
1621 * the last 3 bytes with the lower 3 bytes of serial number.
1622 *
1623 * Return: 0 for success
1624 * Non zero failure code for errors
1625 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001626static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001627{
1628 unsigned int serialno = 0;
1629 struct qdf_mac_addr mac_addr = {
1630 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1631 };
1632
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001633 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001634 if (serialno == 0)
1635 return -EINVAL;
1636
1637 serialno &= 0x00ffffff;
1638
1639 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1640 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1641 mac_addr.bytes[5] = serialno & 0xff;
1642
1643 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1644 return 0;
1645}
1646
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301647/**
1648 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1649 * configuration to cfg_ini in HDD
1650 * @hdd_ctx: Pointer to hdd_ctx
1651 * @cfg: target configuration
1652 *
1653 * Return: None
1654 */
1655#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001656static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301657 struct wma_tgt_cfg *cfg)
1658{
1659 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1660}
1661#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001662static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301663 struct wma_tgt_cfg *cfg)
1664{
1665}
1666#endif
1667
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001668void hdd_update_tgt_cfg(void *context, void *param)
1669{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001670 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001671 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001672 struct wma_tgt_cfg *cfg = param;
1673 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001674 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301675 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301676
Yue Mae3e86ab2017-05-08 10:48:24 -07001677 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301678 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1679 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1680 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1681 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1682 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001683 /* Restore pdev to MAC/WMA contexts */
1684 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001685 } else {
1686 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1687 if (ret) {
1688 hdd_err("pdev creation fails!");
1689 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301690 } else
1691 hdd_debug("New pdev has been created with pdev_id = %u",
1692 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301693 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001694
Naveen Rawat64e477e2016-05-20 10:34:56 -07001695 if (cds_cfg) {
1696 if (hdd_ctx->config->enable_sub_20_channel_width !=
1697 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1698 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1699 cds_cfg->sub_20_channel_width =
1700 WLAN_SUB_20_CH_WIDTH_NONE;
1701 } else {
1702 cds_cfg->sub_20_channel_width =
1703 hdd_ctx->config->enable_sub_20_channel_width;
1704 }
1705 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001706
1707 /* first store the INI band capability */
1708 temp_band_cap = hdd_ctx->config->nBandCapability;
1709
1710 hdd_ctx->config->nBandCapability = cfg->band_cap;
1711
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001712 /*
1713 * now overwrite the target band capability with INI
1714 * setting if INI setting is a subset
1715 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001716
1717 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1718 (temp_band_cap != eCSR_BAND_ALL))
1719 hdd_ctx->config->nBandCapability = temp_band_cap;
1720 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1721 (temp_band_cap != eCSR_BAND_ALL) &&
1722 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001723 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001724 }
1725
Amar Singhal58b45ef2017-08-01 13:43:54 -07001726 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1727
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301728 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001729 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1730 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1731 }
1732
1733 /* This can be extended to other configurations like ht, vht cap... */
1734
Anurag Chouhanc5548422016-02-24 18:33:27 +05301735 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001736 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001737 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001739 static struct qdf_mac_addr default_mac_addr = {
1740 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1741 };
1742 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1743 &default_mac_addr)) {
1744 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1745 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1746 MAC_ADDRESS_STR,
1747 MAC_ADDR_ARRAY(hdd_ctx->config->
1748 intfMacAddr[0].bytes));
1749 } else {
1750 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1751 MAC_ADDRESS_STR,
1752 MAC_ADDR_ARRAY(hdd_ctx->config->
1753 intfMacAddr[0].bytes));
1754 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001755 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001756 }
1757
1758 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001759 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001760
1761 hdd_ctx->max_intf_count = cfg->max_intf_count;
1762
Jeff Johnsonc875e242016-09-23 18:12:34 -07001763 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001764 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001765
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001766 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1767 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1768
1769 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1770
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001772 if (cfg->services.en_11ax) {
1773 hdd_info("11AX: 11ax is enabled - update HDD config");
1774 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1775 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001776
1777 hdd_update_vdev_nss(hdd_ctx);
1778
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301779 hdd_update_hw_dbs_capable(hdd_ctx);
1780
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001781 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001782 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001783 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001784 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001785
Nitesh Shahe50711f2017-04-26 16:30:45 +05301786 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1787 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1788 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001789 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001790 hdd_ctx->current_antenna_mode);
1791
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001792 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1793 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301794 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301795
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301796 if ((hdd_ctx->config->txBFCsnValue >
1797 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1798 !cfg->tx_bfee_8ss_enabled)
1799 hdd_ctx->config->txBFCsnValue =
1800 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1801
1802 if (sme_cfg_set_int(hdd_ctx->hHal,
1803 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1804 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1805 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1806
1807
1808 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1809 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1810 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301811
1812 /*
1813 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1814 */
1815 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301816
1817 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1818
Arun Khandavallid454d422016-08-17 12:47:05 +05301819 /*
1820 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1821 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1822 * configure the STA mode wow pattern.
1823 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301824 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301825 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301826
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301827 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1828
Yue Macd359b72017-10-03 15:21:00 -07001829 /*
1830 * This needs to be done after HDD pdev is created and stored since
1831 * it will access the HDD pdev object lock.
1832 */
1833 hdd_runtime_suspend_context_init(hdd_ctx);
1834
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001835 /* Configure NAN datapath features */
1836 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001837 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001838}
1839
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001840bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001841{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001842 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001843 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301844 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001845 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001846
Arif Hussaincd151632017-02-11 16:57:19 -08001847 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001848 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001849 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301850 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001851 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001852
Arif Hussaincd151632017-02-11 16:57:19 -08001853 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1854 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001855 adapter = adapterNode->adapter;
Arif Hussaincd151632017-02-11 16:57:19 -08001856 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1857
1858 if ((QDF_SAP_MODE == adapter->device_mode ||
1859 QDF_P2P_GO_MODE == adapter->device_mode) &&
1860 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1861 ap_ctx->operatingChannel))) {
1862 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1863 true;
1864 hdd_info("tx blocked for session: %d",
1865 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301866 }
Arif Hussaincd151632017-02-11 16:57:19 -08001867 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1868 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001869 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301870
1871 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001872}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001873
1874/**
1875 * hdd_is_valid_mac_address() - validate MAC address
1876 * @pMacAddr: Pointer to the input MAC address
1877 *
1878 * This function validates whether the given MAC address is valid or not
1879 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1880 * where X is the hexa decimal digit character and separated by ':'
1881 * This algorithm works even if MAC address is not separated by ':'
1882 *
1883 * This code checks given input string mac contains exactly 12 hexadecimal
1884 * digits and a separator colon : appears in the input string only after
1885 * an even number of hex digits.
1886 *
1887 * Return: 1 for valid and 0 for invalid
1888 */
1889bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1890{
1891 int xdigit = 0;
1892 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001893
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001894 while (*pMacAddr) {
1895 if (isxdigit(*pMacAddr)) {
1896 xdigit++;
1897 } else if (':' == *pMacAddr) {
1898 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1899 break;
1900
1901 ++separator;
1902 } else {
1903 /* Invalid MAC found */
1904 return 0;
1905 }
1906 ++pMacAddr;
1907 }
1908 return xdigit == 12 && (separator == 5 || separator == 0);
1909}
1910
1911/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301912 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1913 * @dev: Handle to struct net_device to be updated.
1914 *
1915 * Return: None
1916 */
1917static void hdd_mon_mode_ether_setup(struct net_device *dev)
1918{
1919 dev->header_ops = NULL;
1920 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1921 dev->hard_header_len = ETH_HLEN;
1922 dev->mtu = ETH_DATA_LEN;
1923 dev->addr_len = ETH_ALEN;
1924 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1925 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1926 dev->priv_flags |= IFF_TX_SKB_SHARING;
1927
1928 memset(dev->broadcast, 0xFF, ETH_ALEN);
1929}
1930
1931/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001932 * __hdd__mon_open() - HDD Open function
1933 * @dev: Pointer to net_device structure
1934 *
1935 * This is called in response to ifconfig up
1936 *
1937 * Return: 0 for success; non-zero for failure
1938 */
1939static int __hdd_mon_open(struct net_device *dev)
1940{
1941 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001942 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1943 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001944
1945 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001946
1947 ret = wlan_hdd_validate_context(hdd_ctx);
1948 if (ret)
1949 return ret;
1950
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301951 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001952
1953 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1954 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1955 if (ret) {
1956 hdd_err("Failed to start WLAN modules return");
1957 return ret;
1958 }
1959 hdd_err("hdd_wlan_start_modules() successful !");
1960
1961 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1962 ret = hdd_start_adapter(adapter);
1963 if (ret) {
1964 hdd_err("Failed to start adapter :%d",
1965 adapter->device_mode);
1966 return ret;
1967 }
1968 hdd_err("hdd_start_adapters() successful !");
1969 }
1970 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1971 }
1972
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001973 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001974
1975 if (!ret)
1976 ret = hdd_enable_monitor_mode(dev);
1977
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001978 return ret;
1979}
1980
1981/**
1982 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1983 * @dev: Pointer to net_device structure
1984 *
1985 * This is called in response to ifconfig up
1986 *
1987 * Return: 0 for success; non-zero for failure
1988 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001989static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001990{
1991 int ret;
1992
1993 cds_ssr_protect(__func__);
1994 ret = __hdd_mon_open(dev);
1995 cds_ssr_unprotect(__func__);
1996
1997 return ret;
1998}
1999
2000/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302001 * hdd_start_adapter() - Wrapper function for device specific adapter
2002 * @adapter: pointer to HDD adapter
2003 *
2004 * This function is called to start the device specific adapter for
2005 * the mode passed in the adapter's device_mode.
2006 *
2007 * Return: 0 for success; non-zero for failure
2008 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002009int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302010{
2011
2012 int ret;
2013 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
2014
2015 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002016 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302017
2018 switch (device_mode) {
2019 case QDF_P2P_CLIENT_MODE:
2020 case QDF_P2P_DEVICE_MODE:
2021 case QDF_OCB_MODE:
2022 case QDF_STA_MODE:
2023 case QDF_MONITOR_MODE:
2024 ret = hdd_start_station_adapter(adapter);
2025 if (ret)
2026 goto err_start_adapter;
2027 break;
2028 case QDF_P2P_GO_MODE:
2029 case QDF_SAP_MODE:
2030 ret = hdd_start_ap_adapter(adapter);
2031 if (ret)
2032 goto err_start_adapter;
2033 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302034 case QDF_IBSS_MODE:
2035 /*
2036 * For IBSS interface is initialized as part of
2037 * hdd_init_station_mode()
2038 */
2039 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302040 case QDF_FTM_MODE:
2041 ret = hdd_start_ftm_adapter(adapter);
2042 if (ret)
2043 goto err_start_adapter;
2044 break;
2045 default:
2046 hdd_err("Invalid session type %d", device_mode);
2047 QDF_ASSERT(0);
2048 goto err_start_adapter;
2049 }
2050 if (hdd_set_fw_params(adapter))
2051 hdd_err("Failed to set the FW params for the adapter!");
2052
2053 /*
2054 * Action frame registered in one adapter which will
2055 * applicable to all interfaces
2056 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302057 ret = wlan_hdd_cfg80211_register_frames(adapter);
2058 if (ret < 0) {
2059 hdd_err("Failed to register frames - ret %d", ret);
2060 goto err_start_adapter;
2061 }
2062
Arun Khandavallifae92942016-08-01 13:31:08 +05302063 EXIT();
2064 return 0;
2065err_start_adapter:
2066 return -EINVAL;
2067}
2068
2069/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302070 * hdd_enable_power_management() - API to Enable Power Management
2071 *
2072 * API invokes Bus Interface Layer power management functionality
2073 *
2074 * Return: None
2075 */
2076static void hdd_enable_power_management(void)
2077{
2078 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2079
2080 if (!hif_ctx) {
2081 hdd_err("Bus Interface Context is Invalid");
2082 return;
2083 }
2084
2085 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2086}
2087
2088/**
2089 * hdd_disable_power_management() - API to disable Power Management
2090 *
2091 * API disable Bus Interface Layer Power management functionality
2092 *
2093 * Return: None
2094 */
2095static void hdd_disable_power_management(void)
2096{
2097 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2098
2099 if (!hif_ctx) {
2100 hdd_err("Bus Interface Context is Invalid");
2101 return;
2102 }
2103
2104 hif_disable_power_management(hif_ctx);
2105}
2106
2107/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302108 * hdd_update_hw_sw_info() - API to update the HW/SW information
2109 *
2110 * API to update the HW and SW information in the driver
2111 *
2112 * Return: None
2113 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002114static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302115{
2116 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002117 size_t target_hw_name_len;
2118 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302119
2120 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2121 if (!hif_sc) {
2122 hdd_err("HIF context is NULL");
2123 return;
2124 }
2125
2126 /*
2127 * target hw version/revision would only be retrieved after firmware
2128 * download
2129 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002130 hif_get_hw_info(hif_sc,
2131 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302132 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002133 &target_hw_name);
2134
2135 if (hdd_ctx->target_hw_name)
2136 qdf_mem_free(hdd_ctx->target_hw_name);
2137
2138 target_hw_name_len = strlen(target_hw_name) + 1;
2139 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2140 if (hdd_ctx->target_hw_name)
2141 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2142 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302143
2144 /* Get the wlan hw/fw version */
2145 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302146}
2147
2148/**
gbian62edd7e2017-03-07 13:12:13 +08002149 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2150 * @hdd_ctx: Pointer to hdd context
2151 *
2152 * Return: none
2153 */
2154static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002155hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002156{
2157 uint8_t num_entries = 0;
2158 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2159 uint8_t *tx_sched_wrr_ac;
2160 int i;
2161 cds_context_type *cds_ctx;
2162
2163 if (NULL == hdd_ctx)
2164 return;
2165
2166 if (NULL == hdd_ctx->config) {
2167 /* Do nothing if hdd_ctx is invalid */
2168 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2169 return;
2170 }
2171
2172 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2173
2174 if (!cds_ctx) {
2175 hdd_err("Invalid CDS Context");
2176 return;
2177 }
2178
2179 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2180 switch (i) {
2181 case OL_TX_WMM_AC_BE:
2182 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2183 break;
2184 case OL_TX_WMM_AC_BK:
2185 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2186 break;
2187 case OL_TX_WMM_AC_VI:
2188 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2189 break;
2190 case OL_TX_WMM_AC_VO:
2191 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2192 break;
2193 default:
2194 tx_sched_wrr_ac = NULL;
2195 break;
2196 }
2197
2198 hdd_string_to_u8_array(tx_sched_wrr_ac,
2199 tx_sched_wrr_param,
2200 &num_entries,
2201 sizeof(tx_sched_wrr_param));
2202
2203 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2204 cds_ctx->ac_specs[i].wrr_skip_weight =
2205 tx_sched_wrr_param[0];
2206 cds_ctx->ac_specs[i].credit_threshold =
2207 tx_sched_wrr_param[1];
2208 cds_ctx->ac_specs[i].send_limit =
2209 tx_sched_wrr_param[2];
2210 cds_ctx->ac_specs[i].credit_reserve =
2211 tx_sched_wrr_param[3];
2212 cds_ctx->ac_specs[i].discard_weight =
2213 tx_sched_wrr_param[4];
2214 }
2215
2216 num_entries = 0;
2217 }
2218}
2219
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002220#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002221static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2222 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2223{
Jeff Johnson9d295242017-08-29 14:39:48 -07002224 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002225 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002226
2227 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2228 if (!adapter) {
2229 hdd_err("Adapter is NULL");
2230 return PM_MAX_NUM_OF_MODE;
2231 }
2232
2233 return policy_mgr_convert_device_mode_to_qdf_type(
2234 adapter->device_mode);
2235}
2236
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002237static void hdd_register_policy_manager_callback(
2238 struct wlan_objmgr_psoc *psoc)
2239{
2240 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002241
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002242 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002243 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002244 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2245 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002246 hdd_cbacks.get_mode_for_non_connected_vdev =
2247 wlan_hdd_get_mode_for_non_connected_vdev;
2248
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002249 if (QDF_STATUS_SUCCESS !=
2250 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2251 hdd_err("HDD callback registration with policy manager failed");
2252 }
2253}
2254#else
2255static void hdd_register_policy_manager_callback(
2256 struct wlan_objmgr_psoc *psoc)
2257{
2258}
2259#endif
2260
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002261#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002262static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002263{
2264 struct nan_callbacks cb_obj = {0};
2265
2266 cb_obj.ndi_open = hdd_ndi_open;
2267 cb_obj.ndi_close = hdd_ndi_close;
2268 cb_obj.ndi_start = hdd_ndi_start;
2269 cb_obj.ndi_delete = hdd_ndi_delete;
2270 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2271 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2272
Naveen Rawat37f62c82017-03-26 22:24:43 -07002273 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2274 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002275 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002276
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002277 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2278}
2279#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002280static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002281{
2282}
2283#endif
2284
gbian62edd7e2017-03-07 13:12:13 +08002285/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302286 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2287 * @hdd_ctx: HDD context
2288 * @adapter: HDD adapter
2289 * @reinit: flag to indicate from SSR or normal path
2290 *
2291 * This function maintains the driver state machine it will be invoked from
2292 * startup, reinit and change interface. Depending on the driver state shall
2293 * perform the opening of the modules.
2294 *
2295 * Return: 0 for success; non-zero for failure
2296 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002297int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2298 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302299 bool reinit)
2300{
2301 int ret;
2302 qdf_device_t qdf_dev;
2303 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302304 bool unint = false;
2305 void *hif_ctx;
2306
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002307 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302308
2309 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2310 if (!qdf_dev) {
2311 hdd_err("QDF Device Context is Invalid return");
2312 return -EINVAL;
2313 }
2314
2315 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302316 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302317
2318 if (QDF_TIMER_STATE_RUNNING ==
2319 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2320
2321 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002322 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302323 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2324 }
2325
2326 switch (hdd_ctx->driver_status) {
2327 case DRIVER_MODULES_UNINITIALIZED:
2328 unint = true;
2329 /* Fall through dont add break here */
2330 case DRIVER_MODULES_CLOSED:
2331 if (!reinit && !unint) {
2332 ret = pld_power_on(qdf_dev->dev);
2333 if (ret) {
2334 hdd_err("Failed to Powerup the device: %d", ret);
2335 goto release_lock;
2336 }
2337 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002338
2339 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2340 hdd_ctx->config->enable_fw_log);
2341
Arun Khandavallifae92942016-08-01 13:31:08 +05302342 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2343 qdf_dev->bus_type,
2344 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2345 HIF_ENABLE_TYPE_PROBE);
2346 if (ret) {
2347 hdd_err("Failed to open hif: %d", ret);
2348 goto power_down;
2349 }
2350
2351 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302352 if (!hif_ctx) {
2353 hdd_err("hif context is null!!");
2354 goto power_down;
2355 }
2356
Arun Khandavallifae92942016-08-01 13:31:08 +05302357 status = ol_cds_init(qdf_dev, hif_ctx);
2358 if (status != QDF_STATUS_SUCCESS) {
2359 hdd_err("No Memory to Create BMI Context :%d", status);
2360 goto hif_close;
2361 }
2362
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002363 ret = hdd_update_config(hdd_ctx);
2364 if (ret) {
2365 hdd_err("Failed to update configuration :%d", ret);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002366 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002367 }
2368
gbian62edd7e2017-03-07 13:12:13 +08002369 hdd_update_cds_ac_specs_params(hdd_ctx);
2370
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302371 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302372 if (!QDF_IS_STATUS_SUCCESS(status)) {
2373 hdd_err("Failed to Open CDS: %d", status);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002374 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302375 }
2376
Mukul Sharma9d797a02017-01-05 20:26:03 +05302377 /* initalize components configurations after psoc open */
2378 ret = hdd_update_components_config(hdd_ctx);
2379 if (ret) {
2380 hdd_err("Failed to update components configs :%d",
2381 ret);
2382 goto close;
2383 }
2384
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002385 /*
2386 * NAN compoenet requires certian operations like, open adapter,
2387 * close adapter, etc. to be initiated by HDD, for those
2388 * register HDD callbacks with UMAC's NAN componenet.
2389 */
2390 hdd_nan_register_callbacks(hdd_ctx);
2391
Arun Khandavallifae92942016-08-01 13:31:08 +05302392 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2393
Jeff Johnson3a280122017-09-13 07:42:00 -07002394 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302395 if (!QDF_IS_STATUS_SUCCESS(status)) {
2396 hdd_err("Failed to pre-enable CDS: %d", status);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002397 goto close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302398 }
2399
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002400 hdd_register_policy_manager_callback(
2401 hdd_ctx->hdd_psoc);
2402
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302403 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302404 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302405
Arun Khandavallifae92942016-08-01 13:31:08 +05302406 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2407 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2408 hdd_ftm_mc_process_msg);
2409 break;
2410 }
2411 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002412 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302413 break;
2414 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302415
2416 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002417 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2418 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002419 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002420 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302421 }
2422
Arun Khandavallifae92942016-08-01 13:31:08 +05302423 /* Fall through dont add break here */
2424 case DRIVER_MODULES_OPENED:
2425 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002426 hdd_alert("adapter is Null");
2427 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302428 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302429 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2430 hdd_err("in ftm mode, no need to configure cds modules");
2431 break;
2432 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302433 if (hdd_configure_cds(hdd_ctx, adapter)) {
2434 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002435 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302436 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302437 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302438 hdd_info("Driver Modules Successfully Enabled");
2439 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2440 break;
2441 case DRIVER_MODULES_ENABLED:
2442 hdd_info("Driver modules already Enabled");
2443 break;
2444 default:
2445 hdd_err("WLAN start invoked in wrong state! :%d\n",
2446 hdd_ctx->driver_status);
2447 goto release_lock;
2448 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302449 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302450 mutex_unlock(&hdd_ctx->iface_change_lock);
2451 EXIT();
2452 return 0;
2453
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002454post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002455 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002456
Arun Khandavallifae92942016-08-01 13:31:08 +05302457close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002458 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002459 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302460
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002461ol_cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302462 ol_cds_free();
2463
2464hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002465 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2466 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302467power_down:
2468 if (!reinit && !unint)
2469 pld_power_off(qdf_dev->dev);
2470release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302471 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302472 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302473 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002474
Arun Khandavallifae92942016-08-01 13:31:08 +05302475 return -EINVAL;
2476}
2477
Naveen Rawat910726a2017-03-06 11:42:51 -08002478#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002479static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002480{
2481 int ret = os_if_wifi_pos_register_nl();
2482
2483 if (ret)
2484 hdd_err("os_if_wifi_pos_register_nl failed");
2485
2486 return ret;
2487}
2488
2489static int hdd_deactivate_wifi_pos(void)
2490{
2491 int ret = os_if_wifi_pos_deregister_nl();
2492
2493 if (ret)
2494 hdd_err("os_if_wifi_pos_deregister_nl failed");
2495
2496 return ret;
2497}
2498
2499/**
2500 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2501 * @hdd_ctx: hdd context
2502 *
2503 * Return: status of operation
2504 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002505static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002506{
2507 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2508 struct hdd_config *cfg = hdd_ctx->config;
2509
2510 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2511 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2512 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2513 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2514 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2515 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2516 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2517 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2518}
2519#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002520static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002521{
2522 return oem_activate_service(hdd_ctx);
2523}
2524
2525static int hdd_deactivate_wifi_pos(void)
2526{
2527 return 0;
2528}
2529
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002530static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002531{
2532}
2533#endif
2534
Arun Khandavallifae92942016-08-01 13:31:08 +05302535/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002536 * __hdd_open() - HDD Open function
2537 * @dev: Pointer to net_device structure
2538 *
2539 * This is called in response to ifconfig up
2540 *
2541 * Return: 0 for success; non-zero for failure
2542 */
2543static int __hdd_open(struct net_device *dev)
2544{
Jeff Johnson9d295242017-08-29 14:39:48 -07002545 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002546 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002547 int ret;
2548
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002549 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302550 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302551 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002552
Arunk Khandavallie1b3a382017-09-26 12:01:26 +05302553 if (!hdd_wait_for_recovery_completion()) {
2554 hdd_err("Recovery failed");
2555 return -EIO;
2556 }
2557
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302558 /* Nothing to be done if device is unloading */
2559 if (cds_is_driver_unloading()) {
2560 hdd_err("Driver is unloading can not open the hdd");
2561 return -EBUSY;
2562 }
2563
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302564 mutex_lock(&hdd_init_deinit_lock);
2565
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302566 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2567
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302568 /*
2569 * This scenario can be hit in cases where in the wlan driver after
2570 * registering the netdevices and there is a failure in driver
2571 * initialization. So return error gracefully because the netdevices
2572 * will be de-registered as part of the load failure.
2573 */
2574
2575 if (!cds_is_driver_loaded()) {
2576 hdd_err("Failed to start the wlan driver!!");
2577 ret = -EIO;
2578 goto err_hdd_hdd_init_deinit_lock;
2579 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302580
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002581
Arun Khandavallifae92942016-08-01 13:31:08 +05302582 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2583 if (ret) {
2584 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302585 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302586 }
2587
2588
2589 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2590 ret = hdd_start_adapter(adapter);
2591 if (ret) {
2592 hdd_err("Failed to start adapter :%d",
2593 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302594 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302595 }
2596 }
2597
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002598 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2599 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002600 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002601 /* Enable TX queues only when we are connected */
2602 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302603 WLAN_START_ALL_NETIF_QUEUE,
2604 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002605 }
2606
Naveen Rawat286def52016-09-23 15:38:02 -07002607 /* Enable carrier and transmit queues for NDI */
2608 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002609 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002610 wlan_hdd_netif_queue_control(adapter,
2611 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2612 WLAN_CONTROL_PATH);
2613 }
2614
Naveen Rawat910726a2017-03-06 11:42:51 -08002615 hdd_populate_wifi_pos_cfg(hdd_ctx);
2616
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302617err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302618 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302619 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002620 return ret;
2621}
2622
Arun Khandavallifae92942016-08-01 13:31:08 +05302623
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002624/**
2625 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2626 * @dev: Pointer to net_device structure
2627 *
2628 * This is called in response to ifconfig up
2629 *
2630 * Return: 0 for success; non-zero for failure
2631 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002632static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002633{
2634 int ret;
2635
2636 cds_ssr_protect(__func__);
2637 ret = __hdd_open(dev);
2638 cds_ssr_unprotect(__func__);
2639
2640 return ret;
2641}
2642
2643/**
2644 * __hdd_stop() - HDD stop function
2645 * @dev: Pointer to net_device structure
2646 *
2647 * This is called in response to ifconfig down
2648 *
2649 * Return: 0 for success; non-zero for failure
2650 */
2651static int __hdd_stop(struct net_device *dev)
2652{
Jeff Johnson9d295242017-08-29 14:39:48 -07002653 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002654 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002655 int ret;
2656
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002657 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002658
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302659 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002660 adapter->sessionId, adapter->device_mode));
2661
2662 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302663 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002664 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002665
2666 /* Nothing to be done if the interface is not opened */
2667 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002668 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002669 return -ENODEV;
2670 }
2671
2672 /* Make sure the interface is marked as closed */
2673 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302674
2675 hdd_debug("Disabling Auto Power save timer");
2676 sme_ps_disable_auto_ps_timer(
2677 WLAN_HDD_GET_HAL_CTX(adapter),
2678 adapter->sessionId);
2679
2680 /*
2681 * Disable TX on the interface, after this hard_start_xmit() will not
2682 * be called on that interface
2683 */
2684 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302685 wlan_hdd_netif_queue_control(adapter,
2686 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2687 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002688
2689 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002690 * NAN data interface is different in some sense. The traffic on NDI is
2691 * bursty in nature and depends on the need to transfer. The service
2692 * layer may down the interface after the usage and up again when
2693 * required. In some sense, the NDI is expected to be available
2694 * (like SAP) iface until NDI delete request is issued by the service
2695 * layer. Skip BSS termination and adapter deletion for NAN Data
2696 * interface (NDI).
2697 */
2698 if (WLAN_HDD_IS_NDI(adapter))
2699 return 0;
2700
2701 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002702 * The interface is marked as down for outside world (aka kernel)
2703 * But the driver is pretty much alive inside. The driver needs to
2704 * tear down the existing connection on the netdev (session)
2705 * cleanup the data pipes and wait until the control plane is stabilized
2706 * for this interface. The call also needs to wait until the above
2707 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002708 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002709 * That is intentional to be able to scan if it is a STA/P2P interface
2710 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302711 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002712
2713 /* DeInit the adapter. This ensures datapath cleanup as well */
2714 hdd_deinit_adapter(hdd_ctx, adapter, true);
2715
Arun Khandavallifae92942016-08-01 13:31:08 +05302716
2717 /*
2718 * Find if any iface is up. If any iface is up then can't put device to
2719 * sleep/power save mode
2720 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302721 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002722 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302723 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302724 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302725 hdd_prevent_suspend_timeout(
2726 hdd_ctx->config->iface_change_wait_time,
2727 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302728 }
2729
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002730 EXIT();
2731 return 0;
2732}
2733
2734/**
2735 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2736 * @dev: pointer to net_device structure
2737 *
2738 * This is called in response to ifconfig down
2739 *
2740 * Return: 0 for success and error number for failure
2741 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002742static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743{
2744 int ret;
2745
2746 cds_ssr_protect(__func__);
2747 ret = __hdd_stop(dev);
2748 cds_ssr_unprotect(__func__);
2749
2750 return ret;
2751}
2752
2753/**
2754 * __hdd_uninit() - HDD uninit function
2755 * @dev: Pointer to net_device structure
2756 *
2757 * This is called during the netdev unregister to uninitialize all data
2758 * associated with the device
2759 *
2760 * Return: None
2761 */
2762static void __hdd_uninit(struct net_device *dev)
2763{
Jeff Johnson9d295242017-08-29 14:39:48 -07002764 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002765 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002766
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002767 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002768
2769 do {
2770 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002771 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002772 break;
2773 }
2774
Jeff Johnson399c6272017-08-30 10:51:00 -07002775 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2776 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002777 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002778 break;
2779 }
2780
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002781 if (dev != adapter->dev)
2782 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002783
Jeff Johnson399c6272017-08-30 10:51:00 -07002784 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002785
2786 /* after uninit our adapter structure will no longer be valid */
2787 adapter->dev = NULL;
2788 adapter->magic = 0;
2789 } while (0);
2790
2791 EXIT();
2792}
2793
2794/**
2795 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2796 * @dev: pointer to net_device structure
2797 *
2798 * This is called during the netdev unregister to uninitialize all data
2799 * associated with the device
2800 *
2801 * Return: none
2802 */
2803static void hdd_uninit(struct net_device *dev)
2804{
2805 cds_ssr_protect(__func__);
2806 __hdd_uninit(dev);
2807 cds_ssr_unprotect(__func__);
2808}
2809
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002810static int hdd_open_cesium_nl_sock(void)
2811{
2812#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2813 struct netlink_kernel_cfg cfg = {
2814 .groups = WLAN_NLINK_MCAST_GRP_ID,
2815 .input = NULL
2816 };
2817#endif
2818 int ret = 0;
2819
2820#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2821 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2822#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2823 THIS_MODULE,
2824#endif
2825 &cfg);
2826#else
2827 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2828 WLAN_NLINK_MCAST_GRP_ID,
2829 NULL, NULL, THIS_MODULE);
2830#endif
2831
2832 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002833 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002834 ret = -ECONNREFUSED;
2835 }
2836
2837 return ret;
2838}
2839
2840static void hdd_close_cesium_nl_sock(void)
2841{
2842 if (NULL != cesium_nl_srv_sock) {
2843 netlink_kernel_release(cesium_nl_srv_sock);
2844 cesium_nl_srv_sock = NULL;
2845 }
2846}
2847
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002848/**
2849 * __hdd_set_mac_address() - set the user specified mac address
2850 * @dev: Pointer to the net device.
2851 * @addr: Pointer to the sockaddr.
2852 *
2853 * This function sets the user specified mac address using
2854 * the command ifconfig wlanX hw ether <mac adress>.
2855 *
2856 * Return: 0 for success, non zero for failure
2857 */
2858static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2859{
Jeff Johnson9d295242017-08-29 14:39:48 -07002860 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002861 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002862 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302863 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002864 int ret;
2865
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002866 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002867
2868 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2869 ret = wlan_hdd_validate_context(hdd_ctx);
2870 if (0 != ret)
2871 return ret;
2872
2873 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2874 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2875
2876 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302877 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878}
2879
2880/**
2881 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2882 * function from SSR
2883 * @dev: pointer to net_device structure
2884 * @addr: Pointer to the sockaddr
2885 *
2886 * This function sets the user specified mac address using
2887 * the command ifconfig wlanX hw ether <mac adress>.
2888 *
2889 * Return: 0 for success.
2890 */
2891static int hdd_set_mac_address(struct net_device *dev, void *addr)
2892{
2893 int ret;
2894
2895 cds_ssr_protect(__func__);
2896 ret = __hdd_set_mac_address(dev, addr);
2897 cds_ssr_unprotect(__func__);
2898
2899 return ret;
2900}
2901
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002902uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903{
2904 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002905
Anurag Chouhan6d760662016-02-20 16:05:43 +05302906 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002907 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2908 break;
2909 }
2910
Anurag Chouhan6d760662016-02-20 16:05:43 +05302911 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002912 return NULL;
2913
2914 hdd_ctx->config->intfAddrMask |= (1 << i);
2915 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2916}
2917
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07002918void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
2919 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002920{
2921 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002922
Anurag Chouhan6d760662016-02-20 16:05:43 +05302923 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002924 if (!memcmp(releaseAddr,
2925 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2926 6)) {
2927 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2928 break;
2929 }
2930 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002931}
2932
2933#ifdef WLAN_FEATURE_PACKET_FILTERING
2934/**
2935 * __hdd_set_multicast_list() - set the multicast address list
2936 * @dev: Pointer to the WLAN device.
2937 * @skb: Pointer to OS packet (sk_buff).
2938 *
2939 * This funciton sets the multicast address list.
2940 *
2941 * Return: None
2942 */
2943static void __hdd_set_multicast_list(struct net_device *dev)
2944{
Jeff Johnson9d295242017-08-29 14:39:48 -07002945 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002946 int i = 0, status;
2947 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002948 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302949 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2950 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2951 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002952
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002953 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302954 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302955 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002957 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302958 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302959 goto out;
2960
Dustin Brownc788acb2017-08-01 17:43:51 -07002961 status = hdd_validate_adapter(adapter);
2962 if (status)
2963 goto out;
2964
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302965 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2966 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002967 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302968 goto out;
2969 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002970
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302971 /* Delete already configured multicast address list */
2972 if (adapter->mc_addr_list.mc_cnt > 0) {
2973 hdd_info("clear previously configured MC address list");
2974 hdd_disable_and_flush_mc_addr_list(adapter,
2975 pmo_mc_list_change_notify);
2976 }
2977
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002978 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002979 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302980 hdd_disable_and_flush_mc_addr_list(adapter,
2981 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002982 } else {
2983 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302984 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002985 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302986 pmo_ucfg_max_mc_addr_supported(psoc));
2987 hdd_disable_and_flush_mc_addr_list(adapter,
2988 pmo_mc_list_change_notify);
2989 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002990 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002991 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002992 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302993 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002994 if (i == mc_count)
2995 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302996 memset(&(mc_list_request->mc_addr[i].bytes),
2997 0, ETH_ALEN);
2998 memcpy(&(mc_list_request->mc_addr[i].bytes),
2999 ha->addr, ETH_ALEN);
3000 hdd_info("mlist[%d] = %pM", i,
3001 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003002 i++;
3003 }
3004 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303005
3006 mc_list_request->psoc = psoc;
3007 mc_list_request->vdev_id = adapter->sessionId;
3008 mc_list_request->count = mc_count;
3009 status = hdd_cache_mc_addr_list(mc_list_request);
3010 if (status == 0) {
3011 hdd_enable_mc_addr_filtering(adapter,
3012 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003013 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303014 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003015 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303016out:
3017 if (mc_list_request)
3018 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303019 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003020}
3021
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303022
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003023/**
3024 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3025 * @dev: pointer to net_device
3026 *
3027 * Return: none
3028 */
3029static void hdd_set_multicast_list(struct net_device *dev)
3030{
3031 cds_ssr_protect(__func__);
3032 __hdd_set_multicast_list(dev);
3033 cds_ssr_unprotect(__func__);
3034}
3035#endif
3036
3037/**
3038 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3039 * @dev: Pointer to the WLAN device.
3040 * @skb: Pointer to OS packet (sk_buff).
3041 *
3042 * This function is registered with the Linux OS for network
3043 * core to decide which queue to use first.
3044 *
3045 * Return: ac, Queue Index/access category corresponding to UP in IP header
3046 */
3047static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3048#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3049 , void *accel_priv
3050#endif
3051#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3052 , select_queue_fallback_t fallback
3053#endif
3054)
3055{
3056 return hdd_wmm_select_queue(dev, skb);
3057}
3058
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003059static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003060 .ndo_open = hdd_open,
3061 .ndo_stop = hdd_stop,
3062 .ndo_uninit = hdd_uninit,
3063 .ndo_start_xmit = hdd_hard_start_xmit,
3064 .ndo_tx_timeout = hdd_tx_timeout,
3065 .ndo_get_stats = hdd_get_stats,
3066 .ndo_do_ioctl = hdd_ioctl,
3067 .ndo_set_mac_address = hdd_set_mac_address,
3068 .ndo_select_queue = hdd_select_queue,
3069#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003070 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003071#endif
3072};
3073
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003074/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003075static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003076 .ndo_open = hdd_mon_open,
3077 .ndo_stop = hdd_stop,
3078 .ndo_get_stats = hdd_get_stats,
3079};
3080
3081/**
3082 * hdd_set_station_ops() - update net_device ops for monitor mode
3083 * @pWlanDev: Handle to struct net_device to be updated.
3084 * Return: None
3085 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003086void hdd_set_station_ops(struct net_device *pWlanDev)
3087{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003088 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
3089 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
3090 else
3091 pWlanDev->netdev_ops = &wlan_drv_ops;
3092}
3093
3094/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003095 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3096 * @hdd_ctx: global hdd context
3097 * @macAddr: mac address to assign to the interface
3098 * @name: User-visible name of the interface
3099 *
3100 * hdd adapter pointer would point to the netdev->priv space, this function
3101 * would retrive the pointer, and setup the hdd adapter configuration.
3102 *
3103 * Return: the pointer to hdd adapter, otherwise NULL
3104 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003105static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003107 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003108 const char *name)
3109{
3110 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003111 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003112 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003113 /*
3114 * cfg80211 initialization and registration....
3115 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003116 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003117#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3118 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003119#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003120 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3121 hdd_mon_mode_ether_setup : ether_setup),
3122 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003123
3124 if (pWlanDev != NULL) {
3125
3126 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003127 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003128
Jeff Johnson9d295242017-08-29 14:39:48 -07003129 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303130 sta_ctx = &adapter->sessionCtx.station;
3131 qdf_mem_set(sta_ctx->conn_info.staId,
3132 sizeof(sta_ctx->conn_info.staId),
3133 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003134 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003135 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003136 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303137 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138
3139 init_completion(&adapter->session_open_comp_var);
3140 init_completion(&adapter->session_close_comp_var);
3141 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303142 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003143 init_completion(&adapter->linkup_event_var);
3144 init_completion(&adapter->cancel_rem_on_chan_var);
3145 init_completion(&adapter->rem_on_chan_ready_event);
3146 init_completion(&adapter->sta_authorized_event);
3147 init_completion(&adapter->offchannel_tx_event);
3148 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003149 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150 init_completion(&adapter->change_country_code);
3151
3152
3153 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303154 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003155
3156 adapter->offloads_configured = false;
3157 adapter->isLinkUpSvcNeeded = false;
3158 adapter->higherDtimTransition = true;
3159 /* Init the net_device structure */
3160 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3161
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303162 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003163 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303164 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003165 sizeof(tSirMacAddr));
3166 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003167
3168 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3169 pWlanDev->features |=
3170 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3171 pWlanDev->features |= NETIF_F_RXCSUM;
3172
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003173 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3174
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003175 hdd_set_station_ops(adapter->dev);
3176
Dustin Brownc81dd412017-08-15 16:26:28 -07003177 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003179 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003180 adapter->wdev.wiphy = hdd_ctx->wiphy;
3181 adapter->wdev.netdev = pWlanDev;
3182 /* set pWlanDev's parent to underlying device */
3183 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3184 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303185 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303187 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188 }
3189
3190 return adapter;
3191}
3192
Jeff Johnson9d295242017-08-29 14:39:48 -07003193static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003195 struct net_device *dev = adapter->dev;
3196 int ret;
3197
3198 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003200 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003201 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3202
3203 ret = dev_alloc_name(dev, dev->name);
3204 if (ret < 0) {
3205 hdd_err(
3206 "unable to get dev name: %s, err = 0x%x",
3207 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303208 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003209 }
3210 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003211
3212 ret = register_netdevice(dev);
3213 if (ret) {
3214 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3215 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303216 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217 }
3218 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003219 ret = register_netdev(dev);
3220 if (ret) {
3221 hdd_err("register_netdev(%s) failed, err = 0x%x",
3222 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303223 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003224 }
3225 }
3226 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3227
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003228 EXIT();
3229
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303230 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003231}
3232
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003233QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003234{
Jeff Johnson9d295242017-08-29 14:39:48 -07003235 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003236
3237 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003238 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303239 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003240 }
3241
3242 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003243 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303244 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003245 }
3246
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003247 /*
3248 * For NAN Data interface, the close session results in the final
3249 * indication to the userspace
3250 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003251 if (adapter->device_mode == QDF_NDI_MODE)
3252 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003253
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003254 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3255
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003256 /*
3257 * We can be blocked while waiting for scheduled work to be
3258 * flushed, and the adapter structure can potentially be freed, in
3259 * which case the magic will have been reset. So make sure the
3260 * magic is still good, and hence the adapter structure is still
3261 * valid, before signaling completion
3262 */
3263 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3264 complete(&adapter->session_close_comp_var);
3265
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303266 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267}
3268
Jeff Johnson9d295242017-08-29 14:39:48 -07003269int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270{
Dustin Brownd28772b2017-03-17 14:16:07 -07003271 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272
Dustin Brownd28772b2017-03-17 14:16:07 -07003273 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003274 if (QDF_IS_STATUS_ERROR(status))
3275 return qdf_status_to_os_return(status);
3276
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003277 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003278 if (QDF_IS_STATUS_ERROR(status))
3279 return qdf_status_to_os_return(status);
3280
3281 if (wma_capability_enhanced_mcast_filter())
3282 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3283 else
3284 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003285
3286 return qdf_status_to_os_return(status);
3287}
3288
Jeff Johnson9d295242017-08-29 14:39:48 -07003289int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003290{
3291 QDF_STATUS status;
3292 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003293 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003294 unsigned long rc;
3295
3296 hdd_info("destroying vdev %d", adapter->sessionId);
3297
3298 /* vdev created sanity check */
3299 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3300 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3301 return -EINVAL;
3302 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003303 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003304 /*
3305 * In SSR case, there is no need to destroy vdev in firmware since
3306 * it has already asserted. vdev can be released directly.
3307 */
3308 if (cds_is_driver_recovering())
3309 goto release_vdev;
3310
Dustin Brownd28772b2017-03-17 14:16:07 -07003311 /* close sme session (destroy vdev in firmware via legacy API) */
3312 INIT_COMPLETION(adapter->session_close_comp_var);
3313 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3314 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3315 hdd_sme_close_session_callback, adapter);
3316 if (QDF_IS_STATUS_ERROR(status)) {
3317 hdd_err("failed to close sme session: %d", status);
3318 return qdf_status_to_os_return(status);
3319 }
3320
3321 /* block on a completion variable until sme session is closed */
3322 rc = wait_for_completion_timeout(
3323 &adapter->session_close_comp_var,
3324 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3325 if (!rc) {
3326 hdd_err("timed out waiting for close sme session: %ld", rc);
3327 if (adapter->device_mode == QDF_NDI_MODE)
3328 hdd_ndp_session_end_handler(adapter);
3329 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3330 return -ETIMEDOUT;
3331 }
Yue Maf9782842017-05-08 12:49:49 -07003332release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003333 /* do vdev logical destroy via objmgr */
3334 errno = hdd_objmgr_destroy_vdev(adapter);
3335 if (errno) {
3336 hdd_err("failed to destroy objmgr vdev: %d", errno);
3337 return errno;
3338 }
3339
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003340 /* now that sme session is closed, allow physical vdev destroy */
3341 errno = hdd_objmgr_release_vdev(adapter);
3342 if (errno) {
3343 hdd_err("failed to release objmgr vdev: %d", errno);
3344 return errno;
3345 }
3346
Dustin Brownd28772b2017-03-17 14:16:07 -07003347 hdd_info("vdev destroyed successfully");
3348
3349 return 0;
3350}
3351
Jeff Johnson9d295242017-08-29 14:39:48 -07003352int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003353{
3354 QDF_STATUS status;
3355 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003356 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003357 uint32_t type;
3358 uint32_t sub_type;
3359 unsigned long rc;
3360
3361 hdd_info("creating new vdev");
3362
3363 /* determine vdev (sub)type */
3364 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303365 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003366 hdd_err("failed to get vdev type: %d", status);
3367 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003369
3370 /* do vdev create via objmgr */
3371 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003372 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003373 if (errno) {
3374 hdd_err("failed to create objmgr vdev: %d", errno);
3375 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003376 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003377
3378 /* Open a SME session (prepare vdev in firmware via legacy API) */
3379 INIT_COMPLETION(adapter->session_open_comp_var);
3380 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3381 (uint8_t *)&adapter->macAddressCurrent,
3382 adapter->sessionId, type, sub_type);
3383 if (QDF_IS_STATUS_ERROR(status)) {
3384 hdd_err("failed to open sme session: %d", status);
3385 errno = qdf_status_to_os_return(status);
3386 goto objmgr_vdev_destroy;
3387 }
3388
3389 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003390 rc = wait_for_completion_timeout(
3391 &adapter->session_open_comp_var,
3392 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3393 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003394 hdd_err("timed out waiting for open sme session: %ld", rc);
3395 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303396 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3397 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003398 }
3399
3400 /* firmware ready for component communication, raise vdev_ready event */
3401 errno = hdd_vdev_ready(adapter);
3402 if (errno) {
3403 hdd_err("failed to dispatch vdev ready event: %d", errno);
3404 goto hdd_vdev_destroy;
3405 }
3406
3407 hdd_info("vdev %d created successfully", adapter->sessionId);
3408
3409 return 0;
3410
3411 /*
3412 * Due to legacy constraints, we need to destroy in the same order as
3413 * create. So, split error handling into 2 cases to accommodate.
3414 */
3415
3416objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003417 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003418
3419 return errno;
3420
3421hdd_vdev_destroy:
3422 QDF_BUG(!hdd_vdev_destroy(adapter));
3423
3424 return errno;
3425}
3426
Jeff Johnson9d295242017-08-29 14:39:48 -07003427QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003428{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003429 struct hdd_station_ctx *sta_ctx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003430 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003431 QDF_STATUS status;
3432 int ret_val;
3433
3434 ret_val = hdd_vdev_create(adapter);
3435 if (ret_val) {
3436 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303437 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003438 }
3439
Dustin Brownd28772b2017-03-17 14:16:07 -07003440 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3441 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3442 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003443 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003445 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003446 status = hdd_register_wext(adapter->dev);
3447 if (QDF_IS_STATUS_ERROR(status)) {
3448 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449 goto error_register_wext;
3450 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003451 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452
Jeff Johnsond377dce2017-10-04 10:32:42 -07003453 qdf_mem_set(sta_ctx->conn_info.staId,
3454 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303455
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003456 /* set fast roaming capability in sme session */
3457 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3458 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003459 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003460 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461 hdd_ctx->config->OperatingChannel;
3462
3463 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003464 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465
3466 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303467 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003468 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469 status, status);
3470 goto error_init_txrx;
3471 }
3472
3473 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3474
3475 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303476 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003477 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478 status, status);
3479 goto error_wmm_init;
3480 }
3481
3482 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3483
Naveen Rawat247a8682017-06-05 15:00:31 -07003484 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003485 WMI_PDEV_PARAM_BURST_ENABLE,
3486 hdd_ctx->config->enableSifsBurst,
3487 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003488 if (ret_val)
3489 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003490
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003491 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303492 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494error_wmm_init:
3495 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3496 hdd_deinit_tx_rx(adapter);
3497error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003498 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003500 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003502 return status;
3503}
3504
Jeff Johnson9d295242017-08-29 14:39:48 -07003505void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003506{
Wu Gao02bd75b2017-10-13 18:34:02 +08003507 hdd_debug("Cleanup action frame");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003508}
3509
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303510/**
3511 * hdd_station_adapter_deinit() - De-initialize the station adapter
3512 * @hdd_ctx: global hdd context
3513 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003514 * @rtnl_held: Used to indicate whether or not the caller is holding
3515 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303516 *
3517 * This function De-initializes the STA/P2P/OCB adapter.
3518 *
3519 * Return: None.
3520 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003521static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003522 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003523 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303524{
3525 ENTER_DEV(adapter->dev);
3526
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303527 if (adapter->dev) {
3528 if (rtnl_held)
3529 adapter->dev->wireless_handlers = NULL;
3530 else {
3531 rtnl_lock();
3532 adapter->dev->wireless_handlers = NULL;
3533 rtnl_unlock();
3534 }
3535 }
3536
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303537 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3538 hdd_deinit_tx_rx(adapter);
3539 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3540 }
3541
3542 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3543 hdd_wmm_adapter_close(adapter);
3544 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3545 }
3546
3547 hdd_cleanup_actionframe(hdd_ctx, adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303548
3549 EXIT();
3550}
3551
3552/**
3553 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3554 * @hdd_ctx: global hdd context
3555 * @adapter: HDD adapter
3556 * @rtnl_held: the rtnl lock hold flag
3557 * This function De-initializes the AP/P2PGo adapter.
3558 *
3559 * Return: None.
3560 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003561static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003562 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003563 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303564{
3565 ENTER_DEV(adapter->dev);
3566
3567 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3568 hdd_wmm_adapter_close(adapter);
3569 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3570 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003571 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303572
3573 hdd_cleanup_actionframe(hdd_ctx, adapter);
3574
3575 hdd_unregister_hostapd(adapter, rtnl_held);
3576
3577 EXIT();
3578}
3579
Jeff Johnson9d295242017-08-29 14:39:48 -07003580void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003581 bool rtnl_held)
3582{
3583 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303584
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003586 case QDF_STA_MODE:
3587 case QDF_P2P_CLIENT_MODE:
3588 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303590 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591 break;
3592 }
3593
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003594 case QDF_SAP_MODE:
3595 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003596 {
3597
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303598 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599 break;
3600 }
3601
3602 default:
3603 break;
3604 }
3605
3606 EXIT();
3607}
3608
Jeff Johnson9d295242017-08-29 14:39:48 -07003609static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003610 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003611{
3612 struct net_device *pWlanDev = NULL;
3613
3614 if (adapter)
3615 pWlanDev = adapter->dev;
3616 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003617 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618 return;
3619 }
3620
Rajeev Kumardca5f812016-02-04 17:28:06 -08003621 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303622
3623 if (adapter->scan_info.default_scan_ies) {
3624 qdf_mem_free(adapter->scan_info.default_scan_ies);
3625 adapter->scan_info.default_scan_ies = NULL;
3626 }
3627
Komal Seelama89be8d2016-09-29 11:09:26 +05303628 hdd_adapter_runtime_suspend_denit(adapter);
3629
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003630 /*
3631 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3632 * the driver is almost closed and cannot handle either control
3633 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003634 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3635 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003636 * is not right. Setting this flag helps hdd_stop() to recognize that
3637 * the interface is closed and restricts any operations on that
3638 */
3639 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3640
3641 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003642 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003643 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003644 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003646 /*
3647 * Note that the adapter is no longer valid at this point
3648 * since the memory has been reclaimed
3649 */
3650 }
3651}
3652
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003653static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003654 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655{
3656 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003657 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303658 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003659
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303661 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003662 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003663 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303664 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303666 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 }
3668 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3669 adapterNode = pNext;
3670 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303671 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003672}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003673
Arun Khandavalli2358d522016-05-16 18:05:37 +05303674#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3675/**
3676 * hdd_set_fw_log_params() - Set log parameters to FW
3677 * @hdd_ctx: HDD Context
3678 * @adapter: HDD Adapter
3679 *
3680 * This function set the FW Debug log level based on the INI.
3681 *
3682 * Return: None
3683 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003684static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003685 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303686{
3687 uint8_t count = 0, numentries = 0,
3688 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3689 uint32_t value = 0;
3690 int ret;
3691
Arun Khandavallifae92942016-08-01 13:31:08 +05303692 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3693 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003694 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303695 return;
3696 }
3697
Arun Khandavallifae92942016-08-01 13:31:08 +05303698 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303699 hdd_ctx->fw_log_settings.dl_type =
3700 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003701 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303702 WMI_DBGLOG_TYPE,
3703 hdd_ctx->config->enableFwLogType,
3704 DBG_CMD);
3705 if (ret != 0)
3706 hdd_err("Failed to enable FW log type ret %d",
3707 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303708
3709 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303710 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003711 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303712 WMI_DBGLOG_LOG_LEVEL,
3713 hdd_ctx->config->enableFwLogLevel,
3714 DBG_CMD);
3715 if (ret != 0)
3716 hdd_err("Failed to enable FW log level ret %d",
3717 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303718
3719 hdd_string_to_u8_array(
3720 hdd_ctx->config->enableFwModuleLogLevel,
3721 moduleloglevel,
3722 &numentries,
3723 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3724
3725 while (count < numentries) {
3726 /*
3727 * FW module log level input string looks like
3728 * below:
3729 * gFwDebugModuleLoglevel=<FW Module ID>,
3730 * <Log Level>,...
3731 * For example:
3732 * gFwDebugModuleLoglevel=
3733 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3734 * Above input string means :
3735 * For FW module ID 1 enable log level 0
3736 * For FW module ID 2 enable log level 1
3737 * For FW module ID 3 enable log level 2
3738 * For FW module ID 4 enable log level 3
3739 * For FW module ID 5 enable log level 4
3740 * For FW module ID 6 enable log level 5
3741 * For FW module ID 7 enable log level 6
3742 */
3743
Nishank Aggarwale239d962017-03-03 12:26:02 +05303744 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3745 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3746 hdd_err("Module id %d and dbglog level %d input length is more than max",
3747 moduleloglevel[count],
3748 moduleloglevel[count + 1]);
3749 return;
3750 }
3751
3752 value = moduleloglevel[count] << 16;
3753 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003754 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303755 WMI_DBGLOG_MOD_LOG_LEVEL,
3756 value, DBG_CMD);
3757 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303758 hdd_err("Failed to enable FW module log level %d ret %d",
3759 value, ret);
3760
3761 count += 2;
3762 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303763
Arun Khandavalli2358d522016-05-16 18:05:37 +05303764}
3765#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003766static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003767 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303768{
3769}
3770
3771#endif
3772
3773/**
3774 * hdd_set_fw_params() - Set parameters to firmware
3775 * @adapter: HDD adapter
3776 *
3777 * This function Sets various parameters to fw once the
3778 * adapter is started.
3779 *
3780 * Return: 0 on success or errno on failure
3781 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003782int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303783{
3784 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003785 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303786
3787 ENTER_DEV(adapter->dev);
3788
3789 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3790 if (!hdd_ctx)
3791 return -EINVAL;
3792
Dustin Brown732ab9c2017-06-15 13:24:09 -07003793 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3794 hdd_debug("FTM Mode is active; nothing to do");
3795 return 0;
3796 }
3797
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303798 ret = sme_cli_set_command(adapter->sessionId,
3799 WMI_PDEV_PARAM_DTIM_SYNTH,
3800 hdd_ctx->config->enable_lprx, PDEV_CMD);
3801 if (ret) {
3802 hdd_err("Failed to set LPRx");
3803 goto error;
3804 }
3805
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303806 if (adapter->device_mode == QDF_STA_MODE) {
3807 sme_set_smps_cfg(adapter->sessionId,
3808 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3809 hdd_ctx->config->upper_brssi_thresh);
3810
3811 sme_set_smps_cfg(adapter->sessionId,
3812 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3813 hdd_ctx->config->lower_brssi_thresh);
3814
3815 sme_set_smps_cfg(adapter->sessionId,
3816 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3817 hdd_ctx->config->enable_dtim_1chrx);
3818 }
3819
Dustin Brown732ab9c2017-06-15 13:24:09 -07003820 if (hdd_ctx->config->enable2x2) {
3821 hdd_debug("configuring 2x2 mode fw params");
3822
Naveen Rawat247a8682017-06-05 15:00:31 -07003823 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003824 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3825 hdd_ctx->config->enable_cck_tx_fir_override,
3826 PDEV_CMD);
3827 if (ret) {
3828 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3829 ret);
3830 goto error;
3831 }
3832 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303833#define HDD_DTIM_1CHAIN_RX_ID 0x5
3834#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003835 hdd_debug("configuring 1x1 mode fw params");
3836
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003837 /*
3838 * Disable DTIM 1 chain Rx when in 1x1,
3839 * we are passing two value
3840 * as param_id << 29 | param_value.
3841 * Below param_value = 0(disable)
3842 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003843 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003844 WMI_STA_SMPS_PARAM_CMDID,
3845 HDD_DTIM_1CHAIN_RX_ID <<
3846 HDD_SMPS_PARAM_VALUE_S,
3847 VDEV_CMD);
3848 if (ret) {
3849 hdd_err("DTIM 1 chain set failed %d", ret);
3850 goto error;
3851 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303852
Naveen Rawat247a8682017-06-05 15:00:31 -07003853 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003854 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3855 hdd_ctx->config->txchainmask1x1,
3856 PDEV_CMD);
3857 if (ret) {
3858 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3859 ret);
3860 goto error;
3861 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303862
Naveen Rawat247a8682017-06-05 15:00:31 -07003863 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003864 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3865 hdd_ctx->config->rxchainmask1x1,
3866 PDEV_CMD);
3867 if (ret) {
3868 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3869 ret);
3870 goto error;
3871 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303872#undef HDD_DTIM_1CHAIN_RX_ID
3873#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003874 }
3875
Naveen Rawat247a8682017-06-05 15:00:31 -07003876 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003877 WMI_PDEV_PARAM_HYST_EN,
3878 hdd_ctx->config->enableMemDeepSleep,
3879 PDEV_CMD);
3880 if (ret) {
3881 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3882 goto error;
3883 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303884
Naveen Rawat247a8682017-06-05 15:00:31 -07003885 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003886 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3887 hdd_ctx->config->rts_profile,
3888 VDEV_CMD);
3889 if (ret) {
3890 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3891 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303892 }
3893
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003894 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3895
3896 ret = wma_cli_set_command(adapter->sessionId,
3897 GEN_VDEV_PARAM_AMSDU,
3898 hdd_ctx->config->max_amsdu_num,
3899 GEN_CMD);
3900 if (ret != 0) {
3901 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3902 goto error;
3903 }
3904
Arun Khandavalli2358d522016-05-16 18:05:37 +05303905 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303906 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003907
Arun Khandavalli2358d522016-05-16 18:05:37 +05303908 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303909
Arun Khandavalli2358d522016-05-16 18:05:37 +05303910error:
3911 return -EINVAL;
3912}
3913
Ryan Hsu07495ea2016-01-21 15:25:39 -08003914/**
3915 * hdd_open_adapter() - open and setup the hdd adatper
3916 * @hdd_ctx: global hdd context
3917 * @session_type: type of the interface to be created
3918 * @iface_name: User-visible name of the interface
3919 * @macAddr: MAC address to assign to the interface
3920 * @name_assign_type: the name of assign type of the netdev
3921 * @rtnl_held: the rtnl lock hold flag
3922 *
3923 * This function open and setup the hdd adpater according to the device
3924 * type request, assign the name, the mac address assigned, and then prepared
3925 * the hdd related parameters, queue, lock and ready to start.
3926 *
3927 * Return: the pointer of hdd adapter, otherwise NULL.
3928 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003929struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003931 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003932 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933{
Jeff Johnson9d295242017-08-29 14:39:48 -07003934 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303936 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Jeff Johnson5e4b93c2017-09-30 18:09:16 -07003937 struct hdd_cfg80211_state *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003938
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939
3940 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3941 /*
3942 * Max limit reached on the number of vdevs configured by the
3943 * host. Return error
3944 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303945 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3946 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947 return NULL;
3948 }
3949
3950 if (macAddr == NULL) {
3951 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303952 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953 return NULL;
3954 }
3955 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303956 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303957 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3958 " already exists",
3959 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003960 return NULL;
3961 }
3962
3963 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003964 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003965 /* Reset locally administered bit if the device mode is STA */
3966 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303967 hdd_info("locally administered bit reset in sta mode: "
3968 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003969 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003970 case QDF_P2P_CLIENT_MODE:
3971 case QDF_P2P_DEVICE_MODE:
3972 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003973 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303974 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003975 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3976 name_assign_type,
3977 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003978
3979 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303980 hdd_err("failed to allocate adapter for session %d",
3981 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003982 return NULL;
3983 }
3984
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003985 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003987 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003988 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303989 else if (QDF_MONITOR_MODE == session_type)
3990 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 else
3992 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3993
3994 adapter->device_mode = session_type;
3995
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003997 /*
3998 * Workqueue which gets scheduled in IPv4 notification
3999 * callback
4000 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4002 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004003
4004#ifdef WLAN_NS_OFFLOAD
4005 /*
4006 * Workqueue which gets scheduled in IPv6
4007 * notification callback.
4008 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004009 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4010 hdd_ipv6_notifier_work_queue);
4011#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304013 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004014 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304015 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004016 }
4017
4018 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004019 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004020 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304021 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4022 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304023
Ravi Joshi1a292562017-05-18 16:28:54 -07004024 /* Initialize NAN Data Interface */
4025 if (QDF_NDI_MODE == session_type) {
4026 status = hdd_init_nan_data_mode(adapter);
4027 if (QDF_STATUS_SUCCESS != status)
4028 goto err_free_netdev;
4029 }
4030
4031 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004033 case QDF_P2P_GO_MODE:
4034 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004035 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4036 name_assign_type,
4037 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004039 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304040 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041 return NULL;
4042 }
4043
4044 adapter->wdev.iftype =
4045 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004046 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004047 NL80211_IFTYPE_P2P_GO;
4048 adapter->device_mode = session_type;
4049
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004050 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304051 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4053 goto err_free_netdev;
4054 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004055 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304057 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4058 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304059
4060 /*
4061 * Workqueue which gets scheduled in IPv4 notification
4062 * callback
4063 */
4064 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4065 hdd_ipv4_notifier_work_queue);
4066
4067#ifdef WLAN_NS_OFFLOAD
4068 /*
4069 * Workqueue which gets scheduled in IPv6
4070 * notification callback.
4071 */
4072 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4073 hdd_ipv6_notifier_work_queue);
4074#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004075 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304076 case QDF_FTM_MODE:
4077 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4078 name_assign_type,
4079 "wlan0");
4080 if (NULL == adapter) {
4081 hdd_err("Failed to allocate adapter for FTM mode");
4082 return NULL;
4083 }
4084 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4085 adapter->device_mode = session_type;
4086 status = hdd_register_interface(adapter, rtnl_held);
4087 if (QDF_STATUS_SUCCESS != status) {
4088 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4089 goto err_free_netdev;
4090 }
4091 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004092 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304093 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304094 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4095 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304096 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004098 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304099 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 return NULL;
4101 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004102
hqueaa33ee2017-05-04 17:56:35 +08004103 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004106
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304107 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004108 /* Add it to the hdd's session list. */
4109 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304110 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004111 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304112 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004113 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004114 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4116 }
4117 }
4118
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304119 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004120 if (NULL != adapter) {
4121 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4122 adapter = NULL;
4123 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004124 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304125 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004126
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004127 return NULL;
4128 }
4129
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304130 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004131 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4132 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004134 /* Adapter successfully added. Increment the vdev count */
4135 hdd_ctx->current_intf_count++;
4136
Jeff Johnson5880d792016-08-15 13:32:30 -07004137 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004138 hdd_ctx->current_intf_count);
4139
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004140 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004141 }
4142
Rajeev Kumardca5f812016-02-04 17:28:06 -08004143 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004144 hdd_err("Interface %s wow debug_fs init failed",
4145 netdev_name(adapter->dev));
4146
4147 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4148 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004149
4150 return adapter;
4151
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304154 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004155
4156 return NULL;
4157}
4158
Jeff Johnson9d295242017-08-29 14:39:48 -07004159QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004160 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004161{
4162 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304163 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004164
4165 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304166 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004167 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168 status);
4169 return status;
4170 }
4171
Jeff Johnson57eb2732017-10-02 11:40:20 -07004172 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004173 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304174 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175 break;
4176
4177 pCurrent = pNext;
4178 }
4179 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304180 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004181 /*
4182 * Here we are stopping global bus_bw timer & work per adapter.
4183 *
4184 * The reason is to fix one race condition between
4185 * bus bandwidth work and cleaning up an adapter.
4186 * Under some conditions, it is possible for the bus bandwidth
4187 * work to access a particularly destroyed adapter, leading to
4188 * use-after-free.
4189 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004190 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004191 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004192 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004193
4194 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004195 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4196 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004197 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004198 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304199 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004200 adapterNode = NULL;
4201
Dustin Brown5ec6b552017-03-31 12:11:40 -07004202 /* conditionally restart the bw timer */
4203 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004205 /* Adapter removed. Decrement vdev count */
4206 if (hdd_ctx->current_intf_count != 0)
4207 hdd_ctx->current_intf_count--;
4208
4209 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304210 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004211 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304212
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304213 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004214}
4215
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004216/**
4217 * hdd_close_all_adapters - Close all open adapters
4218 * @hdd_ctx: Hdd context
4219 * rtnl_held: True if RTNL lock held
4220 *
4221 * Close all open adapters.
4222 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304223 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004224 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004225QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004226{
4227 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304228 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004229
4230 ENTER();
4231
4232 do {
4233 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304234 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304235 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004236 pHddAdapterNode->adapter->macAddressCurrent.bytes);
4237 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004238 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304239 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304240 /* Adapter removed. Decrement vdev count */
4241 if (hdd_ctx->current_intf_count != 0)
4242 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004243 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304244 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004245
4246 EXIT();
4247
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304248 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004249}
4250
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004251void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004252{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304253 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004254 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004255
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004256 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004257 case QDF_STA_MODE:
4258 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004260 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004261 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004262 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004263 break;
4264 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004265 case QDF_SAP_MODE:
4266 case QDF_P2P_GO_MODE:
4267 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004268 {
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004269 bssid = &adapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004270 break;
4271 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004272 case QDF_FTM_MODE:
4273 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274 default:
4275 /*
4276 * wlan_hdd_reset_prob_rspies should not have been called
4277 * for these kind of devices
4278 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004279 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004280 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004281 return;
4282 }
4283
Anurag Chouhanc5548422016-02-24 18:33:27 +05304284 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004285 updateIE.smeSessionId = adapter->sessionId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004286 updateIE.ieBufferlength = 0;
4287 updateIE.pAdditionIEBuffer = NULL;
4288 updateIE.append = true;
4289 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004290 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304292 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004293 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004294 }
4295}
4296
Jeff Johnson9d295242017-08-29 14:39:48 -07004297QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004298 const bool bCloseSession)
4299{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304300 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004301 struct hdd_wext_state *pWextState =
4302 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004303 union iwreq_data wrqu;
4304 tSirUpdateIE updateIE;
4305 unsigned long rc;
4306
4307 ENTER();
4308
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004309 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304310 wlan_hdd_netif_queue_control(adapter,
4311 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4312 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004313 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004314 case QDF_STA_MODE:
4315 case QDF_P2P_CLIENT_MODE:
4316 case QDF_IBSS_MODE:
4317 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004318 case QDF_NDI_MODE:
4319 if ((QDF_NDI_MODE == adapter->device_mode) ||
4320 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004321 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4322 hdd_is_connecting(
4323 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004324 INIT_COMPLETION(adapter->disconnect_comp_var);
4325 /*
4326 * For NDI do not use pWextState from sta_ctx, if needed
4327 * extract from ndi_ctx.
4328 */
4329 if (QDF_NDI_MODE == adapter->device_mode)
4330 qdf_ret_status = sme_roam_disconnect(
4331 hdd_ctx->hHal,
4332 adapter->sessionId,
4333 eCSR_DISCONNECT_REASON_NDI_DELETE);
4334 else if (pWextState->roamProfile.BSSType ==
4335 eCSR_BSS_TYPE_START_IBSS)
4336 qdf_ret_status = sme_roam_disconnect(
4337 hdd_ctx->hHal,
4338 adapter->sessionId,
4339 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004340 else if (QDF_STA_MODE == adapter->device_mode)
4341 qdf_ret_status =
4342 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004343 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004344 qdf_ret_status = sme_roam_disconnect(
4345 hdd_ctx->hHal,
4346 adapter->sessionId,
4347 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004348 /* success implies disconnect command got
4349 * queued up successfully
4350 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004351 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4352 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353 rc = wait_for_completion_timeout(
4354 &adapter->disconnect_comp_var,
4355 msecs_to_jiffies
4356 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004357 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004358 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004359 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004360 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4361 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004362 memset(&wrqu, '\0', sizeof(wrqu));
4363 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4364 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4365 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4366 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304367 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004368 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004369
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304370 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304371 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004372
4373#ifdef WLAN_OPEN_SOURCE
4374 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4375#endif
4376
4377 hdd_deregister_tx_flow_control(adapter);
4378
4379#ifdef WLAN_NS_OFFLOAD
4380#ifdef WLAN_OPEN_SOURCE
4381 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4382#endif
4383#endif
4384
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304385 if (adapter->device_mode == QDF_STA_MODE)
4386 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4387 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004388 /*
4389 * It is possible that the caller of this function does not
4390 * wish to close the session
4391 */
Krunal Soni985b8132017-02-10 18:49:08 -08004392 if (true == bCloseSession) {
4393 if (0 != wlan_hdd_try_disconnect(adapter)) {
4394 hdd_err("Error: Can't disconnect adapter");
4395 return QDF_STATUS_E_FAILURE;
4396 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004397 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004398 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399 break;
4400
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004401 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304402 /* Flush IPA exception path packets */
4403 hdd_ipa_flush(hdd_ctx);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004404 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004405 if (QDF_SAP_MODE == adapter->device_mode) {
4406 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4407 cds_flush_delayed_work(
4408 &adapter->acs_pending_work);
4409 clear_bit(ACS_PENDING, &adapter->event_flags);
4410 }
4411 }
Krunal Soni22208392017-09-29 18:10:34 -07004412 cds_flush_work(&adapter->sap_stop_bss_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004413 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004414 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004415 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4416
4417 hdd_deregister_tx_flow_control(adapter);
4418
Kapil Guptac1224bf2017-06-22 21:22:40 +05304419 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004420 mutex_lock(&hdd_ctx->sap_lock);
4421 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304422 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304423 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424
4425 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004426 status = wlansap_stop_bss(
4427 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004428
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304429 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004430 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004431 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304432 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304433 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304434 qdf_status =
4435 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004436 qdf_stop_bss_event,
4437 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438
Anurag Chouhance0dc992016-02-16 18:18:03 +05304439 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004440 hdd_err("failure waiting for wlansap_stop_bss %d",
4441 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004442 }
4443 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004444 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004445 }
4446 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004447 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4448 adapter->device_mode,
4449 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004450
Anurag Chouhanc5548422016-02-24 18:33:27 +05304451 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004452 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004453 updateIE.smeSessionId = adapter->sessionId;
4454 updateIE.ieBufferlength = 0;
4455 updateIE.pAdditionIEBuffer = NULL;
4456 updateIE.append = false;
4457 updateIE.notify = false;
4458 /* Probe bcn reset */
4459 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4460 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304461 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004462 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004463 }
4464 /* Assoc resp reset */
4465 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4466 &updateIE,
4467 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304468 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004469 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004470 }
4471 /* Reset WNI_CFG_PROBE_RSP Flags */
4472 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004473 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004474 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4475 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304476 /*
4477 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4478 */
4479 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4480 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4481
Peng Xu66162de2016-02-11 17:01:20 -08004482 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004483 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004484 mutex_unlock(&hdd_ctx->sap_lock);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304485
4486#ifdef WLAN_OPEN_SOURCE
4487 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4488#endif
4489
4490#ifdef WLAN_NS_OFFLOAD
4491#ifdef WLAN_OPEN_SOURCE
4492 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4493#endif
4494#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004495 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004496 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004497 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004498 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004499 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 break;
4501 default:
4502 break;
4503 }
4504
4505 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304506 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507}
4508
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304509/**
4510 * hdd_deinit_all_adapters - deinit all adapters
4511 * @hdd_ctx: HDD context
4512 * @rtnl_held: True if RTNL lock held
4513 *
4514 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004515void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304516{
4517 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4518 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004519 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304520
4521 ENTER();
4522
4523 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4524
4525 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004526 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304527 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4528 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4529 adapter_node = next;
4530 }
4531
4532 EXIT();
4533}
4534
Dustin Brown27cd9942017-09-27 16:11:44 -07004535QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4536 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537{
4538 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304539 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004540 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004541
4542 ENTER();
4543
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304544 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4545
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004546 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4547
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304548 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004549 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004550 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004551 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4552 adapterNode = pNext;
4553 }
4554
4555 EXIT();
4556
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304557 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004558}
4559
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004560QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004561{
4562 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304563 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004564 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004565 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004566 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004567
4568 ENTER();
4569
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304570 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004572 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4573
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304574 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004575 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004576 hdd_notice("Disabling queues for adapter type: %d",
4577 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304578
4579 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004580 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304581 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004582 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304583
Arun Khandavallicc544b32017-01-30 19:52:16 +05304584 if (hdd_ctx->config->sap_internal_restart &&
4585 adapter->device_mode == QDF_SAP_MODE) {
4586 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304587 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304588 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004589 if (test_bit(SOFTAP_BSS_STARTED,
4590 &adapter->event_flags)) {
4591 hdd_sap_indicate_disconnect_for_sta(adapter);
4592 hdd_cleanup_actionframe(hdd_ctx, adapter);
4593 hdd_sap_destroy_events(adapter);
4594 }
4595 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4596 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304597 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304598 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004599 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004600 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004601
4602 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4603
4604 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004605 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4606 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004607 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4608 hdd_wmm_adapter_close(adapter);
4609 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4610 }
4611
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304612 if (adapter->device_mode == QDF_STA_MODE)
4613 hdd_clear_fils_connection_info(adapter);
4614
Wu Gao3545e642017-07-14 19:24:41 +08004615 if (adapter->device_mode == QDF_SAP_MODE) {
4616 /*
4617 * If adapter is SAP, set session ID to invalid
4618 * since SAP session will be cleanup during SSR.
4619 */
Wu Gao36717432016-11-21 15:09:48 +08004620 wlansap_set_invalid_session(
4621 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4622
Wu Gao3545e642017-07-14 19:24:41 +08004623 wlansap_cleanup_cac_timer(
4624 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4625 }
4626
Yue Mad5b4b9f2017-05-26 16:23:40 -07004627 /* Delete peers if any for STA and P2P client modes */
4628 if (adapter->device_mode == QDF_STA_MODE ||
4629 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004630 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004631 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004632 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004633
4634 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4635 peerMacAddr.bytes);
4636 }
4637
Yue Maf9782842017-05-08 12:49:49 -07004638 /* Destroy vdev which will be recreated during reinit. */
4639 hdd_vdev_destroy(adapter);
4640
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004641 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4642 adapterNode = pNext;
4643 }
4644
4645 EXIT();
4646
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304647 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004648}
4649
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004650bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304651{
4652 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4653 QDF_STATUS status;
4654 bool close_modules = true;
4655
Arun Khandavalliba479c42017-07-26 21:29:40 +05304656 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4657 hdd_info("FTM mode, don't close the module");
4658 return false;
4659 }
4660
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304661 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4662 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4663 if (test_bit(DEVICE_IFACE_OPENED,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004664 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004665 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304666 close_modules = false;
4667 break;
4668 }
4669 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4670 adapter_node = next;
4671 }
4672
4673 return close_modules;
4674}
4675
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304676bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304677{
4678 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4679 return true;
4680 else
4681 return false;
4682}
4683
Anurag Chouhanc4092922016-09-08 15:56:11 +05304684#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004685 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304686struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4687 struct ieee80211_channel *channel,
4688 const u8 *bssid, const u8 *ssid,
4689 size_t ssid_len)
4690{
4691 return cfg80211_get_bss(wiphy, channel, bssid,
4692 ssid, ssid_len,
4693 WLAN_CAPABILITY_ESS,
4694 WLAN_CAPABILITY_ESS);
4695}
4696#else
4697struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4698 struct ieee80211_channel *channel,
4699 const u8 *bssid, const u8 *ssid,
4700 size_t ssid_len)
4701{
4702 return cfg80211_get_bss(wiphy, channel, bssid,
4703 ssid, ssid_len,
4704 IEEE80211_BSS_TYPE_ESS,
4705 IEEE80211_PRIVACY_ANY);
4706}
4707#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304708
Abhishek Singha84d3952016-09-13 13:45:05 +05304709#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304710#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4711 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4712/**
4713 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4714 * @timeout_reason: reason for connect timeout
4715 *
4716 * This function is used to convert host timeout
4717 * reason enum to kernel specific enum.
4718 *
4719 * Return: nl timeout enum
4720 */
4721static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4722 tSirResultCodes timeout_reason)
4723{
4724 switch (timeout_reason) {
4725 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4726 return NL80211_TIMEOUT_SCAN;
4727 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4728 return NL80211_TIMEOUT_AUTH;
4729 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4730 return NL80211_TIMEOUT_ASSOC;
4731 default:
4732 return NL80211_TIMEOUT_UNSPECIFIED;
4733 }
4734}
4735
4736/**
4737 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4738 * @dev: network device
4739 * @bssid: bssid to which we want to associate
4740 * @timeout_reason: reason for connect timeout
4741 *
4742 * This API is used to send connection timeout reason to supplicant
4743 *
4744 * Return: void
4745 */
4746static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4747 const u8 *bssid,
4748 tSirResultCodes timeout_reason)
4749{
4750 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004751
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304752 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4753
4754 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4755 nl_timeout_reason);
4756}
4757
4758/**
4759 * __hdd_connect_bss() - API to send connection status to supplicant
4760 * @dev: network device
4761 * @bssid: bssid to which we want to associate
4762 * @req_ie: Request Information Element
4763 * @req_ie_len: len of the req IE
4764 * @resp_ie: Response IE
4765 * @resp_ie_len: len of ht response IE
4766 * @status: status
4767 * @gfp: Kernel Flag
4768 * @timeout_reason: reason for connect timeout
4769 *
4770 * Return: void
4771 */
4772static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4773 struct cfg80211_bss *bss, const u8 *req_ie,
4774 size_t req_ie_len, const u8 *resp_ie,
4775 size_t resp_ie_len, int status, gfp_t gfp,
4776 tSirResultCodes timeout_reason)
4777{
4778 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004779
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304780 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4781
4782 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4783 resp_ie, resp_ie_len, status, gfp,
4784 nl_timeout_reason);
4785}
4786#else
4787#if defined CFG80211_CONNECT_TIMEOUT
4788static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4789 const u8 *bssid,
4790 tSirResultCodes timeout_reason)
4791{
4792 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4793}
4794#endif
4795
4796static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4797 struct cfg80211_bss *bss, const u8 *req_ie,
4798 size_t req_ie_len, const u8 *resp_ie,
4799 size_t resp_ie_len, int status, gfp_t gfp,
4800 tSirResultCodes timeout_reason)
4801{
4802 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4803 resp_ie, resp_ie_len, status, gfp);
4804}
4805#endif
4806
Abhishek Singha84d3952016-09-13 13:45:05 +05304807/**
4808 * hdd_connect_bss() - API to send connection status to supplicant
4809 * @dev: network device
4810 * @bssid: bssid to which we want to associate
4811 * @req_ie: Request Information Element
4812 * @req_ie_len: len of the req IE
4813 * @resp_ie: Response IE
4814 * @resp_ie_len: len of ht response IE
4815 * @status: status
4816 * @gfp: Kernel Flag
4817 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304818 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304819 *
4820 * The API is a wrapper to send connection status to supplicant
4821 *
4822 * Return: Void
4823 */
4824#if defined CFG80211_CONNECT_TIMEOUT
4825static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4826 struct cfg80211_bss *bss, const u8 *req_ie,
4827 size_t req_ie_len, const u8 *resp_ie,
4828 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304829 bool connect_timeout,
4830 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304831{
4832 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304833 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304834 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304835 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4836 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304837}
4838#else
4839static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4840 struct cfg80211_bss *bss, const u8 *req_ie,
4841 size_t req_ie_len, const u8 *resp_ie,
4842 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304843 bool connect_timeout,
4844 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304845{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304846 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4847 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304848}
4849#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304850
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304851#ifdef WLAN_FEATURE_FILS_SK
4852#ifdef CFG80211_CONNECT_DONE
4853#ifdef CFG80211_FILS_SK_OFFLOAD_SUPPORT
4854/**
4855 * hdd_populate_fils_params() - Populate FILS keys to connect response
4856 * @fils_params: connect response to supplicant
4857 * @fils_kek: FILS kek
4858 * @fils_kek_len: FILS kek length
4859 * @pmk: FILS PMK
4860 * @pmk_len: FILS PMK length
4861 * @pmkid: PMKID
4862 * @fils_seq_num: FILS Seq number
4863 *
4864 * Return: None
4865 */
4866static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4867 *fils_params, const uint8_t *fils_kek,
4868 size_t fils_kek_len, const uint8_t *pmk,
4869 size_t pmk_len, const uint8_t *pmkid,
4870 uint16_t fils_seq_num)
4871{
4872 /* Increament seq number to be used for next FILS */
4873 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4874 fils_params->update_erp_next_seq_num = true;
4875 fils_params->fils_kek = fils_kek;
4876 fils_params->fils_kek_len = fils_kek_len;
4877 fils_params->pmk = pmk;
4878 fils_params->pmk_len = pmk_len;
4879 fils_params->pmkid = pmkid;
4880}
4881#else
4882static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4883 *fils_params, const uint8_t
4884 *fils_kek, size_t fils_kek_len,
4885 const uint8_t *pmk, size_t pmk_len,
4886 const uint8_t *pmkid,
4887 uint16_t fils_seq_num)
4888{ }
4889#endif
4890
4891/**
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304892 * hdd_update_hlp_info() - Update HLP packet received in FILS assoc rsp
4893 * @dev: net device
4894 * @roam_fils_params: Fils join rsp params
4895 *
4896 * This API is used to send the received HLP packet in Assoc rsp(FILS AKM)
4897 * to the network layer.
4898 *
4899 * Return: None
4900 */
4901static void hdd_update_hlp_info(struct net_device *dev,
4902 struct fils_join_rsp_params *roam_fils_params)
4903{
4904 struct sk_buff *skb;
4905 uint16_t skb_len;
4906 struct llc_snap_hdr_t *llc_hdr;
4907 QDF_STATUS status;
4908 uint8_t *hlp_data = roam_fils_params->hlp_data;
4909 uint16_t hlp_data_len = roam_fils_params->hlp_data_len;
4910 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
4911
4912 /* Calculate skb length */
4913 skb_len = (2 * ETH_ALEN) + hlp_data_len;
4914 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
4915 if (skb == NULL) {
4916 hdd_err("HLP packet nbuf alloc fails");
4917 return;
4918 }
4919
4920 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
4921 QDF_MAC_ADDR_SIZE);
4922 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
4923 QDF_MAC_ADDR_SIZE);
4924
4925 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
4926 if (IS_SNAP(llc_hdr)) {
4927 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4928 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4929 }
4930
4931 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
4932
4933 /*
4934 * This HLP packet is formed from HLP info encapsulated
4935 * in assoc response frame which is AEAD encrypted.
4936 * Hence, this checksum validation can be set unnecessary.
4937 * i.e. network layer need not worry about checksum.
4938 */
4939 skb->ip_summed = CHECKSUM_UNNECESSARY;
4940
4941 status = hdd_rx_packet_cbk(padapter, skb);
4942 if (QDF_IS_STATUS_ERROR(status)) {
4943 hdd_err("Sending HLP packet fails");
4944 return;
4945 }
4946 hdd_debug("send HLP packet to netif successfully");
4947}
4948
4949/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304950 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4951 * @dev: network device
4952 * @bssid: bssid to which we want to associate
4953 * @bss: cfg80211 bss info
4954 * @roam_info: information about connected bss
4955 * @req_ie: Request Information Element
4956 * @req_ie_len: len of the req IE
4957 * @resp_ie: Response IE
4958 * @resp_ie_len: len of ht response IE
4959 * @status: status
4960 * @gfp: allocation flags
4961 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4962 * @timeout_reason: reason for connect timeout
4963 * @roam_fils_params: FILS join response params
4964 *
4965 * This API is used as wrapper to send FILS key/sequence number
4966 * params etc. to supplicant in case of FILS connection
4967 *
4968 * Return: None
4969 */
4970static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4971 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4972 const u8 *req_ie, size_t req_ie_len,
4973 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004974 gfp_t gfp, bool connect_timeout,
4975 tSirResultCodes timeout_reason,
4976 struct fils_join_rsp_params *roam_fils_params)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304977{
4978 struct cfg80211_connect_resp_params fils_params;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004979
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304980 qdf_mem_zero(&fils_params, sizeof(fils_params));
4981
4982 if (!roam_fils_params) {
4983 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4984 } else {
4985 fils_params.status = status;
4986 fils_params.bssid = bssid;
4987 fils_params.timeout_reason = timeout_reason;
4988 fils_params.req_ie = req_ie;
4989 fils_params.req_ie_len = req_ie_len;
4990 fils_params.resp_ie = resp_ie;
4991 fils_params.resp_ie_len = resp_ie_len;
4992 fils_params.bss = bss;
4993 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4994 roam_fils_params->kek_len,
4995 roam_fils_params->fils_pmk,
4996 roam_fils_params->fils_pmk_len,
4997 roam_fils_params->fils_pmkid,
4998 roam_info->fils_seq_num);
4999 }
5000 hdd_debug("FILS indicate connect status %d seq no %d",
5001 fils_params.status,
5002 fils_params.fils_erp_next_seq_num);
5003
5004 cfg80211_connect_done(dev, &fils_params, gfp);
5005
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305006 if (roam_fils_params && roam_fils_params->hlp_data_len)
5007 hdd_update_hlp_info(dev, roam_fils_params);
5008
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305009 /* Clear all the FILS key info */
5010 if (roam_fils_params && roam_fils_params->fils_pmk)
5011 qdf_mem_free(roam_fils_params->fils_pmk);
5012 if (roam_fils_params)
5013 qdf_mem_free(roam_fils_params);
5014 roam_info->fils_join_rsp = NULL;
5015}
5016#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005017static inline void
5018hdd_connect_done(struct net_device *dev, const u8 *bssid,
5019 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
5020 const u8 *req_ie, size_t req_ie_len,
5021 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5022 gfp_t gfp, bool connect_timeout,
5023 tSirResultCodes timeout_reason,
5024 struct fils_join_rsp_params *roam_fils_params)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305025{ }
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305026
5027static inline void hdd_update_hlp_info(struct net_device *dev,
5028 struct fils_join_rsp_params *roam_fils_params)
5029
5030{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305031#endif
5032#endif
5033
5034#if defined(CFG80211_CONNECT_DONE) && defined(WLAN_FEATURE_FILS_SK)
5035/**
5036 * hdd_fils_update_connect_results() - API to send fils connection status to
5037 * supplicant.
5038 * @dev: network device
5039 * @bssid: bssid to which we want to associate
5040 * @bss: cfg80211 bss info
5041 * @roam_info: information about connected bss
5042 * @req_ie: Request Information Element
5043 * @req_ie_len: len of the req IE
5044 * @resp_ie: Response IE
5045 * @resp_ie_len: len of ht response IE
5046 * @status: status
5047 * @gfp: allocation flags
5048 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5049 * @timeout_reason: reason for connect timeout
5050 *
5051 * The API is a wrapper to send connection status to supplicant
5052 *
5053 * Return: 0 if success else failure
5054 */
5055static int hdd_fils_update_connect_results(struct net_device *dev,
5056 const u8 *bssid,
5057 struct cfg80211_bss *bss,
5058 tCsrRoamInfo *roam_info, const u8 *req_ie,
5059 size_t req_ie_len, const u8 *resp_ie,
5060 size_t resp_ie_len, u16 status, gfp_t gfp,
5061 bool connect_timeout,
5062 tSirResultCodes timeout_reason)
5063{
5064 ENTER();
5065 if (!roam_info || !roam_info->is_fils_connection)
5066 return -EINVAL;
5067
5068 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5069 resp_ie, resp_ie_len, status, gfp, connect_timeout,
5070 timeout_reason, roam_info->fils_join_rsp);
5071 return 0;
5072}
5073#else
5074static inline int hdd_fils_update_connect_results(struct net_device *dev,
5075 const u8 *bssid,
5076 struct cfg80211_bss *bss,
5077 tCsrRoamInfo *roam_info, const u8 *req_ie,
5078 size_t req_ie_len, const u8 *resp_ie,
5079 size_t resp_ie_len, u16 status, gfp_t gfp,
5080 bool connect_timeout,
5081 tSirResultCodes timeout_reason)
5082{
5083 return -EINVAL;
5084}
5085#endif
5086
Anurag Chouhanc4092922016-09-08 15:56:11 +05305087/**
5088 * hdd_connect_result() - API to send connection status to supplicant
5089 * @dev: network device
5090 * @bssid: bssid to which we want to associate
5091 * @roam_info: information about connected bss
5092 * @req_ie: Request Information Element
5093 * @req_ie_len: len of the req IE
5094 * @resp_ie: Response IE
5095 * @resp_ie_len: len of ht response IE
5096 * @status: status
5097 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305098 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305099 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305100 *
5101 * The API is a wrapper to send connection status to supplicant
5102 * and allow runtime suspend
5103 *
5104 * Return: Void
5105 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305106void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5107 tCsrRoamInfo *roam_info, const u8 *req_ie,
5108 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305109 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305110 bool connect_timeout,
5111 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305112{
Jeff Johnson9d295242017-08-29 14:39:48 -07005113 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305114 struct cfg80211_bss *bss = NULL;
5115
5116 if (WLAN_STATUS_SUCCESS == status) {
5117 struct ieee80211_channel *chan;
5118 int freq;
5119 int chan_no = roam_info->pBssDesc->channelId;
5120
5121 if (chan_no <= 14)
5122 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005123 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305124 else
5125 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005126 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305127
5128 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5129 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5130 roam_info->u.pConnectedProfile->SSID.ssId,
5131 roam_info->u.pConnectedProfile->SSID.length);
5132 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305133
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305134 if (hdd_fils_update_connect_results(dev, bssid, bss,
5135 roam_info, req_ie, req_ie_len, resp_ie,
5136 resp_ie_len, status, gfp, connect_timeout,
5137 timeout_reason) != 0) {
5138 hdd_connect_bss(dev, bssid, bss, req_ie,
5139 req_ie_len, resp_ie, resp_ie_len,
5140 status, gfp, connect_timeout, timeout_reason);
5141 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305142
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005143 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005144 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305145}
5146#else
5147void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5148 tCsrRoamInfo *roam_info, const u8 *req_ie,
5149 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305150 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305151 bool connect_timeout,
5152 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305153{
Jeff Johnson9d295242017-08-29 14:39:48 -07005154 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305155
Anurag Chouhanc4092922016-09-08 15:56:11 +05305156 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5157 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005158
5159 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005160 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305161}
5162#endif
5163
5164
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005165QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005166{
5167 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305168 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005169 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305171 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005172#endif
5173 eConnectionState connState;
5174
5175 ENTER();
5176
5177 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305178 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005179 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005180
Arun Khandavallifae92942016-08-01 13:31:08 +05305181 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305182 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305183
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005184 hdd_wmm_init(adapter);
5185
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005186 adapter->scan_info.mScanPending = false;
5187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005189 case QDF_STA_MODE:
5190 case QDF_P2P_CLIENT_MODE:
5191 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005192
5193 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5194 ->conn_info.connState;
5195
5196 hdd_init_station_mode(adapter);
5197 /* Open the gates for HDD to receive Wext commands */
5198 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005200 /* Indicate disconnect event to supplicant
5201 * if associated previously
5202 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005204 eConnectionState_IbssConnected == connState ||
5205 eConnectionState_NotConnected == connState ||
5206 eConnectionState_IbssDisconnected == connState ||
5207 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005208 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005209
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 memset(&wrqu, '\0', sizeof(wrqu));
5211 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5212 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5213 wireless_send_event(adapter->dev, SIOCGIWAP,
5214 &wrqu, NULL);
5215 adapter->sessionCtx.station.
5216 hdd_ReassocScenario = false;
5217
5218 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305219 wlan_hdd_cfg80211_indicate_disconnect(
5220 adapter->dev, false,
5221 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005222 } else if (eConnectionState_Connecting == connState) {
5223 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005224 * Indicate connect failure to supplicant if we
5225 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005226 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305227 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305228 NULL, 0, NULL, 0,
5229 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005230 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231 }
5232
5233 hdd_register_tx_flow_control(adapter,
5234 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005235 hdd_tx_resume_cb,
5236 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005237
5238 break;
5239
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005240 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005241 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305242 hdd_init_ap_mode(adapter, true);
5243
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244 break;
5245
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005246 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005247#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005248 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5250#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005251 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252 /* event supplicant to restart */
5253 cfg80211_del_sta(adapter->dev,
5254 (const u8 *)&bcastMac.bytes[0],
5255 GFP_KERNEL);
5256#endif
5257 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305258 case QDF_MONITOR_MODE:
5259 hdd_init_station_mode(adapter);
5260 hdd_set_mon_rx_cb(adapter->dev);
5261 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5262 adapter->mon_bandwidth);
5263 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005264 default:
5265 break;
5266 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005267 /*
5268 * Action frame registered in one adapter which will
5269 * applicable to all interfaces
5270 */
5271 wlan_hdd_cfg80211_register_frames(adapter);
5272
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305273get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005274 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5275 adapterNode = pNext;
5276 }
5277
5278 EXIT();
5279
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305280 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005281}
5282
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005283QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284 hdd_adapter_list_node_t **padapterNode)
5285{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305286 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005287
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005288 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305289 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5290 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005291 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005292 return status;
5293}
5294
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005295QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005296 hdd_adapter_list_node_t *adapterNode,
5297 hdd_adapter_list_node_t **pNextAdapterNode)
5298{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305299 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005300
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005301 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305302 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5303 (qdf_list_node_t *) adapterNode,
5304 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005306 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005307 return status;
5308}
5309
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005310QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005311 hdd_adapter_list_node_t *adapterNode)
5312{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305313 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005314
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005315 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305316 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005317 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005318 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319 return status;
5320}
5321
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005322QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005323 hdd_adapter_list_node_t **padapterNode)
5324{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305325 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005326
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005327 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305328 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5329 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005330 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005331 return status;
5332}
5333
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005334QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005335 hdd_adapter_list_node_t *adapterNode)
5336{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305337 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005338
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005339 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305340 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5341 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005342 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005343 return status;
5344}
5345
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005346QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005347 hdd_adapter_list_node_t *adapterNode)
5348{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305349 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005350
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005351 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305352 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5353 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005354 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355 return status;
5356}
5357
Jeff Johnson9d295242017-08-29 14:39:48 -07005358struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005359 tSirMacAddr macAddr)
5360{
5361 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005362 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305363 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005364
5365 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5366
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305367 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005368 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005369
5370 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305371 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005372 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005373 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005374
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005375 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5376 adapterNode = pNext;
5377 }
5378
5379 return NULL;
5380
5381}
5382
Jeff Johnson9d295242017-08-29 14:39:48 -07005383struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005384 uint32_t vdev_id)
5385{
5386 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005387 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305388 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005389
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305390 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005391
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305392 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005393 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005394
5395 if (adapter->sessionId == vdev_id)
5396 return adapter;
5397
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305398 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005399 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5400 adapterNode = pNext;
5401 }
5402
Jeff Johnson5880d792016-08-15 13:32:30 -07005403 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005404
5405 return NULL;
5406}
5407
Abhishek Singh7996eb72015-12-30 17:24:02 +05305408/**
5409 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5410 * the sessionid
5411 * @hdd_ctx: hdd context.
5412 * @sme_session_id: sme session is for the adapter to get.
5413 *
5414 * This function is used to get the adapter with provided session id
5415 *
5416 * Return: adapter pointer if found
5417 *
5418 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005419struct hdd_adapter *
5420hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5421 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305422{
5423 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005424 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305425 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305426
5427
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305428 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305429
5430 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305431 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005432 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305433
5434 if (adapter &&
5435 adapter->sessionId == sme_session_id)
5436 return adapter;
5437
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305438 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305439 hdd_get_next_adapter(hdd_ctx,
5440 adapter_node, &next);
5441 adapter_node = next;
5442 }
5443 return NULL;
5444}
5445
Jeff Johnson9d295242017-08-29 14:39:48 -07005446struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005447 const char *iface_name)
5448{
5449 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005450 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005451 QDF_STATUS qdf_status;
5452
5453 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5454
5455 while ((NULL != adapter_node) &&
5456 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005457 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005458
5459 if (adapter &&
5460 !qdf_str_cmp(adapter->dev->name, iface_name))
5461 return adapter;
5462
5463 qdf_status =
5464 hdd_get_next_adapter(hdd_ctx,
5465 adapter_node, &next);
5466 adapter_node = next;
5467 }
5468 return NULL;
5469}
5470
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005471/**
5472 * hdd_get_adapter() - to get adapter matching the mode
5473 * @hdd_ctx: hdd context
5474 * @mode: adapter mode
5475 *
5476 * This routine will return the pointer to adapter matching
5477 * with the passed mode.
5478 *
5479 * Return: pointer to adapter or null
5480 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005481struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005482 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005483{
5484 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005485 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305486 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005487
5488 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5489
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305490 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005491 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005492
5493 if (adapter && (mode == adapter->device_mode))
5494 return adapter;
5495
5496 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5497 adapterNode = pNext;
5498 }
5499
5500 return NULL;
5501
5502}
5503
5504/**
5505 * hdd_get_operating_channel() - return operating channel of the device mode
5506 * @hdd_ctx: Pointer to the HDD context.
5507 * @mode: Device mode for which operating channel is required.
5508 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005509 * QDF_STA_MODE,
5510 * QDF_P2P_CLIENT_MODE,
5511 * QDF_SAP_MODE,
5512 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005513 *
5514 * This API returns the operating channel of the requested device mode
5515 *
5516 * Return: channel number. "0" id the requested device is not found OR it is
5517 * not connected.
5518 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005519uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005520 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005521{
5522 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305523 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005524 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005525 uint8_t operatingChannel = 0;
5526
5527 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5528
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305529 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005530 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005531
5532 if (mode == adapter->device_mode) {
5533 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005534 case QDF_STA_MODE:
5535 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005536 if (hdd_conn_is_connected
5537 (WLAN_HDD_GET_STATION_CTX_PTR
5538 (adapter))) {
5539 operatingChannel =
5540 (WLAN_HDD_GET_STATION_CTX_PTR
5541 (adapter))->conn_info.
5542 operationChannel;
5543 }
5544 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005545 case QDF_SAP_MODE:
5546 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005547 /* softap connection info */
5548 if (test_bit
5549 (SOFTAP_BSS_STARTED,
5550 &adapter->event_flags))
5551 operatingChannel =
5552 (WLAN_HDD_GET_AP_CTX_PTR
5553 (adapter))->operatingChannel;
5554 break;
5555 default:
5556 break;
5557 }
5558
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005559 /* Found the device of interest. break the loop */
5560 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005561 }
5562
5563 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5564 adapterNode = pNext;
5565 }
5566 return operatingChannel;
5567}
5568
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005569static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005570 hdd_ctx)
5571{
5572 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305573 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005574 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005575
5576 ENTER();
5577
5578 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5579
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305580 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005581 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005582 if ((adapter->device_mode == QDF_STA_MODE) ||
5583 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5584 (adapter->device_mode == QDF_IBSS_MODE) ||
5585 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5586 (adapter->device_mode == QDF_SAP_MODE) ||
5587 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005588 wlan_hdd_cfg80211_deregister_frames(adapter);
5589 hdd_unregister_wext(adapter->dev);
5590 }
5591 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5592 adapterNode = pNext;
5593 }
5594
5595 EXIT();
5596
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305597 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598}
5599
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005600QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005601{
5602 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305603 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005604 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005605
5606 ENTER();
5607
5608 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5609
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305610 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005611 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005612 if ((adapter->device_mode == QDF_STA_MODE) ||
5613 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5614 (adapter->device_mode == QDF_IBSS_MODE) ||
5615 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5616 (adapter->device_mode == QDF_SAP_MODE) ||
5617 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005618 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5619 adapter->sessionId, INVALID_SCAN_ID,
5620 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005621 }
5622 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5623 adapterNode = pNext;
5624 }
5625
5626 EXIT();
5627
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305628 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005629}
5630
Dustin Brownf27bce82016-11-03 12:52:27 -07005631/**
5632 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5633 * adapters
5634 * @hdd_ctx: The HDD context containing the adapters to operate on
5635 *
5636 * return: QDF_STATUS_SUCCESS
5637 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005638static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005639{
5640 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5641 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005642 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005643 int err;
5644
5645 ENTER();
5646
5647 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5648
5649 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005650 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005651 if ((adapter->device_mode == QDF_STA_MODE) ||
5652 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5653 (adapter->device_mode == QDF_IBSS_MODE) ||
5654 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5655 (adapter->device_mode == QDF_SAP_MODE) ||
5656 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5657 err = wlan_hdd_sched_scan_stop(adapter->dev);
5658 if (err)
5659 hdd_err("Unable to stop scheduled scan");
5660 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005661 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5662 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005663 adapter_node = next_node;
5664 }
5665
5666 EXIT();
5667
5668 return QDF_STATUS_SUCCESS;
5669}
5670
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671#ifdef WLAN_NS_OFFLOAD
5672/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005673 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005674 * @hdd_ctx: Pointer to hdd context
5675 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005676 * Unregister for IPv6 address change notifications.
5677 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005678 * Return: None
5679 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005680static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681{
5682 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005683}
5684
5685/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005686 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005687 * @hdd_ctx: Pointer to hdd context
5688 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005689 * Register for IPv6 address change notifications.
5690 *
5691 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005692 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005693static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005694{
5695 int ret;
5696
5697 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5698 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005699 if (ret) {
5700 hdd_err("Failed to register IPv6 notifier: %d", ret);
5701 goto out;
5702 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005704 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005705out:
5706 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005707}
5708#else
5709/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005710 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005711 * @hdd_ctx: Pointer to hdd context
5712 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005713 * Unregister for IPv6 address change notifications.
5714 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715 * Return: None
5716 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005717static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005718{
5719}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005720
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005721/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005722 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005723 * @hdd_ctx: Pointer to hdd context
5724 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005725 * Register for IPv6 address change notifications.
5726 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005727 * Return: None
5728 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005729static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005730{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005731 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005732}
5733#endif
5734
5735/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005736 * hdd_register_notifiers - Register netdev notifiers.
5737 * @hdd_ctx: HDD context
5738 *
5739 * Register netdev notifiers like IPv4 and IPv6.
5740 *
5741 * Return: 0 on success and errno on failure
5742 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005743static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005744{
5745 int ret;
5746
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005747 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5748 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305749 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005750
5751 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5752 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5753 if (ret) {
5754 hdd_err("Failed to register IPv4 notifier: %d", ret);
5755 goto unregister_ip6_notifier;
5756 }
5757
5758 return 0;
5759
5760unregister_ip6_notifier:
5761 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005762out:
5763 return ret;
5764
5765}
5766
5767/**
5768 * hdd_unregister_notifiers - Unregister netdev notifiers.
5769 * @hdd_ctx: HDD context
5770 *
5771 * Unregister netdev notifiers like IPv4 and IPv6.
5772 *
5773 * Return: None.
5774 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005775void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005776{
5777 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5778
5779 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005780}
5781
5782/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005783 * hdd_exit_netlink_services - Exit netlink services
5784 * @hdd_ctx: HDD context
5785 *
5786 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5787 * nl service.
5788 *
5789 * Return: None.
5790 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005791static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005792{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005793 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005794 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005795 ptt_sock_deactivate_svc();
5796
5797 nl_srv_exit();
5798}
5799
5800/**
5801 * hdd_init_netlink_services- Init netlink services
5802 * @hdd_ctx: HDD context
5803 *
5804 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5805 * nl service.
5806 *
5807 * Return: 0 on success and errno on failure.
5808 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005809static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005810{
5811 int ret;
5812
Ryan Hsuceddceb2016-04-28 10:20:14 -07005813 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005814 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005815 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005816 goto out;
5817 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005818 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005819
Naveen Rawat910726a2017-03-06 11:42:51 -08005820 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005821 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005822 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005823 goto err_nl_srv;
5824 }
5825
5826 ret = ptt_sock_activate_svc();
5827 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005828 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005829 goto err_nl_srv;
5830 }
5831
5832 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005833 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005834 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005835
5836 ret = cnss_diag_activate_service();
5837 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005838 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005839 goto err_close_cesium;
5840 }
5841
5842 return 0;
5843
5844err_close_cesium:
5845 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005846 ptt_sock_deactivate_svc();
5847err_nl_srv:
5848 nl_srv_exit();
5849out:
5850 return ret;
5851}
5852
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005853/**
5854 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5855 * @hdd_ctx: HDD context.
5856 *
5857 * Destroy RX wakelock.
5858 *
5859 * Return: None.
5860 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005861static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005862{
5863 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5864}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005865
5866/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005867 * hdd_rx_wake_lock_create() - Create RX wakelock
5868 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005869 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005870 * Create RX wakelock.
5871 *
5872 * Return: None.
5873 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005874static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005875{
5876 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5877}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005878
5879/**
Houston Hoffman160db392016-10-10 17:37:51 -07005880 * hdd_context_deinit() - Deinitialize HDD context
5881 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005882 *
Houston Hoffman160db392016-10-10 17:37:51 -07005883 * Deinitialize HDD context along with all the feature specific contexts but
5884 * do not free hdd context itself. Caller of this API is supposed to free
5885 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005886 *
Houston Hoffman160db392016-10-10 17:37:51 -07005887 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005888 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005889static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005890{
Houston Hoffman160db392016-10-10 17:37:51 -07005891 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005892
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005893 hdd_sap_context_destroy(hdd_ctx);
5894
5895 hdd_rx_wake_lock_destroy(hdd_ctx);
5896
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005897 hdd_scan_context_destroy(hdd_ctx);
5898
5899 qdf_list_destroy(&hdd_ctx->hddAdapters);
5900
Houston Hoffman160db392016-10-10 17:37:51 -07005901 return 0;
5902}
5903
5904/**
5905 * hdd_context_destroy() - Destroy HDD context
5906 * @hdd_ctx: HDD context to be destroyed.
5907 *
5908 * Free config and HDD context as well as destroy all the resources.
5909 *
5910 * Return: None
5911 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005912static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005913{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005914 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305915
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305916 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5917
Houston Hoffman160db392016-10-10 17:37:51 -07005918 hdd_context_deinit(hdd_ctx);
5919
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305920 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005921 hdd_ctx->config = NULL;
5922
5923 wiphy_free(hdd_ctx->wiphy);
5924}
5925
5926/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305927 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5928 *
5929 * This function is used to destroy bug report lock
5930 *
5931 * Return: None
5932 */
5933static void wlan_destroy_bug_report_lock(void)
5934{
5935 p_cds_contextType p_cds_context;
5936
5937 p_cds_context = cds_get_global_context();
5938 if (!p_cds_context) {
5939 hdd_err("cds context is NULL");
5940 return;
5941 }
5942
5943 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5944}
5945
5946/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005947 * hdd_wlan_exit() - HDD WLAN exit function
5948 * @hdd_ctx: Pointer to the HDD Context
5949 *
5950 * This is the driver exit point (invoked during rmmod)
5951 *
5952 * Return: None
5953 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005954static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005955{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305956 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005957 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305958 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005959
5960 ENTER();
5961
Arun Khandavallifae92942016-08-01 13:31:08 +05305962 if (QDF_TIMER_STATE_RUNNING ==
5963 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005964 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305965 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005966 }
5967
Arun Khandavallifae92942016-08-01 13:31:08 +05305968 if (!QDF_IS_STATUS_SUCCESS
5969 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5970 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005971
Arun Khandavallifae92942016-08-01 13:31:08 +05305972
5973 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005974
Prashanth Bhattaab004382016-10-11 16:08:11 -07005975 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005976
5977#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305978 if (QDF_TIMER_STATE_RUNNING ==
5979 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5980 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005981 }
5982
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305983 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305984 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005985 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005986 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005987 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5988 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5989 hdd_ctx->last_acs_channel_list = NULL;
5990 hdd_ctx->num_of_channels = 0;
5991 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005992#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005993
Arun Khandavallifae92942016-08-01 13:31:08 +05305994 mutex_lock(&hdd_ctx->iface_change_lock);
5995 driver_status = hdd_ctx->driver_status;
5996 mutex_unlock(&hdd_ctx->iface_change_lock);
5997
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005998 /*
5999 * Powersave Offload Case
6000 * Disable Idle Power Save Mode
6001 */
6002 hdd_set_idle_ps_config(hdd_ctx, false);
6003
Arun Khandavallifae92942016-08-01 13:31:08 +05306004 if (driver_status != DRIVER_MODULES_CLOSED) {
6005 hdd_unregister_wext_all_adapters(hdd_ctx);
6006 /*
6007 * Cancel any outstanding scan requests. We are about to close
6008 * all of our adapters, but an adapter structure is what SME
6009 * passes back to our callback function. Hence if there
6010 * are any outstanding scan requests then there is a
6011 * race condition between when the adapter is closed and
6012 * when the callback is invoked. We try to resolve that
6013 * race condition here by canceling any outstanding scans
6014 * before we close the adapters.
6015 * Note that the scans may be cancelled in an asynchronous
6016 * manner, so ideally there needs to be some kind of
6017 * synchronization. Rather than introduce a new
6018 * synchronization here, we will utilize the fact that we are
6019 * about to Request Full Power, and since that is synchronized,
6020 * the expectation is that by the time Request Full Power has
6021 * completed, all scans will be cancelled
6022 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07006023 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05306024 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006025 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006026 hdd_stop_all_adapters(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006027 }
6028
6029 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306030 * Close the scheduler before calling cds_close to make sure
6031 * no thread is scheduled after the each module close is
6032 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006033 */
Jeff Johnson7d562272017-09-13 15:12:54 -07006034 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306035 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05306036 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306037 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006038 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006039
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306040 unregister_netdevice_notifier(&hdd_netdev_notifier);
6041
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006042 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306043
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306044 qdf_nbuf_deinit_replenish_timer();
6045
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306046 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6047 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6048 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6049
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006050 /*
6051 * Close CDS
6052 * This frees pMac(HAL) context. There should not be any call
6053 * that requires pMac access after this.
6054 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006055
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006056 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006057 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006058
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006059 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006060
6061 hdd_ipa_cleanup(hdd_ctx);
6062
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306063 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306064 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306065 /*
6066 * If there is re_init failure wiphy would have already de-registered
6067 * check the wiphy status before un-registering again
6068 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306069 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306070 wiphy_unregister(wiphy);
6071 wlan_hdd_cfg80211_deinit(wiphy);
6072 hdd_lpass_notify_stop(hdd_ctx);
6073 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006074
Arun Khandavallifae92942016-08-01 13:31:08 +05306075 hdd_exit_netlink_services(hdd_ctx);
6076 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306077#ifdef FEATURE_WLAN_CH_AVOID
6078 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6079#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306080
6081 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6082 if (driver_status)
6083 hdd_err("Pdev delete failed");
6084
6085 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6086 if (driver_status)
6087 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006088
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006089 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006090}
6091
6092void __hdd_wlan_exit(void)
6093{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006094 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006095
6096 ENTER();
6097
Anurag Chouhan6d760662016-02-20 16:05:43 +05306098 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006099 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006100 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006101 EXIT();
6102 return;
6103 }
6104
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006105 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306106 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006107
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006108 /* Do all the cleanup before deregistering the driver */
6109 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006110
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006111 EXIT();
6112}
6113
6114#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006115/**
6116 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006117 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006118 *
6119 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6120 * Then new ACS request will do a fresh scan without reusing the cached
6121 * scan information.
6122 *
6123 * Return: void
6124 */
Tang Yingying523322d2017-01-17 23:28:43 +08006125static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006126{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006127 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006128
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006129 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006130 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006131 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6132 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6133 hdd_ctx->last_acs_channel_list = NULL;
6134 hdd_ctx->num_of_channels = 0;
6135 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006136
6137 if (!hdd_ctx->hHal)
6138 return;
6139 sme_scan_flush_result(hdd_ctx->hHal);
6140}
6141#endif
6142
6143#ifdef QCA_HT_2040_COEX
6144/**
6145 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
6146 * @adapter: pointer to adapter
6147 * @staId: station id
6148 * @macAddrSTA: station MAC address
6149 * @channel_type: channel type
6150 *
6151 * This function notifies FW with HT20/HT40 mode
6152 *
6153 * Return: 0 if successful, error number otherwise
6154 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006155int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05306156 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006157{
6158 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306159 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006160 struct hdd_context *hdd_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006161
6162 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6163
6164 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306165 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006166 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306167
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006168 if (!hdd_ctx->hHal)
6169 return -EINVAL;
6170
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306171 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006172 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306173 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006174 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006175 return -EINVAL;
6176 }
6177
6178 return 0;
6179}
6180#endif
6181
6182/**
6183 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6184 * @state: state
6185 *
6186 * This function notifies FW with modem power status
6187 *
6188 * Return: 0 if successful, error number otherwise
6189 */
6190int hdd_wlan_notify_modem_power_state(int state)
6191{
6192 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306193 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006194 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006195
Anurag Chouhan6d760662016-02-20 16:05:43 +05306196 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006197 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306198 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006199 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306200
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006201 if (!hdd_ctx->hHal)
6202 return -EINVAL;
6203
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306204 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6205 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006206 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006207 state);
6208 return -EINVAL;
6209 }
6210 return 0;
6211}
6212
6213/**
6214 *
6215 * hdd_post_cds_enable_config() - HDD post cds start config helper
6216 * @adapter - Pointer to the HDD
6217 *
6218 * Return: None
6219 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006220QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006221{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306222 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006223
6224 /*
6225 * Send ready indication to the HDD. This will kick off the MAC
6226 * into a 'running' state and should kick off an initial scan.
6227 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306228 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6229 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006230 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6231 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306232 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006233 }
6234
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306235 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006236}
6237
6238/* wake lock APIs for HDD */
6239void hdd_prevent_suspend(uint32_t reason)
6240{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306241 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006242}
6243
6244void hdd_allow_suspend(uint32_t reason)
6245{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306246 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006247}
6248
6249void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6250{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306251 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6252 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006253}
6254
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006255/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006256QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006257{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006258
Amar Singhal6f8592b2017-04-26 14:31:58 -07006259 return sme_init_chan_list(hdd_ctx->hHal,
6260 hdd_ctx->reg.alpha2,
6261 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006262}
6263
6264/**
6265 * hdd_is_5g_supported() - check if hardware supports 5GHz
6266 * @hdd_ctx: Pointer to the hdd context
6267 *
6268 * HDD function to know if hardware supports 5GHz
6269 *
6270 * Return: true if hardware supports 5GHz
6271 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006272bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006273{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006274 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006275 return true;
6276
Amar Singhal58b45ef2017-08-01 13:43:54 -07006277 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006278 return true;
6279 else
6280 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006281}
6282
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006283static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006284{
6285 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006286 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006287
6288 wiphy = hdd_ctx->wiphy;
6289
6290 /*
6291 * The channel information in
6292 * wiphy needs to be initialized before wiphy registration
6293 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006294 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6295 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006296 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006297 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006298 }
6299
6300#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6301 wiphy->wowlan = &wowlan_support_reg_init;
6302#else
6303 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6304 WIPHY_WOWLAN_MAGIC_PKT |
6305 WIPHY_WOWLAN_DISCONNECT |
6306 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6307 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6308 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6309 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6310 WIPHY_WOWLAN_RFKILL_RELEASE;
6311
6312 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6313 WOW_MAX_FILTERS_PER_LIST);
6314 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6315 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6316#endif
6317
6318 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006319 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306320 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006321 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306322 return ret_val;
6323 }
6324
Amar Singhal5cccafe2017-02-15 12:42:58 -08006325 if (!hdd_ctx->reg_offload)
6326 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006327
Amar Singhale4f28ee2015-10-21 14:36:56 -07006328 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006329}
6330
Ravi Joshie2331e82015-07-01 18:18:54 -07006331/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006332 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006333 * @hdd_ctx - handle to hdd context
6334 * @tx_packets - transmit packet count
6335 * @rx_packets - receive packet count
6336 *
6337 * The function controls the bus bandwidth and dynamic control of
6338 * tcp delayed ack configuration
6339 *
6340 * Returns: None
6341 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006342#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006343static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006344 const uint64_t tx_packets,
6345 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006347 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006348 uint64_t temp_rx = 0;
6349 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006350 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006351 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006352 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006353 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006354 uint16_t index = 0;
6355 bool vote_level_change = false;
6356 bool rx_level_change = false;
6357 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006358
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006359 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006360 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006361 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006362 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006363 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006364 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006365 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006366 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006367
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006368 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006369 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6370 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006371 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006372 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006373 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306374 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306375 if (hdd_ctx->hbw_requested) {
6376 pld_remove_pm_qos(hdd_ctx->parent_dev);
6377 hdd_ctx->hbw_requested = false;
6378 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306379 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006380 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006381 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306382 if (!hdd_ctx->hbw_requested) {
6383 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6384 hdd_ctx->hbw_requested = true;
6385 }
6386
Nirav Shah3bbfa512016-05-12 16:43:49 +05306387 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006388 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006389 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006390 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006391 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006392
Mohit Khannaf8f96822017-05-17 17:11:59 -07006393 qdf_dp_trace_throttle_live_mode(
6394 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6395
Mohit Khannae71e2262015-11-10 09:37:24 -08006396 /* fine-tuning parameters for RX Flows */
6397 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6398
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006399 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006400
Ravi Joshifed83572016-10-07 16:20:37 -07006401 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6402 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6403 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6404 next_rx_level = WLAN_SVC_TP_HIGH;
6405 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006406 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006407 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006408 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006409 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006411 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006412 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006413 next_rx_level, temp_rx);
6414 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006415 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006416 /* Send throughput indication only if it is enabled.
6417 * Disabling tcp_del_ack will revert the tcp stack behavior
6418 * to default delayed ack. Note that this will disable the
6419 * dynamic delayed ack mechanism across the system
6420 */
6421 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306422 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6423 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006424 &next_rx_level,
6425 sizeof(next_rx_level));
6426 }
6427
Mohit Khannae71e2262015-11-10 09:37:24 -08006428 /* fine-tuning parameters for TX Flows */
6429 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6430 hdd_ctx->prev_tx = tx_packets;
6431 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6432 next_tx_level = WLAN_SVC_TP_HIGH;
6433 else
6434 next_tx_level = WLAN_SVC_TP_LOW;
6435
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006436 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006437 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6438 next_tx_level, temp_tx);
6439 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006440 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306441 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6442 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006443 &next_tx_level,
6444 sizeof(next_tx_level));
6445 }
6446
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006447 index = hdd_ctx->hdd_txrx_hist_idx;
6448
6449 if (vote_level_change || tx_level_change || rx_level_change) {
6450 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6451 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6452 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6453 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6454 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6455 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6456 hdd_ctx->hdd_txrx_hist_idx++;
6457 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6458 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006459}
6460
6461#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306462static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006463{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006464 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306465 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006466 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306467 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306468 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6469 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006470 uint64_t total_tx = 0, total_rx = 0;
6471 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306472 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306473 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006474 bool connected = false;
6475 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6476
Prashanth Bhattaab004382016-10-11 16:08:11 -07006477 if (wlan_hdd_validate_context(hdd_ctx))
6478 return;
6479
Jingxiang Gec64e1932017-08-22 14:38:59 +08006480 if (hdd_ctx->isWiphySuspended)
6481 goto restart_timer;
6482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006483 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306484 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006485 status =
6486 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6487
Jeff Johnson57eb2732017-10-02 11:40:20 -07006488 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006489 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006490 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306491 /*
6492 * Validate magic so we don't end up accessing
6493 * an invalid adapter.
6494 */
6495 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6496 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006497
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006498 if ((adapter->device_mode == QDF_STA_MODE ||
6499 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006500 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6501 != eConnectionState_Associated) {
6502
6503 continue;
6504 }
6505
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006506 if ((adapter->device_mode == QDF_SAP_MODE ||
6507 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006508 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6509
6510 continue;
6511 }
6512
6513 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6514 adapter->prev_tx_packets);
6515 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6516 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306517
6518 if (adapter->device_mode == QDF_SAP_MODE ||
6519 adapter->device_mode == QDF_P2P_GO_MODE ||
6520 adapter->device_mode == QDF_IBSS_MODE) {
6521
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006522 ret = cdp_get_intra_bss_fwd_pkts_count(
6523 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306524 adapter->sessionId,
6525 &fwd_tx_packets, &fwd_rx_packets);
6526 if (ret == A_OK) {
6527 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6528 fwd_tx_packets,
6529 adapter->prev_fwd_tx_packets);
6530 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6531 fwd_tx_packets,
6532 adapter->prev_fwd_rx_packets);
6533 }
6534 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006535
6536 total_rx += adapter->stats.rx_packets;
6537 total_tx += adapter->stats.tx_packets;
6538
6539 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6540 adapter->prev_tx_packets = adapter->stats.tx_packets;
6541 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306542 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6543 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006544 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6545 connected = true;
6546 }
6547
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306548 /* add intra bss forwarded tx and rx packets */
6549 tx_packets += fwd_tx_packets_diff;
6550 rx_packets += fwd_rx_packets_diff;
6551
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006552 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6553 tx_packets += (uint64_t)ipa_tx_packets;
6554 rx_packets += (uint64_t)ipa_rx_packets;
6555
Yun Park2aa880c2017-08-22 10:58:10 -07006556 if (adapter) {
6557 adapter->stats.tx_packets += ipa_tx_packets;
6558 adapter->stats.rx_packets += ipa_rx_packets;
6559 }
6560
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006561 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006562 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006563 return;
6564 }
6565
Yuanyuan Liu13738502016-04-06 17:41:37 -07006566 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006567
6568 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6569 hdd_ipa_uc_stat_request(adapter, 2);
6570
Jingxiang Gec64e1932017-08-22 14:38:59 +08006571restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006572 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006573 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006574 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306575 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006576 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006577 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006578}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006579
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306580/**
6581 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6582 * @arg: Argument of timer function
6583 *
6584 * Schedule a workqueue in this function where all the processing is done.
6585 *
6586 * Return: None.
6587 */
6588static void __hdd_bus_bw_cbk(void *arg)
6589{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006590 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306591
6592 if (wlan_hdd_validate_context(hdd_ctx))
6593 return;
6594
6595 schedule_work(&hdd_ctx->bus_bw_work);
6596}
6597
6598/**
6599 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6600 * @arg: Argument of timer function
6601 *
6602 * Return: None.
6603 */
6604static void hdd_bus_bw_cbk(void *arg)
6605{
6606 cds_ssr_protect(__func__);
6607 __hdd_bus_bw_cbk(arg);
6608 cds_ssr_unprotect(__func__);
6609}
6610
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006611int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006612{
6613 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306614 INIT_WORK(&hdd_ctx->bus_bw_work,
6615 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006616 hdd_ctx->bus_bw_timer_running = false;
6617 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306618 qdf_timer_init(NULL,
6619 &hdd_ctx->bus_bw_timer,
6620 hdd_bus_bw_cbk, (void *)hdd_ctx,
6621 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006622
6623 return 0;
6624}
6625
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006626void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006627{
Dustin Brownfce08d12017-01-17 16:29:38 -08006628 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006629 hdd_reset_tcp_delack(hdd_ctx);
6630
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006631 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306632 cancel_work_sync(&hdd_ctx->bus_bw_work);
6633 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006634 hdd_ctx->bus_bw_timer_running = false;
6635 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006636}
Lin Baic5c06882017-09-21 13:58:43 +08006637
6638void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6639{
6640 if (hdd_ctx)
6641 cancel_work_sync(&hdd_ctx->bus_bw_work);
6642}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006643#endif
6644
6645/**
Nirav Shahed34b212016-04-25 10:59:16 +05306646 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6647 * @hdd_ctx: hdd context
6648 *
6649 * Return: 0 for success or error code
6650 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006651static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306652{
6653 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6654 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6655 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006656 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306657 return -ENOMEM;
6658 }
6659 return 0;
6660}
6661
6662/**
6663 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6664 * @hdd_ctx: hdd context
6665 *
6666 * Return: none
6667 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006668void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306669{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306670 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6671 return;
6672
6673 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6674 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306675}
6676
Nirav Shahda008342016-05-17 18:50:40 +05306677static uint8_t *convert_level_to_string(uint32_t level)
6678{
6679 switch (level) {
6680 /* initialize the wlan sub system */
6681 case WLAN_SVC_TP_NONE:
6682 return "NONE";
6683 case WLAN_SVC_TP_LOW:
6684 return "LOW";
6685 case WLAN_SVC_TP_MEDIUM:
6686 return "MED";
6687 case WLAN_SVC_TP_HIGH:
6688 return "HIGH";
6689 default:
6690 return "INVAL";
6691 }
6692}
6693
Nirav Shahed34b212016-04-25 10:59:16 +05306694
6695/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006696 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6697 * @hdd_ctx: hdd context
6698 *
6699 * Return: none
6700 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006701void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006702{
6703 int i;
6704
6705#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006706 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306707 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006708 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006709 hdd_ctx->config->busBandwidthHighThreshold,
6710 hdd_ctx->config->busBandwidthMediumThreshold,
6711 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006712 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306713 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006714 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006715 hdd_ctx->config->tcpDelackThresholdHigh,
6716 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006717 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306718 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006719#endif
6720
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006721 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306722 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6723
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006724 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006725
6726 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006727 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006728 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006729 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006730 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6731 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006732 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006733 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6734 convert_level_to_string(
6735 hdd_ctx->hdd_txrx_hist[i].
6736 next_vote_level),
6737 convert_level_to_string(
6738 hdd_ctx->hdd_txrx_hist[i].
6739 next_rx_level),
6740 convert_level_to_string(
6741 hdd_ctx->hdd_txrx_hist[i].
6742 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006743 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006744}
6745
6746/**
6747 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6748 * @hdd_ctx: hdd context
6749 *
6750 * Return: none
6751 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006752void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006753{
6754 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306755 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6756 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006757}
6758
6759/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006760 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006761 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006762 *
6763 * Return: none
6764 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006765void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766{
6767
Jeff Johnson9d295242017-08-29 14:39:48 -07006768 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006769 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306770 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006771 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306772 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006773
6774 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306775 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006776 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006777
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006778 hdd_debug("Netif queue operation statistics:");
6779 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306780 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006781 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306782 curr_time = qdf_system_ticks();
6783 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306784 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306785 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306786 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306787 unpause = adapter->total_unpause_time;
6788 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306789 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306790 pause = adapter->total_pause_time;
6791 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006792 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306793 qdf_system_ticks_to_msecs(total),
6794 qdf_system_ticks_to_msecs(pause),
6795 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006796 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006797
Nirav Shahda008342016-05-17 18:50:40 +05306798 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6799 qdf_time_t pause_delta = 0;
6800
6801 if (adapter->pause_map & (1 << i))
6802 pause_delta = delta;
6803
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006804 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006805 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006806 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807 hdd_reason_type_to_string(i),
6808 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306809 adapter->queue_oper_stats[i].unpause_count,
6810 qdf_system_ticks_to_msecs(
6811 adapter->queue_oper_stats[i].total_pause_time +
6812 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006813 }
6814
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006815 hdd_debug("Netif queue operation history:");
6816 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306817 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6818
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006819 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006820
6821 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006822 /* using hdd_log to avoid printing function name */
6823 if (adapter->queue_oper_history[i].time == 0)
6824 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006825 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006826 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306827 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006828 adapter->queue_oper_history[i].time),
6829 hdd_action_type_to_string(
6830 adapter->queue_oper_history[i].netif_action),
6831 hdd_reason_type_to_string(
6832 adapter->queue_oper_history[i].netif_reason),
6833 adapter->queue_oper_history[i].pause_map);
6834 }
6835
6836 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6837 adapter_node = next;
6838 }
6839
6840
6841}
6842
6843/**
6844 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6845 * @hdd_ctx: hdd context
6846 *
6847 * Return: none
6848 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006849void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006850{
Jeff Johnson9d295242017-08-29 14:39:48 -07006851 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006852 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306853 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006854
6855 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306856 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006857 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006858
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306859 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006860 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306861 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306863 adapter->history_index = 0;
6864 adapter->start_time = adapter->last_time = qdf_system_ticks();
6865 adapter->total_pause_time = 0;
6866 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006867 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6868 adapter_node = next;
6869 }
6870}
6871
6872/**
6873 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6874 * @halHandle: Hal handle
6875 * @pContext: Pointer to the context
6876 * @sessionId: Session ID
6877 * @scanId: Scan ID
6878 * @status: Status
6879 *
6880 * This is the callback to be executed when 11d scan is completed to flush out
6881 * the scan results
6882 *
6883 * 11d scan is done during driver load and is a passive scan on all
6884 * channels supported by the device, 11d scans may find some APs on
6885 * frequencies which are forbidden to be used in the regulatory domain
6886 * the device is operating in. If these APs are notified to the supplicant
6887 * it may try to connect to these APs, thus flush out all the scan results
6888 * which are present in SME after 11d scan is done.
6889 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306890 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006891 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306892static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006893 uint8_t sessionId, uint32_t scanId,
6894 eCsrScanStatus status)
6895{
6896 ENTER();
6897
6898 sme_scan_flush_result(halHandle);
6899
6900 EXIT();
6901
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306902 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006903}
6904
6905#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6906/**
6907 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6908 * @hdd_ctx: hdd global context
6909 *
6910 * Return: none
6911 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006912static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006913{
6914 uint8_t i;
6915
6916 mutex_init(&hdd_ctx->op_ctx.op_lock);
6917 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6918 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6919 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6920 }
6921}
6922#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006923static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006924{
6925}
6926#endif
6927
Yingying Tang95409972016-10-20 15:16:15 +08006928#ifdef WLAN_FEATURE_WOW_PULSE
6929/**
6930 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006931 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006932 * @enable: enable or disable this behaviour
6933 *
6934 * Return: int
6935 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006936static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006937{
6938 struct hdd_config *pcfg_ini = phddctx->config;
6939 struct wow_pulse_mode wow_pulse_set_info;
6940 QDF_STATUS status;
6941
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006942 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006943
6944 if (false == phddctx->config->wow_pulse_support)
6945 return 0;
6946
6947 /* prepare the request to send to SME */
6948 if (enable == true) {
6949 wow_pulse_set_info.wow_pulse_enable = true;
6950 wow_pulse_set_info.wow_pulse_pin =
6951 pcfg_ini->wow_pulse_pin;
6952 wow_pulse_set_info.wow_pulse_interval_low =
6953 pcfg_ini->wow_pulse_interval_low;
6954 wow_pulse_set_info.wow_pulse_interval_high =
6955 pcfg_ini->wow_pulse_interval_high;
6956 } else {
6957 wow_pulse_set_info.wow_pulse_enable = false;
6958 wow_pulse_set_info.wow_pulse_pin = 0;
6959 wow_pulse_set_info.wow_pulse_interval_low = 0;
6960 wow_pulse_set_info.wow_pulse_interval_high = 0;
6961 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006962 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006963 wow_pulse_set_info.wow_pulse_enable,
6964 wow_pulse_set_info.wow_pulse_pin,
6965 wow_pulse_set_info.wow_pulse_interval_low,
6966 wow_pulse_set_info.wow_pulse_interval_high);
6967
6968 status = sme_set_wow_pulse(&wow_pulse_set_info);
6969 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006970 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006971 return -EIO;
6972 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006973 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006974 return 0;
6975}
6976#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006977static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006978{
6979 return 0;
6980}
6981#endif
6982
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006983#ifdef WLAN_FEATURE_FASTPATH
6984/**
6985 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6986 * @hdd_cfg: hdd config
6987 * @context: lower layer context
6988 *
6989 * Return: none
6990 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306991void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006992 void *context)
6993{
6994 if (hdd_cfg->fastpath_enable)
6995 hif_enable_fastpath(context);
6996}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006997#endif
6998
Yuanyuan Liu13738502016-04-06 17:41:37 -07006999#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007000/**
7001 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007002 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007003 * @level: thermal level
7004 *
7005 * Change IPA data path to SW path when the thermal throttle level greater
7006 * than 0, and restore the original data path when throttle level is 0
7007 *
7008 * Return: none
7009 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007010static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007011{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007012 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007013
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007014 /* Change IPA to SW path when throttle level greater than 0 */
7015 if (level > THROTTLE_LEVEL_0)
7016 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7017 else
7018 /* restore original concurrency mode */
7019 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7020}
7021
7022/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307023 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7024 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307025 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007026 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307027 * Get a safe channel to restart SAP. PCL already takes into account the
7028 * unsafe channels. So, the PCL is validated with the ACS range to provide
7029 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007030 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307031 * Return: Channel number to restart SAP in case of success. In case of any
7032 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007033 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307034static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007035 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007036{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307037 struct sir_pcl_list pcl;
7038 QDF_STATUS status;
7039 uint32_t i, j;
7040 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007041 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307042 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007043
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307044 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7045 if (!hdd_ctx) {
7046 hdd_err("invalid HDD context");
7047 return INVALID_CHANNEL_ID;
7048 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007049
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307050 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7051 if (!hal_handle) {
7052 hdd_err("invalid HAL handle");
7053 return INVALID_CHANNEL_ID;
7054 }
7055
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007056 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7057 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007058 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7059 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307060 if (QDF_IS_STATUS_ERROR(status)) {
7061 hdd_err("Get PCL failed");
7062 return INVALID_CHANNEL_ID;
7063 }
7064
Frank Liudc2cefb2017-06-21 15:38:18 +08007065 /*
7066 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7067 * channel is unsafe channel, the pcl may be empty, instead of return,
7068 * try to choose a safe channel from acs range.
7069 */
7070 if (!pcl.pcl_len)
7071 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307072
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007073 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307074 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7075 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7076
7077 /* PCL already takes unsafe channel into account */
7078 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007079 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307080 if ((pcl.pcl_list[i] >=
7081 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7082 (pcl.pcl_list[i] <=
7083 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007084 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307085 return pcl.pcl_list[i];
7086 }
7087 }
7088
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007089 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307090
7091 /* Try for safe channel from all valid channel */
7092 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007093 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307094 &pcl.pcl_len);
7095 if (QDF_IS_STATUS_ERROR(status)) {
7096 hdd_err("error in getting valid channel list");
7097 return INVALID_CHANNEL_ID;
7098 }
7099
7100 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007101 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307102 found = false;
7103 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007104 if (pcl.pcl_list[i] ==
7105 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007106 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307107 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007108 break;
7109 }
7110 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307111
7112 if (found)
7113 continue;
7114
7115 if ((pcl.pcl_list[i] >=
7116 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7117 (pcl.pcl_list[i] <=
7118 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007119 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307120 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007121 }
7122 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307123
7124 return INVALID_CHANNEL_ID;
7125}
7126
7127/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007128 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307129 * @adapter: AP adapter
7130 * @channel: Channel
7131 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007132 * Moves the SAP interface by invoking the function which
7133 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307134 *
7135 * Return: None
7136 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007137void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307138{
Jeff Johnson87251032017-08-29 13:31:11 -07007139 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307140 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007141 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307142
7143 if (!adapter) {
7144 hdd_err("invalid adapter");
7145 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007146 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307147
7148 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7149
7150 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7151 if (!hal_handle) {
7152 hdd_err("invalid HAL handle");
7153 return;
7154 }
7155
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007156 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7157
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307158 hdd_ap_ctx->sapConfig.channel = channel;
7159 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7160 hdd_ap_ctx->sapConfig.ch_width_orig;
7161
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007162 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307163 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7164
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007165 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7166 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307167 hdd_ap_ctx->sapConfig.sec_ch,
7168 &hdd_ap_ctx->sapConfig.ch_params);
7169
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007170 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7171 adapter->sessionId, channel,
7172 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007173}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307174
Jeff Johnson9d295242017-08-29 14:39:48 -07007175int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307176{
7177 struct hdd_external_acs_timer_context *timer_context;
7178
7179 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7180
7181 if (QDF_TIMER_STATE_RUNNING ==
7182 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7183 ap.vendor_acs_timer)) {
7184 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7185 }
7186 timer_context = (struct hdd_external_acs_timer_context *)
7187 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7188 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307189 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307190 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307191 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7192 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307193 hdd_notice("Updated ACS config to nl with reason %d", reason);
7194
7195 return 0;
7196}
7197
Agrawal Ashish467dde42016-09-08 18:44:22 +05307198/**
7199 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7200 * @hdd_ctx: hdd context pointer
7201 *
7202 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7203 * and if ACS is enabled, driver will ask userspace to restart the
7204 * sap. User space on LTE coex indication restart driver.
7205 *
7206 * Return - none
7207 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007208void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307209{
7210 QDF_STATUS status;
7211 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007212 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307213 uint32_t i;
7214 bool found = false;
7215 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007216
Agrawal Ashish467dde42016-09-08 18:44:22 +05307217 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7218 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007219 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307220
7221 if (!adapter_temp) {
7222 hdd_err("adapter is NULL, moving to next one");
7223 goto next_adapater;
7224 }
7225
7226 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7227 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007228 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307229 adapter_temp->device_mode,
7230 adapter_temp->sessionCtx.ap.sapConfig.
7231 acs_cfg.acs_mode);
7232 goto next_adapater;
7233 }
7234
7235 found = false;
7236 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007237 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307238 hdd_ctxt->unsafe_channel_list[i]) {
7239 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007240 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307241 adapter_temp->sessionCtx.ap.operatingChannel);
7242 break;
7243 }
7244 }
7245
7246 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007247 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307248 adapter_temp->sessionCtx.ap.operatingChannel);
7249 goto next_adapater;
7250 }
7251
Kapil Gupta8878ad92017-02-13 11:56:04 +05307252 if (hdd_ctxt->config->vendor_acs_support &&
7253 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7254 hdd_update_acs_timer_reason(adapter_temp,
7255 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7256 goto next_adapater;
7257 } else
7258 restart_chan =
7259 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307260 adapter_temp);
7261 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007262 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307263 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007264 /*
7265 * SAP restart due to unsafe channel. While
7266 * restarting the SAP, make sure to clear
7267 * acs_channel, channel to reset to
7268 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307269 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007270 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307271 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7272 adapter_temp->sessionCtx.ap.sapConfig.channel =
7273 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007274 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307275 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7276 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007277 hdd_debug("driver to start sap: %d",
7278 hdd_ctxt->config->sap_internal_restart);
7279 if (hdd_ctxt->config->sap_internal_restart)
7280 hdd_switch_sap_channel(adapter_temp, restart_chan);
7281 else
7282 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307283 }
7284
7285next_adapater:
7286 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7287 adapter_node = next;
7288 }
7289}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307290
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007291/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007292 * hdd_init_channel_avoidance() - Initialize channel avoidance
7293 * @hdd_ctx: HDD global context
7294 *
7295 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007296 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007297 * down to the lower layers. Then subscribe to subsequent channel
7298 * avoidance events.
7299 *
7300 * Return: None
7301 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007302static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007303{
7304 uint16_t unsafe_channel_count;
7305 int index;
7306
Yuanyuan Liu13738502016-04-06 17:41:37 -07007307 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7308 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007309 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007310 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007311
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007312 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007313 hdd_ctx->unsafe_channel_count);
7314
Anurag Chouhan6d760662016-02-20 16:05:43 +05307315 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007316 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007317
7318 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007319 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007320 hdd_ctx->unsafe_channel_list[index]);
7321
7322 }
7323
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007324}
Dustin Brown676a2322017-08-15 13:16:13 -07007325
Jeff Johnson9d295242017-08-29 14:39:48 -07007326static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007327 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007328{
7329 uint8_t restart_chan;
7330
7331 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7332 if (!restart_chan) {
7333 hdd_alert("fail to restart SAP");
7334 return;
7335 }
7336
7337 /* SAP restart due to unsafe channel. While restarting
7338 * the SAP, make sure to clear acs_channel, channel to
7339 * reset to 0. Otherwise these settings will override
7340 * the ACS while restart.
7341 */
7342 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7343 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7344
7345 hdd_debug("sending coex indication");
7346
7347 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7348 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7349 hdd_switch_sap_channel(adapter, restart_chan);
7350}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007351
7352int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7353 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7354{
7355 uint32_t size;
7356 uint16_t *unsafe_list;
7357 uint16_t chan_count;
7358
7359 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7360 return -EINVAL;
7361
7362 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7363 NUM_CHANNELS);
7364 if (chan_count) {
7365 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7366 unsafe_list = qdf_mem_malloc(size);
7367 if (!unsafe_list) {
7368 hdd_err("No memory for unsafe chan list size%d",
7369 size);
7370 return -ENOMEM;
7371 }
7372 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7373 } else {
7374 unsafe_list = NULL;
7375 }
7376
7377 *local_unsafe_list = unsafe_list;
7378 *local_unsafe_list_count = chan_count;
7379
7380 return 0;
7381}
7382
7383bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7384 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7385{
7386 int i, j;
7387
7388 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7389 return true;
7390 if (local_unsafe_list_count == 0)
7391 return false;
7392 for (i = 0; i < local_unsafe_list_count; i++) {
7393 for (j = 0; j < local_unsafe_list_count; j++)
7394 if (local_unsafe_list[i] ==
7395 hdd_ctx->unsafe_channel_list[j])
7396 break;
7397 if (j >= local_unsafe_list_count)
7398 break;
7399 }
7400 if (i >= local_unsafe_list_count) {
7401 hdd_info("unsafe chan list same");
7402 return false;
7403 }
7404
7405 return true;
7406}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007407#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007408static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007409{
7410}
Dustin Brown676a2322017-08-15 13:16:13 -07007411
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007412static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007413{
7414}
Dustin Brown676a2322017-08-15 13:16:13 -07007415
Jeff Johnson9d295242017-08-29 14:39:48 -07007416static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007417 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007418{
7419 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7420}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007421#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007422
7423/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007424 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7425 * user space
7426 * @frame_ind: Management frame data to be informed.
7427 *
7428 * This function is used to indicate management frame to
7429 * user space
7430 *
7431 * Return: None
7432 *
7433 */
7434void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7435{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007436 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007437 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007438 int i;
7439
Rajeev Kumard004abc2016-02-17 12:09:56 -08007440 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007441 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007442
7443 if (0 != wlan_hdd_validate_context(hdd_ctx))
7444 return;
7445
7446 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7447 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7448 adapter =
7449 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7450 if (adapter)
7451 break;
7452 }
7453 } else {
7454 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7455 frame_ind->sessionId);
7456 }
7457
7458 if ((NULL != adapter) &&
7459 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7460 __hdd_indicate_mgmt_frame(adapter,
7461 frame_ind->frame_len,
7462 frame_ind->frameBuf,
7463 frame_ind->frameType,
7464 frame_ind->rxChan,
7465 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007466}
7467
Kapil Gupta8878ad92017-02-13 11:56:04 +05307468void hdd_acs_response_timeout_handler(void *context)
7469{
7470 struct hdd_external_acs_timer_context *timer_context =
7471 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007472 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007473 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307474 uint8_t reason;
7475
7476 ENTER();
7477 if (!timer_context) {
7478 hdd_err("invlaid timer context");
7479 return;
7480 }
7481 adapter = timer_context->adapter;
7482 reason = timer_context->reason;
7483
7484
7485 if ((!adapter) ||
7486 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7487 hdd_err("invalid adapter or adapter has invalid magic");
7488 return;
7489 }
7490 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7491 if (wlan_hdd_validate_context(hdd_ctx))
7492 return;
7493
7494 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7495 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7496 else
7497 return;
7498
7499 hdd_err("ACS timeout happened for %s reason %d",
7500 adapter->dev->name, reason);
7501 switch (reason) {
7502 /* SAP init case */
7503 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7504 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7505 false);
7506 wlan_hdd_cfg80211_start_acs(adapter);
7507 break;
7508 /* DFS detected on current channel */
7509 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7510 wlan_sap_update_next_channel(
7511 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7512 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7513 adapter->sessionId);
7514 break;
7515 /* LTE coex event on current channel */
7516 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7517 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7518 break;
7519 default:
7520 hdd_info("invalid reason for timer invoke");
7521
7522 }
7523}
7524
Rajeev Kumard004abc2016-02-17 12:09:56 -08007525/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007526 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7527 * @hdd_ctx: HDD context
7528 *
7529 * Disables all the dual mac features like DBS, Agile DFS etc.
7530 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307531 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007532 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007533static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007534{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007535 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307536 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007537
7538 if (!hdd_ctx) {
7539 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307540 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007541 }
7542
7543 cfg.scan_config = 0;
7544 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007545 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007546
7547 hdd_debug("Disabling all dual mac features...");
7548
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007549 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307550 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007551 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7552 return status;
7553 }
7554
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307555 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007556}
7557
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007558static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007559wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007560{
7561 struct policy_mgr_dual_mac_config cfg = {0};
7562 QDF_STATUS status;
7563
7564 if (!hdd_ctx) {
7565 hdd_err("HDD context is NULL");
7566 return QDF_STATUS_E_FAILURE;
7567 }
7568
7569 cfg.scan_config = 0;
7570 cfg.fw_mode_config = 0;
7571 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7572 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7573 hdd_ctx->hdd_psoc, &cfg.scan_config,
7574 &cfg.fw_mode_config,
7575 hdd_ctx->config->dual_mac_feature_disable);
7576
7577 if (status != QDF_STATUS_SUCCESS) {
7578 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7579 status);
7580 return status;
7581 }
7582
7583 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7584 cfg.scan_config, cfg.fw_mode_config);
7585
7586 status = sme_soc_set_dual_mac_config(cfg);
7587 if (status != QDF_STATUS_SUCCESS) {
7588 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7589 return status;
7590 }
7591
7592 return QDF_STATUS_SUCCESS;
7593}
7594
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007595/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007596 * hdd_override_ini_config - Override INI config
7597 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007598 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007599 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007600 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007601 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007602 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007603static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007604{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007605
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007606 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7607 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007608 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007609 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007610 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007611 if (0 == enable_11d || 1 == enable_11d) {
7612 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007613 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007614 }
Leo Chang11545d62016-10-17 14:53:50 -07007615
7616 if (!hdd_ipa_is_present(hdd_ctx))
7617 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007618}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007619
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007620/**
7621 * hdd_set_trace_level_for_each - Set trace level for each INI config
7622 * @hdd_ctx - HDD context
7623 *
7624 * Set trace level for each module based on INI config.
7625 *
7626 * Return: None
7627 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007628static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007629{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307630 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7631 hdd_ctx->config->qdf_trace_enable_wdi);
7632 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7633 hdd_ctx->config->qdf_trace_enable_hdd);
7634 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7635 hdd_ctx->config->qdf_trace_enable_sme);
7636 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7637 hdd_ctx->config->qdf_trace_enable_pe);
7638 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7639 hdd_ctx->config->qdf_trace_enable_wma);
7640 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7641 hdd_ctx->config->qdf_trace_enable_sys);
7642 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7643 hdd_ctx->config->qdf_trace_enable_qdf);
7644 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7645 hdd_ctx->config->qdf_trace_enable_sap);
7646 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7647 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7648 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7649 hdd_ctx->config->qdf_trace_enable_bmi);
7650 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7651 hdd_ctx->config->qdf_trace_enable_cfg);
7652 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7653 hdd_ctx->config->qdf_trace_enable_epping);
7654 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7655 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7656 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007657 hdd_ctx->config->qdf_trace_enable_txrx);
7658 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7659 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307660 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7661 hdd_ctx->config->qdf_trace_enable_htc);
7662 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7663 hdd_ctx->config->qdf_trace_enable_hif);
7664 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7665 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7666 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7667 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007668 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7669 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007670 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7671 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007672 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7673 hdd_ctx->config->qdf_trace_enable_regulatory);
7674
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007675 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007676}
7677
7678/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007679 * hdd_context_init() - Initialize HDD context
7680 * @hdd_ctx: HDD context.
7681 *
7682 * Initialize HDD context along with all the feature specific contexts.
7683 *
7684 * return: 0 on success and errno on failure.
7685 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007686static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007687{
7688 int ret;
7689
7690 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7691 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7692
7693 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307694 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007695
7696 init_completion(&hdd_ctx->mc_sus_event_var);
7697 init_completion(&hdd_ctx->ready_to_suspend);
7698
7699 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307700 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007701 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307702
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007703 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7704
7705 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7706
7707 ret = hdd_scan_context_init(hdd_ctx);
7708 if (ret)
7709 goto list_destroy;
7710
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007711 hdd_rx_wake_lock_create(hdd_ctx);
7712
7713 ret = hdd_sap_context_init(hdd_ctx);
7714 if (ret)
7715 goto scan_destroy;
7716
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007717 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7718
7719 hdd_init_offloaded_packets_ctx(hdd_ctx);
7720
7721 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7722 hdd_ctx->config);
7723 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08007724 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007725
7726 return 0;
7727
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007728sap_destroy:
7729 hdd_sap_context_destroy(hdd_ctx);
7730
7731scan_destroy:
7732 hdd_scan_context_destroy(hdd_ctx);
7733 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007734list_destroy:
7735 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007736
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007737 return ret;
7738}
7739
7740/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307741 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7742 * @hdd_ctx: pointer to hdd context
7743 *
7744 * Return: status of initialization
7745 * 0 - success
7746 * negative value - failure
7747 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007748static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307749{
7750 int ret;
7751
7752 if (!hdd_ctx->config->probe_req_ie_whitelist)
7753 return 0;
7754
7755 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7756 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7757 hdd_ctx->config->probe_req_ie_whitelist = false;
7758 return -EINVAL;
7759 }
7760
7761 /* parse ini string probe req oui */
7762 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7763 if (ret) {
7764 hdd_err("parsing error: disable ie whitelisting");
7765 hdd_ctx->config->probe_req_ie_whitelist = false;
7766 }
7767
7768 return ret;
7769}
7770
7771/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007772 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307773 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007774 *
7775 * Allocate and initialize HDD context. HDD context is allocated as part of
7776 * wiphy allocation and then context is initialized.
7777 *
7778 * Return: HDD context on success and ERR_PTR on failure
7779 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007780static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007781{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307782 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007783 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007784 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007785
7786 ENTER();
7787
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007788 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007789 if (hdd_ctx == NULL) {
7790 ret = -ENOMEM;
7791 goto err_out;
7792 }
7793
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007794 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307795 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007796
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307797 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007798 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007799 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007800 ret = -ENOMEM;
7801 goto err_free_hdd_context;
7802 }
7803
7804 /* Read and parse the qcom_cfg.ini file */
7805 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307806 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307807 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007808 WLAN_INI_FILE);
7809 ret = -EINVAL;
7810 goto err_free_config;
7811 }
7812
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307813 ie_whitelist_attrs_init(hdd_ctx);
7814
Dustin Brown7f939932017-05-18 15:02:17 -07007815 hdd_debug("setting timer multiplier: %u",
7816 hdd_ctx->config->timer_multiplier);
7817 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7818
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007819
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307820 if (hdd_ctx->config->fhostNSOffload)
7821 hdd_ctx->ns_offload_enable = true;
7822
Abhishek Singh5ea86532016-04-27 14:10:53 +05307823 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7824
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007825 hdd_override_ini_config(hdd_ctx);
7826
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007827 ret = hdd_context_init(hdd_ctx);
7828
7829 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007830 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007831
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007832 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307833 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007834
Anurag Chouhan6d760662016-02-20 16:05:43 +05307835 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007836 goto skip_multicast_logging;
7837
7838 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7839
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007840 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7841 if (ret)
7842 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307843
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007844 ret = hdd_init_netlink_services(hdd_ctx);
7845 if (ret)
7846 goto err_deinit_txrx_histogram;
7847
Dustin Brown7b3dea22017-07-10 13:02:47 -07007848 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7849 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307850
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007851skip_multicast_logging:
7852 hdd_set_trace_level_for_each(hdd_ctx);
7853
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007854 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7855
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007856 EXIT();
7857
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007858 return hdd_ctx;
7859
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007860err_deinit_txrx_histogram:
7861 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7862
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007863err_deinit_hdd_context:
7864 hdd_context_deinit(hdd_ctx);
7865
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007866err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307867 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007868
7869err_free_hdd_context:
7870 wiphy_free(hdd_ctx->wiphy);
7871
7872err_out:
7873 return ERR_PTR(ret);
7874}
7875
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007876#ifdef WLAN_OPEN_P2P_INTERFACE
7877/**
7878 * hdd_open_p2p_interface - Open P2P interface
7879 * @hdd_ctx: HDD context
7880 * @rtnl_held: True if RTNL lock held
7881 *
7882 * Open P2P interface during probe. This function called to open the P2P
7883 * interface at probe along with STA interface.
7884 *
7885 * Return: 0 on success and errno on failure
7886 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007887static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007888{
Jeff Johnson9d295242017-08-29 14:39:48 -07007889 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007890 uint8_t *p2p_dev_addr;
7891
7892 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7893 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307894 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007895 hdd_ctx->config->intfMacAddr[0].bytes,
7896 sizeof(tSirMacAddr));
7897
7898 /*
7899 * Generate the P2P Device Address. This consists of
7900 * the device's primary MAC address with the locally
7901 * administered bit set.
7902 */
7903 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7904 } else {
7905 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7906 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007907 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007908 return -ENOSPC;
7909 }
7910
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307911 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307912 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007913 }
7914
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007915 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007916 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007917 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007918
7919 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007920 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007921 return -ENOSPC;
7922 }
7923
7924 return 0;
7925}
7926#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007927static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007928 bool rtnl_held)
7929{
7930 return 0;
7931}
7932#endif
7933
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007934static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007935{
Jeff Johnson9d295242017-08-29 14:39:48 -07007936 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007937 int ret = 0;
7938
7939 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7940 wlan_hdd_get_intf_addr(hdd_ctx),
7941 NET_NAME_UNKNOWN, rtnl_held);
7942 if (adapter == NULL) {
7943 hdd_err("Failed to open 802.11p interface");
7944 ret = -ENOSPC;
7945 }
7946
7947 return ret;
7948}
7949
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007950/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307951 * hdd_start_station_adapter()- Start the Station Adapter
7952 * @adapter: HDD adapter
7953 *
7954 * This function initializes the adapter for the station mode.
7955 *
7956 * Return: 0 on success or errno on failure.
7957 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007958int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307959{
7960 QDF_STATUS status;
7961
7962 ENTER_DEV(adapter->dev);
7963
7964 status = hdd_init_station_mode(adapter);
7965
7966 if (QDF_STATUS_SUCCESS != status) {
7967 hdd_err("Error Initializing station mode: %d", status);
7968 return qdf_status_to_os_return(status);
7969 }
7970
Arun Khandavallifae92942016-08-01 13:31:08 +05307971 hdd_register_tx_flow_control(adapter,
7972 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007973 hdd_tx_resume_cb,
7974 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307975
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307976 EXIT();
7977 return 0;
7978}
7979
7980/**
7981 * hdd_start_ap_adapter()- Start AP Adapter
7982 * @adapter: HDD adapter
7983 *
7984 * This function initializes the adapter for the AP mode.
7985 *
7986 * Return: 0 on success errno on failure.
7987 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007988int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307989{
7990 QDF_STATUS status;
7991
7992 ENTER();
7993
Arun Khandavallicc544b32017-01-30 19:52:16 +05307994 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307995
7996 if (QDF_STATUS_SUCCESS != status) {
7997 hdd_err("Error Initializing the AP mode: %d", status);
7998 return qdf_status_to_os_return(status);
7999 }
8000
Arun Khandavallifae92942016-08-01 13:31:08 +05308001 hdd_register_tx_flow_control(adapter,
8002 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008003 hdd_softap_tx_resume_cb,
8004 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308005
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308006 EXIT();
8007 return 0;
8008}
8009
8010/**
8011 * hdd_start_ftm_adapter()- Start FTM adapter
8012 * @adapter: HDD adapter
8013 *
8014 * This function initializes the adapter for the FTM mode.
8015 *
8016 * Return: 0 on success or errno on failure.
8017 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008018int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308019{
8020 QDF_STATUS qdf_status;
8021
8022 ENTER_DEV(adapter->dev);
8023
8024 qdf_status = hdd_init_tx_rx(adapter);
8025
8026 if (QDF_STATUS_SUCCESS != qdf_status) {
8027 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8028 return qdf_status_to_os_return(qdf_status);
8029 }
8030
8031 return 0;
8032 EXIT();
8033}
8034
8035/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008036 * hdd_open_interfaces - Open all required interfaces
8037 * hdd_ctx: HDD context
8038 * rtnl_held: True if RTNL lock is held
8039 *
8040 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8041 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008042 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008043 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008044static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008045{
Jeff Johnson9d295242017-08-29 14:39:48 -07008046 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008047 int ret;
8048
Ravi Joshia307f632017-07-17 23:41:41 -07008049 /* open monitor mode adapter if con_mode is monitor mode */
8050 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8051 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8052 wlan_hdd_get_intf_addr(hdd_ctx),
8053 NET_NAME_UNKNOWN, rtnl_held);
8054 if (!adapter) {
8055 hdd_err("open adapter failed");
8056 return -ENOSPC;
8057 }
8058 return 0;
8059 }
8060
Jeff Johnson957bc272017-02-02 08:54:48 -08008061 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308062 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008063 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008064
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008065 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008066 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008067 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008068
8069 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008070 return -ENOSPC;
8071
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008072 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8073 adapter->fast_roaming_allowed = true;
8074
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008075 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8076 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008077 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008078
8079 /* Open 802.11p Interface */
8080 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008081 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8082 if (ret)
8083 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008084 }
8085
Jeff Johnson957bc272017-02-02 08:54:48 -08008086 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008087
Jeff Johnson957bc272017-02-02 08:54:48 -08008088err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008089 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008090 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008091}
8092
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008093/**
8094 * hdd_update_country_code - Update country code
8095 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008096 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008097 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008098 *
8099 * Return: 0 on success and errno on failure
8100 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008101static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008102{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008103 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008104 return 0;
8105
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008106 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008107}
8108
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308109#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8110/**
8111 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8112 * @cds_cfg: CDS Configuration
8113 * @hdd_ctx: Pointer to hdd context
8114 *
8115 * Return: none
8116 */
8117static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8118 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008119 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308120{
8121 cds_cfg->tx_flow_stop_queue_th =
8122 hdd_ctx->config->TxFlowStopQueueThreshold;
8123 cds_cfg->tx_flow_start_queue_offset =
8124 hdd_ctx->config->TxFlowStartQueueOffset;
8125}
8126#else
8127static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8128 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008129 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308130{
8131}
8132#endif
8133
8134#ifdef FEATURE_WLAN_RA_FILTERING
8135/**
8136 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8137 * @cds_cfg: CDS Configuration
8138 * @hdd_ctx: Pointer to hdd context
8139 *
8140 * Return: none
8141 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308142static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008143 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308144{
8145 cds_cfg->ra_ratelimit_interval =
8146 hdd_ctx->config->RArateLimitInterval;
8147 cds_cfg->is_ra_ratelimit_enabled =
8148 hdd_ctx->config->IsRArateLimitEnabled;
8149}
8150#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308151static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008152 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308153{
8154}
8155#endif
8156
8157/**
8158 * hdd_update_cds_config() - API to update cds configuration parameters
8159 * @hdd_ctx: HDD Context
8160 *
8161 * Return: 0 for Success, errno on failure
8162 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008163static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308164{
8165 struct cds_config_info *cds_cfg;
8166
8167 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8168 if (!cds_cfg) {
8169 hdd_err("failed to allocate cds config");
8170 return -ENOMEM;
8171 }
8172
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008173 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008174 if (!hdd_ctx->config->nMaxPsPoll ||
8175 !hdd_ctx->config->enablePowersaveOffload) {
8176 cds_cfg->powersave_offload_enabled =
8177 hdd_ctx->config->enablePowersaveOffload;
8178 } else {
8179 if ((hdd_ctx->config->enablePowersaveOffload ==
8180 PS_QPOWER_NODEEPSLEEP) ||
8181 (hdd_ctx->config->enablePowersaveOffload ==
8182 PS_LEGACY_NODEEPSLEEP))
8183 cds_cfg->powersave_offload_enabled =
8184 PS_LEGACY_NODEEPSLEEP;
8185 else
8186 cds_cfg->powersave_offload_enabled =
8187 PS_LEGACY_DEEPSLEEP;
8188 hdd_info("Qpower disabled in cds config, %d",
8189 cds_cfg->powersave_offload_enabled);
8190 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308191 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8192 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8193 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8194 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8195 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8196
8197 /* Here ol_ini_info is used to store ini status of arp offload
8198 * ns offload and others. Currently 1st bit is used for arp
8199 * off load and 2nd bit for ns offload currently, rest bits are unused
8200 */
8201 if (hdd_ctx->config->fhostArpOffload)
8202 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8203 if (hdd_ctx->config->fhostNSOffload)
8204 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8205
8206 /*
8207 * Copy the DFS Phyerr Filtering Offload status.
8208 * This parameter reflects the value of the
8209 * dfs_phyerr_filter_offload flag as set in the ini.
8210 */
8211 cds_cfg->dfs_phyerr_filter_offload =
8212 hdd_ctx->config->fDfsPhyerrFilterOffload;
8213 if (hdd_ctx->config->ssdp)
8214 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8215
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308216 cds_cfg->force_target_assert_enabled =
8217 hdd_ctx->config->crash_inject_enabled;
8218
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308219 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8220 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8221
8222 cds_cfg->ap_maxoffload_reorderbuffs =
8223 hdd_ctx->config->apMaxOffloadReorderBuffs;
8224
8225 cds_cfg->ap_disable_intrabss_fwd =
8226 hdd_ctx->config->apDisableIntraBssFwd;
8227
8228 cds_cfg->dfs_pri_multiplier =
8229 hdd_ctx->config->dfsRadarPriMultiplier;
8230 cds_cfg->reorder_offload =
8231 hdd_ctx->config->reorderOffloadSupport;
8232
8233 /* IPA micro controller data path offload resource config item */
8234 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008235 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8236 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008237 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008238 hdd_ctx->config->IpaUcTxBufCount);
8239 hdd_ctx->config->IpaUcTxBufCount =
8240 rounddown_pow_of_two(
8241 hdd_ctx->config->IpaUcTxBufCount);
8242 if (!hdd_ctx->config->IpaUcTxBufCount) {
8243 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308244 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008245 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008246 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008247 hdd_ctx->config->IpaUcTxBufCount);
8248 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308249 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8250 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008251 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8252 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008253 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008254 hdd_ctx->config->IpaUcRxIndRingCount);
8255 hdd_ctx->config->IpaUcRxIndRingCount =
8256 rounddown_pow_of_two(
8257 hdd_ctx->config->IpaUcRxIndRingCount);
8258 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8259 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308260 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008261 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008262 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008263 hdd_ctx->config->IpaUcRxIndRingCount);
8264 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308265 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008266 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308267 cds_cfg->uc_tx_partition_base =
8268 hdd_ctx->config->IpaUcTxPartitionBase;
8269 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8270
8271 cds_cfg->ip_tcp_udp_checksum_offload =
8272 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308273 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308274 cds_cfg->ce_classify_enabled =
8275 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008276 cds_cfg->bpf_packet_filter_enable =
8277 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308278 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8279 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8280 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008281 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008282 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008283 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008284 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308285 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8286 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308287 cds_cfg->auto_power_save_fail_mode =
8288 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308289
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308290 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008291 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308292
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308293 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8294 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8295 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008296 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308297 cds_init_ini_config(cds_cfg);
8298 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308299
8300exit:
8301 qdf_mem_free(cds_cfg);
8302 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308303}
8304
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008305/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008306 * hdd_update_user_config() - API to update user configuration
8307 * parameters to obj mgr which are used by multiple components
8308 * @hdd_ctx: HDD Context
8309 *
8310 * Return: 0 for Success, errno on failure
8311 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008312static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008313{
8314 struct wlan_objmgr_psoc_user_config *user_config;
8315
8316 user_config = qdf_mem_malloc(sizeof(*user_config));
8317 if (user_config == NULL) {
8318 hdd_alert("Failed to alloc memory for user_config!");
8319 return -ENOMEM;
8320 }
8321
8322 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8323 user_config->dual_mac_feature_disable =
8324 hdd_ctx->config->dual_mac_feature_disable;
8325 user_config->indoor_channel_support =
8326 hdd_ctx->config->indoor_channel_support;
8327 user_config->is_11d_support_enabled =
8328 hdd_ctx->config->Is11dSupportEnabled;
8329 user_config->is_11h_support_enabled =
8330 hdd_ctx->config->Is11hSupportEnabled;
8331 user_config->optimize_chan_avoid_event =
8332 hdd_ctx->config->goptimize_chan_avoid_event;
8333 user_config->skip_dfs_chnl_in_p2p_search =
8334 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008335 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008336 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8337
8338 qdf_mem_free(user_config);
8339 return 0;
8340}
8341
8342/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008343 * hdd_init_thermal_info - Initialize thermal level
8344 * @hdd_ctx: HDD context
8345 *
8346 * Initialize thermal level at SME layer and set the thermal level callback
8347 * which would be called when a configured thermal threshold is hit.
8348 *
8349 * Return: 0 on success and errno on failure
8350 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008351static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008352{
8353 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308354 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008355
8356 thermal_param.smeThermalMgmtEnabled =
8357 hdd_ctx->config->thermalMitigationEnable;
8358 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8359
Poddar, Siddarth83905022016-04-16 17:56:08 -07008360 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8361 hdd_ctx->config->throttle_dutycycle_level0;
8362 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8363 hdd_ctx->config->throttle_dutycycle_level1;
8364 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8365 hdd_ctx->config->throttle_dutycycle_level2;
8366 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8367 hdd_ctx->config->throttle_dutycycle_level3;
8368
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008369 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8370 hdd_ctx->config->thermalTempMinLevel0;
8371 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8372 hdd_ctx->config->thermalTempMaxLevel0;
8373 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8374 hdd_ctx->config->thermalTempMinLevel1;
8375 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8376 hdd_ctx->config->thermalTempMaxLevel1;
8377 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8378 hdd_ctx->config->thermalTempMinLevel2;
8379 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8380 hdd_ctx->config->thermalTempMaxLevel2;
8381 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8382 hdd_ctx->config->thermalTempMinLevel3;
8383 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8384 hdd_ctx->config->thermalTempMaxLevel3;
8385
8386 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8387
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308388 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308389 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008390
8391 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8392 hdd_set_thermal_level_cb);
8393
8394 return 0;
8395
8396}
8397
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008398#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8399/**
8400 * hdd_hold_rtnl_lock - Hold RTNL lock
8401 *
8402 * Hold RTNL lock
8403 *
8404 * Return: True if held and false otherwise
8405 */
8406static inline bool hdd_hold_rtnl_lock(void)
8407{
8408 rtnl_lock();
8409 return true;
8410}
8411
8412/**
8413 * hdd_release_rtnl_lock - Release RTNL lock
8414 *
8415 * Release RTNL lock
8416 *
8417 * Return: None
8418 */
8419static inline void hdd_release_rtnl_lock(void)
8420{
8421 rtnl_unlock();
8422}
8423#else
8424static inline bool hdd_hold_rtnl_lock(void) { return false; }
8425static inline void hdd_release_rtnl_lock(void) { }
8426#endif
8427
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008428#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008429
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308430/* MAX iwpriv command support */
8431#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308432#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308433#define MAX_PKTLOG_SIZE 16
8434
8435/**
8436 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8437 * @hdd_ctx: hdd context
8438 * @set_value2: pktlog buffer size value
8439 *
8440 *
8441 * Return: 0 for success or error.
8442 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008443static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308444{
8445 struct sir_wifi_start_log start_log = { 0 };
8446 QDF_STATUS status;
8447
8448 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8449 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8450 start_log.ini_triggered = cds_is_packet_log_enabled();
8451 start_log.user_triggered = 1;
8452 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308453 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308454
8455 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8456 if (!QDF_IS_STATUS_SUCCESS(status)) {
8457 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8458 EXIT();
8459 return -EINVAL;
8460 }
8461
8462 return 0;
8463}
8464
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008465/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308466 * hdd_pktlog_clear_buff() - clear pktlog buffer
8467 * @hdd_ctx: hdd context
8468 *
8469 * Return: 0 for success or error.
8470 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008471static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308472{
8473 struct sir_wifi_start_log start_log;
8474 QDF_STATUS status;
8475
8476 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8477 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8478 start_log.ini_triggered = cds_is_packet_log_enabled();
8479 start_log.user_triggered = 1;
8480 start_log.size = 0;
8481 start_log.is_pktlog_buff_clear = true;
8482
8483 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8484 if (!QDF_IS_STATUS_SUCCESS(status)) {
8485 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8486 EXIT();
8487 return -EINVAL;
8488 }
8489
8490 return 0;
8491}
8492
8493
8494/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008495 * hdd_process_pktlog_command() - process pktlog command
8496 * @hdd_ctx: hdd context
8497 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308498 * @set_value2: pktlog buffer size value
8499 *
8500 * This function process pktlog command.
8501 * set_value2 only matters when set_value is 3 (set buff size)
8502 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008503 *
8504 * Return: 0 for success or error.
8505 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008506int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308507 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008508{
8509 int ret;
8510 bool enable;
8511 uint8_t user_triggered = 0;
8512
8513 ret = wlan_hdd_validate_context(hdd_ctx);
8514 if (0 != ret)
8515 return ret;
8516
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008517 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008518
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308519 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008520 hdd_err("invalid pktlog value %d", set_value);
8521 return -EINVAL;
8522 }
8523
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308524 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8525 if (set_value2 <= 0) {
8526 hdd_err("invalid pktlog size %d", set_value2);
8527 return -EINVAL;
8528 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8529 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8530 return -EINVAL;
8531 }
8532 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308533 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8534 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308535 }
8536
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008537 /*
8538 * set_value = 0 then disable packetlog
8539 * set_value = 1 enable packetlog forcefully
8540 * set_vlaue = 2 then disable packetlog if disabled through ini or
8541 * enable packetlog with AUTO type.
8542 */
8543 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8544 true : false;
8545
8546 if (1 == set_value) {
8547 enable = true;
8548 user_triggered = 1;
8549 }
8550
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308551 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008552}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008553
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008554/**
8555 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8556 * @hdd_ctx: HDD context
8557 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308558 * @user_triggered: triggered through iwpriv
8559 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008560 *
8561 * Return: 0 on success; error number otherwise
8562 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008563int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308564 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008565{
8566 struct sir_wifi_start_log start_log;
8567 QDF_STATUS status;
8568
8569 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8570 start_log.verbose_level =
8571 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008572 start_log.ini_triggered = cds_is_packet_log_enabled();
8573 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308574 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308575 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308576 /*
8577 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8578 * commands. Host uses this flag to decide whether to send pktlog
8579 * disable command to fw without sending pktlog enable command
8580 * previously. For eg, If vendor sends pktlog disable command without
8581 * sending pktlog enable command, then host discards the packet
8582 * but for iwpriv command, host will send it to fw.
8583 */
8584 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008585 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8586 if (!QDF_IS_STATUS_SUCCESS(status)) {
8587 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8588 EXIT();
8589 return -EINVAL;
8590 }
8591
8592 return 0;
8593}
8594#endif /* REMOVE_PKT_LOG */
8595
Komal Seelam92fff912016-03-24 11:51:41 +05308596/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008597 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8598 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308599 * @dev: Device Pointer
8600 * @num: Number of Valid Mac address
8601 *
8602 * Return: Pointer to MAC address buffer
8603 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008604static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8605 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308606{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008607 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308608}
Komal Seelam92fff912016-03-24 11:51:41 +05308609
8610/**
8611 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8612 * @hdd_ctx: HDD Context
8613 * @num: Number of random mac addresses needed
8614 *
8615 * Generate random addresses using bit manipulation on the base mac address
8616 *
8617 * Return: None
8618 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008619void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308620{
8621 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8622 uint32_t iter;
8623 struct hdd_config *ini = hdd_ctx->config;
8624 uint8_t *buf = NULL;
8625 uint8_t macaddr_b3, tmp_br3;
8626 uint8_t *src = ini->intfMacAddr[0].bytes;
8627
8628 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8629 buf = ini->intfMacAddr[iter].bytes;
8630 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8631 macaddr_b3 = buf[3];
8632 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8633 INTF_MACADDR_MASK;
8634 macaddr_b3 += tmp_br3;
8635 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8636 buf[0] |= 0x02;
8637 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008638 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308639 }
8640}
8641
8642/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008643 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308644 * @hdd_ctx: HDD Context
8645 *
8646 * API to get mac addresses from platform driver and update the driver
8647 * structures and configure FW with the base mac address.
8648 * Return: int
8649 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008650static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308651{
8652 uint32_t no_of_mac_addr, iter;
8653 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8654 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8655 uint8_t *addr, *buf;
8656 struct device *dev = hdd_ctx->parent_dev;
8657 struct hdd_config *ini = hdd_ctx->config;
8658 tSirMacAddr mac_addr;
8659 QDF_STATUS status;
8660
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008661 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308662
8663 if (no_of_mac_addr == 0 || !addr) {
8664 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8665 return -EINVAL;
8666 }
8667
8668 if (no_of_mac_addr > max_mac_addr)
8669 no_of_mac_addr = max_mac_addr;
8670
8671 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8672
8673 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8674 buf = ini->intfMacAddr[iter].bytes;
8675 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008676 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308677 }
8678
8679 status = sme_set_custom_mac_addr(mac_addr);
8680
8681 if (!QDF_IS_STATUS_SUCCESS(status))
8682 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008683
Komal Seelam92fff912016-03-24 11:51:41 +05308684 if (no_of_mac_addr < max_mac_addr)
8685 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8686 no_of_mac_addr);
8687 return 0;
8688}
8689
8690/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008691 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8692 * @hdd_ctx: HDD Context
8693 *
8694 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8695 * will generate its own MAC and update it to FW.
8696 *
8697 * Return: 0 for success
8698 * Non-zero error code for failure
8699 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008700static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008701{
8702 tSirMacAddr customMacAddr;
8703 QDF_STATUS status;
8704
8705 qdf_mem_copy(&customMacAddr,
8706 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8707 sizeof(tSirMacAddr));
8708 status = sme_set_custom_mac_addr(customMacAddr);
8709 if (!QDF_IS_STATUS_SUCCESS(status))
8710 return -EAGAIN;
8711 return 0;
8712}
8713
8714/**
Komal Seelam92fff912016-03-24 11:51:41 +05308715 * hdd_initialize_mac_address() - API to get wlan mac addresses
8716 * @hdd_ctx: HDD Context
8717 *
8718 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8719 * is provisioned with mac addresses, driver uses it, else it will use
8720 * wlan_mac.bin to update HW MAC addresses.
8721 *
8722 * Return: None
8723 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008724static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308725{
8726 QDF_STATUS status;
8727 int ret;
8728
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008729 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308730 if (ret == 0)
8731 return;
8732
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008733 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8734 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308735
8736 status = hdd_update_mac_config(hdd_ctx);
8737
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008738 if (QDF_IS_STATUS_SUCCESS(status))
8739 return;
8740
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008741 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8742 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008743
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008744 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008745 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008746 if (ret != 0) {
8747 hdd_err("MAC address out-of-sync, ret:%d", ret);
8748 QDF_ASSERT(ret);
8749 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008750 }
Komal Seelam92fff912016-03-24 11:51:41 +05308751}
8752
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008753static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008754{
8755 int vdev_id = 0;
8756 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8757 int value = hdd_ctx->config->smart_chainmask_enabled;
8758 int vpdev = PDEV_CMD;
8759 int ret;
8760
Naveen Rawat247a8682017-06-05 15:00:31 -07008761 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008762 if (ret)
8763 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8764
8765 return ret;
8766}
8767
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008768static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008769{
8770 int vdev_id = 0;
8771 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8772 int value = hdd_ctx->config->alternative_chainmask_enabled;
8773 int vpdev = PDEV_CMD;
8774 int ret;
8775
Naveen Rawat247a8682017-06-05 15:00:31 -07008776 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008777 if (ret)
8778 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8779 ret);
8780
8781 return ret;
8782}
8783
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008784static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008785{
8786 int vdev_id = 0;
8787 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8788 int value = hdd_ctx->config->ani_enabled;
8789 int vpdev = PDEV_CMD;
8790 int ret;
8791
Naveen Rawat247a8682017-06-05 15:00:31 -07008792 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008793 if (ret)
8794 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8795
8796 return ret;
8797}
8798
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008799/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008800 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8801 * @hdd_ctx: HDD context
8802 *
8803 * Pre configurations to be done at lower layer before calling cds enable.
8804 *
8805 * Return: 0 on success and errno on failure.
8806 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008807static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008808{
8809 int ret;
8810 QDF_STATUS status;
8811 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008812 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008813
Leo Changfdb45c32016-10-28 11:09:23 -07008814 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008815 /*
8816 * Set 802.11p config
8817 * TODO-OCB: This has been temporarily added here to ensure this
8818 * parameter is set in CSR when we init the channel list. This should
8819 * be removed once the 5.9 GHz channels are added to the regulatory
8820 * domain.
8821 */
8822 hdd_set_dot11p_config(hdd_ctx);
8823
8824 /*
8825 * Note that the cds_pre_enable() sequence triggers the cfg download.
8826 * The cfg download must occur before we update the SME config
8827 * since the SME config operation must access the cfg database
8828 */
8829 status = hdd_set_sme_config(hdd_ctx);
8830
8831 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008832 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008833 ret = qdf_status_to_os_return(status);
8834 goto out;
8835 }
8836
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008837 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8838 if (QDF_STATUS_SUCCESS != status) {
8839 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8840 ret = qdf_status_to_os_return(status);
8841 goto out;
8842 }
8843
Naveen Rawat247a8682017-06-05 15:00:31 -07008844 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008845 hdd_ctx->config->tx_chain_mask_1ss,
8846 PDEV_CMD);
8847 if (0 != ret) {
8848 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8849 goto out;
8850 }
8851
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008852 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8853 if (ret)
8854 goto out;
8855
8856 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8857 if (ret)
8858 goto out;
8859
Jeff Johnson12a744b2017-04-04 08:19:37 -07008860 ret = hdd_set_ani_enabled(hdd_ctx);
8861 if (ret)
8862 goto out;
8863
Naveen Rawat247a8682017-06-05 15:00:31 -07008864 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008865 hdd_ctx->config->arp_ac_category,
8866 PDEV_CMD);
8867 if (0 != ret) {
8868 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8869 hdd_ctx->config->arp_ac_category, ret);
8870 goto out;
8871 }
8872
8873
Prashanth Bhatta07998752016-04-28 12:35:33 -07008874 status = hdd_set_sme_chan_list(hdd_ctx);
8875 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008876 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008877 ret = qdf_status_to_os_return(status);
8878 goto out;
8879 }
8880
8881 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008882 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008883 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008884 ret = -EINVAL;
8885 goto out;
8886 }
8887
Prashanth Bhatta07998752016-04-28 12:35:33 -07008888 /*
8889 * Set the MAC Address Currently this is used by HAL to add self sta.
8890 * Remove this once self sta is added as part of session open.
8891 */
8892 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8893 hdd_ctx->config->intfMacAddr[0].bytes,
8894 sizeof(hdd_ctx->config->intfMacAddr[0]));
8895
8896 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8897 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8898 hal_status, hal_status);
8899 ret = -EINVAL;
8900 goto out;
8901 }
8902
8903 hdd_init_channel_avoidance(hdd_ctx);
8904
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308905 /* update enable sap mandatory chan list */
8906 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8907 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008908out:
8909 return ret;
8910}
8911
8912/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008913 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8914 * @context_ptr - hdd context pointer
8915 * @event_ptr - event structure pointer
8916 *
8917 * This is the p2p listen offload stop event handler, it sends vendor
8918 * event back to supplicant to notify the stop reason.
8919 *
8920 * Return: None
8921 */
8922static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8923 void *event_ptr)
8924{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008925 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008926 struct sir_p2p_lo_event *evt = event_ptr;
8927 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008928 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008929
8930 ENTER();
8931
8932 if (hdd_ctx == NULL) {
8933 hdd_err("Invalid HDD context pointer");
8934 return;
8935 }
8936
Peng Xu5c682812017-08-06 07:39:13 -07008937 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8938 if (!adapter) {
8939 hdd_err("Cannot find adapter by vdev_id = %d",
8940 evt->vdev_id);
8941 return;
8942 }
8943
Peng Xu8fdaa492016-06-22 10:20:47 -07008944 vendor_event =
8945 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008946 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008947 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8948 GFP_KERNEL);
8949
8950 if (!vendor_event) {
8951 hdd_err("cfg80211_vendor_event_alloc failed");
8952 return;
8953 }
8954
8955 if (nla_put_u32(vendor_event,
8956 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8957 evt->reason_code)) {
8958 hdd_err("nla put failed");
8959 kfree_skb(vendor_event);
8960 return;
8961 }
8962
8963 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008964 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8965 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008966}
8967
8968/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308969 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8970 * @hdd_ctx: HDD context
8971 *
8972 * This function sends the adaptive dwell time config configuration to the
8973 * firmware via WMA
8974 *
8975 * Return: 0 - success, < 0 - failure
8976 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008977static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308978{
8979 QDF_STATUS status;
8980 struct adaptive_dwelltime_params dwelltime_params;
8981
8982 dwelltime_params.is_enabled =
8983 hdd_ctx->config->adaptive_dwell_mode_enabled;
8984 dwelltime_params.dwelltime_mode =
8985 hdd_ctx->config->global_adapt_dwelltime_mode;
8986 dwelltime_params.lpf_weight =
8987 hdd_ctx->config->adapt_dwell_lpf_weight;
8988 dwelltime_params.passive_mon_intval =
8989 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8990 dwelltime_params.wifi_act_threshold =
8991 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8992
8993 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8994 &dwelltime_params);
8995
8996 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8997 if (!QDF_IS_STATUS_SUCCESS(status)) {
8998 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8999 return -EAGAIN;
9000 }
9001 return 0;
9002}
9003
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009004int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309005{
9006 QDF_STATUS status;
9007 struct wmi_dbs_scan_sel_params dbs_scan_params;
9008 uint32_t i = 0;
9009 uint8_t count = 0, numentries = 0;
9010 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9011 * CDS_DBS_SCAN_CLIENTS_MAX];
9012
9013 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009014 if (hdd_ctx->config->dual_mac_feature_disable ==
9015 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309016 return -EINVAL;
9017
9018 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9019 dbs_scan_config, &numentries,
9020 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9021 * CDS_DBS_SCAN_CLIENTS_MAX));
9022
9023 hdd_info("numentries %hu", numentries);
9024 if (!numentries) {
9025 hdd_info("Donot send scan_selection_config");
9026 return 0;
9027 }
9028
9029 /* hdd_set_fw_log_params */
9030 dbs_scan_params.num_clients = 0;
9031 while (count < (numentries - 2)) {
9032 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9033 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9034 dbs_scan_params.num_non_dbs_scans[i] =
9035 dbs_scan_config[count + 2];
9036 dbs_scan_params.num_clients++;
9037 hdd_debug("module:%d NDS:%d NNDS:%d",
9038 dbs_scan_params.module_id[i],
9039 dbs_scan_params.num_dbs_scans[i],
9040 dbs_scan_params.num_non_dbs_scans[i]);
9041 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9042 i++;
9043 }
9044
9045 dbs_scan_params.pdev_id = 0;
9046
9047 hdd_debug("clients:%d pdev:%d",
9048 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9049
9050 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9051 &dbs_scan_params);
9052 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9053 if (!QDF_IS_STATUS_SUCCESS(status)) {
9054 hdd_err("Failed to send DBS Scan selection configuration!");
9055 return -EAGAIN;
9056 }
9057 return 0;
9058}
9059
Arun Khandavallid4349a92016-07-25 11:10:43 +05309060#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9061/**
9062 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9063 * @hdd_ctx: HDD context
9064 *
9065 * Set auto shutdown callback to get indications from firmware to indicate
9066 * userspace to shutdown WLAN after a configured amount of inactivity.
9067 *
9068 * Return: 0 on success and errno on failure.
9069 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009070static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309071{
9072 QDF_STATUS status;
9073
9074 if (!hdd_ctx->config->WlanAutoShutdown)
9075 return 0;
9076
9077 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9078 wlan_hdd_auto_shutdown_cb);
9079 if (status != QDF_STATUS_SUCCESS)
9080 hdd_err("Auto shutdown feature could not be enabled: %d",
9081 status);
9082
9083 return qdf_status_to_os_return(status);
9084}
9085#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009086static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309087{
9088 return 0;
9089}
9090#endif
9091
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009092static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009093{
9094 QDF_STATUS status = QDF_STATUS_SUCCESS;
9095
9096 switch (hdd_ctx->config->dual_mac_feature_disable) {
9097 case DISABLE_DBS_CXN_AND_SCAN:
9098 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9099 if (status != QDF_STATUS_SUCCESS)
9100 hdd_err("Failed to disable dual mac features");
9101 break;
9102 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9103 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9104 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9105 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9106 if (status != QDF_STATUS_SUCCESS)
9107 hdd_err("Failed to set dbs scan and fw mode config");
9108 break;
9109 default:
9110 break;
9111 }
9112
9113 return status;
9114}
9115
Arun Khandavallid4349a92016-07-25 11:10:43 +05309116/**
9117 * hdd_features_init() - Init features
9118 * @hdd_ctx: HDD context
9119 * @adapter: Primary adapter context
9120 *
9121 * Initialize features and their feature context after WLAN firmware is up.
9122 *
9123 * Return: 0 on success and errno on failure.
9124 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009125static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309126{
9127 tSirTxPowerLimit hddtxlimit;
9128 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309129 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309130 int ret;
9131
9132 ENTER();
9133
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009134 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309135 if (ret) {
9136 hdd_err("Failed to update country code: %d", ret);
9137 goto out;
9138 }
9139
9140 /* FW capabilities received, Set the Dot11 mode */
9141 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009142 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9143 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309144
Arun Khandavallid4349a92016-07-25 11:10:43 +05309145
9146 if (hdd_ctx->config->fIsImpsEnabled)
9147 hdd_set_idle_ps_config(hdd_ctx, true);
9148 else
9149 hdd_set_idle_ps_config(hdd_ctx, false);
9150
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309151 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009152 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309153
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309154 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9155 hdd_warn("Error in setting Voltage Corner mode config to FW");
9156
Arun Khandavallid4349a92016-07-25 11:10:43 +05309157 if (hdd_lro_init(hdd_ctx))
9158 hdd_err("Unable to initialize LRO in fw");
9159
9160 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9161 hdd_err("Unable to send adaptive dwelltime setting to FW");
9162
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309163 if (hdd_dbs_scan_selection_init(hdd_ctx))
9164 hdd_err("Unable to send DBS scan selection setting to FW");
9165
Arun Khandavallid4349a92016-07-25 11:10:43 +05309166 ret = hdd_init_thermal_info(hdd_ctx);
9167 if (ret) {
9168 hdd_err("Error while initializing thermal information");
9169 goto deregister_frames;
9170 }
9171
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309172 if (cds_is_packet_log_enabled())
9173 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9174
Arun Khandavallid4349a92016-07-25 11:10:43 +05309175 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9176 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9177 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9178 if (!QDF_IS_STATUS_SUCCESS(status))
9179 hdd_err("Error setting txlimit in sme: %d", status);
9180
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009181 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309182
Arun Khandavallid4349a92016-07-25 11:10:43 +05309183 ret = hdd_register_cb(hdd_ctx);
9184 if (ret) {
9185 hdd_err("Failed to register HDD callbacks!");
9186 goto deregister_frames;
9187 }
9188
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009189 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9190 if (!QDF_IS_STATUS_SUCCESS(status)) {
9191 hdd_err("Failed to set dbs scan and fw mode cfg");
9192 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309193 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009194
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309195 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9196 status = sme_enable_disable_chanavoidind_event(
9197 hdd_ctx->hHal, 0);
9198 if (!QDF_IS_STATUS_SUCCESS(status)) {
9199 hdd_err("Failed to disable Chan Avoidance Indication");
9200 goto deregister_cb;
9201 }
9202 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309203
Manjeet Singha9cae432017-02-28 11:58:22 +05309204 if (hdd_ctx->config->enable_5g_band_pref) {
9205 band_pref_params.rssi_boost_threshold_5g =
9206 hdd_ctx->config->rssi_boost_threshold_5g;
9207 band_pref_params.rssi_boost_factor_5g =
9208 hdd_ctx->config->rssi_boost_factor_5g;
9209 band_pref_params.max_rssi_boost_5g =
9210 hdd_ctx->config->max_rssi_boost_5g;
9211 band_pref_params.rssi_penalize_threshold_5g =
9212 hdd_ctx->config->rssi_penalize_threshold_5g;
9213 band_pref_params.rssi_penalize_factor_5g =
9214 hdd_ctx->config->rssi_penalize_factor_5g;
9215 band_pref_params.max_rssi_penalize_5g =
9216 hdd_ctx->config->max_rssi_penalize_5g;
9217 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9218 }
9219
Arun Khandavallid4349a92016-07-25 11:10:43 +05309220 /* register P2P Listen Offload event callback */
9221 if (wma_is_p2p_lo_capable())
9222 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9223 wlan_hdd_p2p_lo_event_callback);
9224
9225 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9226
9227 if (ret)
9228 goto deregister_cb;
9229
9230 EXIT();
9231 return 0;
9232
9233deregister_cb:
9234 hdd_deregister_cb(hdd_ctx);
9235deregister_frames:
9236 wlan_hdd_cfg80211_deregister_frames(adapter);
9237out:
9238 return -EINVAL;
9239
9240}
9241
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009242/**
9243 * hdd_features_deinit() - Deinit features
9244 * @hdd_ctx: HDD context
9245 *
9246 * De-Initialize features and their feature context.
9247 *
9248 * Return: none.
9249 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009250static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009251{
9252 wlan_hdd_tsf_deinit(hdd_ctx);
9253}
9254
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309255/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009256 * hdd_register_bcn_cb() - register scan beacon callback
9257 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309258 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009259 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309260 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009261static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309262{
9263 QDF_STATUS status;
9264
9265 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9266 wlan_cfg80211_inform_bss_frame,
9267 SCAN_CB_TYPE_INFORM_BCN);
9268 if (!QDF_IS_STATUS_SUCCESS(status)) {
9269 hdd_err("failed with status code %08d [x%08x]",
9270 status, status);
9271 return status;
9272 }
9273
9274 return QDF_STATUS_SUCCESS;
9275}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309276
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309277/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309278 * hdd_configure_cds() - Configure cds modules
9279 * @hdd_ctx: HDD context
9280 * @adapter: Primary adapter context
9281 *
9282 * Enable Cds modules after WLAN firmware is up.
9283 *
9284 * Return: 0 on success and errno on failure.
9285 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009286int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309287{
9288 int ret;
9289 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309290 int set_value;
9291 uint32_t num_abg_tx_chains = 0;
9292 uint32_t num_11b_tx_chains = 0;
9293 uint32_t num_11ag_tx_chains = 0;
9294
9295 if (hdd_ctx->config->sifs_burst_duration) {
9296 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9297 hdd_ctx->config->sifs_burst_duration;
9298
9299 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9300 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9301 set_value, PDEV_CMD);
9302 }
9303
9304 if (hdd_ctx->config->is_force_1x1)
9305 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9306 1, PDEV_CMD);
9307 /* set chip power save failure detected callback */
9308 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9309 hdd_chip_pwr_save_fail_detected_cb);
9310
9311 if (hdd_ctx->config->max_mpdus_inampdu) {
9312 set_value = hdd_ctx->config->max_mpdus_inampdu;
9313 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9314 set_value, PDEV_CMD);
9315 }
9316
9317 if (hdd_ctx->config->enable_rts_sifsbursting) {
9318 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9319 sme_cli_set_command(0,
9320 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9321 set_value, PDEV_CMD);
9322 }
9323
9324 if (hdd_ctx->config->sap_get_peer_info) {
9325 set_value = hdd_ctx->config->sap_get_peer_info;
9326 sme_cli_set_command(0,
9327 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9328 set_value, PDEV_CMD);
9329 }
9330
9331 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9332 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9333 if (!hdd_ctx->config->enable2x2) {
9334 if (num_11b_tx_chains > 1)
9335 num_11b_tx_chains = 1;
9336 if (num_11ag_tx_chains > 1)
9337 num_11ag_tx_chains = 1;
9338 }
9339 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9340 num_11b_tx_chains);
9341 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9342 num_11ag_tx_chains);
9343 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9344 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309345
9346 ret = hdd_pre_enable_configure(hdd_ctx);
9347 if (ret) {
9348 hdd_err("Failed to pre-configure cds");
9349 goto out;
9350 }
9351
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009352 /* Always get latest IPA resources allocated from cds_open and configure
9353 * IPA module before configuring them to FW. Sequence required as crash
9354 * observed otherwise.
9355 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009356 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9357 hdd_err("Failed to setup pipes");
9358 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009359 }
9360
Arun Khandavallifae92942016-08-01 13:31:08 +05309361 /*
9362 * Start CDS which starts up the SME/MAC/HAL modules and everything
9363 * else
9364 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009365 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309366
9367 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009368 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309369 goto out;
9370 }
9371
9372 status = hdd_post_cds_enable_config(hdd_ctx);
9373 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009374 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009375 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309376 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309377 status = hdd_register_bcn_cb(hdd_ctx);
9378 if (!QDF_IS_STATUS_SUCCESS(status)) {
9379 hdd_alert("hdd_post_cds_enable_config failed");
9380 goto cds_disable;
9381 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309382
9383 ret = hdd_features_init(hdd_ctx, adapter);
9384 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009385 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309386
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309387 if (hdd_enable_egap(hdd_ctx))
9388 hdd_debug("enhance green ap is not enabled");
9389
Nachiket Kukadedd302662017-07-13 17:31:44 +05309390 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9391 hdd_debug("Failed to set wow pulse");
9392
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309393 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9394 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9395
Arun Khandavallifae92942016-08-01 13:31:08 +05309396 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009397
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009398cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009399 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009400
Arun Khandavallifae92942016-08-01 13:31:08 +05309401out:
9402 return -EINVAL;
9403}
9404
9405/**
9406 * hdd_deconfigure_cds() -De-Configure cds
9407 * @hdd_ctx: HDD context
9408 *
9409 * Deconfigure Cds modules before WLAN firmware is down.
9410 *
9411 * Return: 0 on success and errno on failure.
9412 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009413static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309414{
9415 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009416 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309417
9418 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009419
9420 /* De-init features */
9421 hdd_features_deinit(hdd_ctx);
9422
Arun Khandavallifae92942016-08-01 13:31:08 +05309423 /* De-register the SME callbacks */
9424 hdd_deregister_cb(hdd_ctx);
9425
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009426 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309427 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9428 hdd_err("Failed to Disable the CDS Modules! :%d",
9429 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009430 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309431 }
9432
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309433 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9434 hdd_err("Failed to disconnect pipes");
9435 ret = -EINVAL;
9436 }
9437
Arun Khandavallifae92942016-08-01 13:31:08 +05309438 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009439 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309440}
9441
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009442#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9443static void hdd_deregister_policy_manager_callback(
9444 struct wlan_objmgr_psoc *psoc)
9445{
9446 if (QDF_STATUS_SUCCESS !=
9447 policy_mgr_deregister_hdd_cb(psoc)) {
9448 hdd_err("HDD callback deregister with policy manager failed");
9449 }
9450}
9451#else
9452static void hdd_deregister_policy_manager_callback(
9453 struct wlan_objmgr_psoc *psoc)
9454{
9455}
9456#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309457
9458/**
9459 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9460 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009461 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309462 *
9463 * This function maintains the driver state machine it will be invoked from
9464 * exit, shutdown and con_mode change handler. Depending on the driver state
9465 * shall perform the stopping/closing of the modules.
9466 *
9467 * Return: 0 for success; non-zero for failure
9468 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009469int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309470{
9471 void *hif_ctx;
9472 qdf_device_t qdf_ctx;
9473 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309474 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009475 bool is_idle_stop = !cds_is_driver_unloading() &&
9476 !cds_is_driver_recovering();
9477 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309478
9479 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009480 hdd_alert("stop WLAN module: entering driver status=%d",
9481 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309482
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009483 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9484
Arun Khandavallifae92942016-08-01 13:31:08 +05309485 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9486 if (!qdf_ctx) {
9487 hdd_err("QDF device context NULL");
9488 return -EINVAL;
9489 }
9490
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309491 mutex_lock(&hdd_ctx->iface_change_lock);
9492 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309493
Dustin Brown70111822017-03-30 15:31:40 -07009494 active_threads = cds_return_external_threads_count();
9495 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009496 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009497 active_threads, hdd_ctx->isWiphySuspended);
9498
9499 cds_print_external_threads();
9500
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009501 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009502 mutex_unlock(&hdd_ctx->iface_change_lock);
9503 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009504 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309505 hdd_prevent_suspend_timeout(
9506 hdd_ctx->config->iface_change_wait_time,
9507 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009508 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009509 return 0;
9510 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009511 }
9512
Arun Khandavallifae92942016-08-01 13:31:08 +05309513 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9514
9515 switch (hdd_ctx->driver_status) {
9516 case DRIVER_MODULES_UNINITIALIZED:
9517 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309518 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309519 case DRIVER_MODULES_CLOSED:
9520 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309521 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309522 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309523 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309524 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009525 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309526 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309527 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309528 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009529 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309530 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9531 break;
9532 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009533 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309534 break;
9535 default:
9536 hdd_err("Trying to stop wlan in a wrong state: %d",
9537 hdd_ctx->driver_status);
9538 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309539 ret = -EINVAL;
9540 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309541 }
9542
Rajeev Kumarbe021242017-02-16 16:12:23 -08009543 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309544 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9545 hdd_err("Failed to process post CDS disable Modules! :%d",
9546 qdf_status);
9547 ret = -EINVAL;
9548 QDF_ASSERT(0);
9549 }
Jeff Johnsone4b14592017-09-13 14:23:33 -07009550 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309551 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009552 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309553 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309554 QDF_ASSERT(0);
9555 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009556
Arun Khandavallifae92942016-08-01 13:31:08 +05309557 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9558 if (!hif_ctx) {
9559 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309560 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309561 }
9562
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309563 hdd_runtime_suspend_context_deinit(hdd_ctx);
9564
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309565 if (hdd_ctx->target_hw_name) {
9566 qdf_mem_free(hdd_ctx->target_hw_name);
9567 hdd_ctx->target_hw_name = NULL;
9568 }
9569
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309570 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309571
9572 ol_cds_free();
9573
Dustin Brown70111822017-03-30 15:31:40 -07009574 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309575 ret = pld_power_off(qdf_ctx->dev);
9576 if (ret)
9577 hdd_err("CNSS power down failed put device into Low power mode:%d",
9578 ret);
9579 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309580
9581 /* Once the firmware sequence is completed reset this flag */
9582 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309583 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009584 /*
9585 * Reset total mac phy during module stop such that during
9586 * next module start same psoc is used to populate new service
9587 * ready data
9588 */
9589 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309590
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309591done:
9592 hdd_ctx->stop_modules_in_progress = false;
9593 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07009594 hdd_alert("stop WLAN module: exit driver status=%d",
9595 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309596 EXIT();
9597
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309598 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309599
9600}
9601
9602/**
9603 * hdd_iface_change_callback() - Function invoked when stop modules expires
9604 * @priv: pointer to hdd context
9605 *
9606 * This function is invoked when the timer waiting for the interface change
9607 * expires, it shall cut-down the power to wlan and stop all the modules.
9608 *
9609 * Return: void
9610 */
9611static void hdd_iface_change_callback(void *priv)
9612{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009613 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309614 int ret;
9615 int status = wlan_hdd_validate_context(hdd_ctx);
9616
9617 if (status)
9618 return;
9619
9620 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009621 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009622 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309623 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009624 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309625 EXIT();
9626}
9627
9628/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309629 * hdd_state_info_dump() - prints state information of hdd layer
9630 * @buf: buffer pointer
9631 * @size: size of buffer to be filled
9632 *
9633 * This function is used to dump state information of hdd layer
9634 *
9635 * Return: None
9636 */
9637static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9638{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009639 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309640 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9641 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009642 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009643 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309644 uint16_t len = 0;
9645 char *buf = *buf_ptr;
9646
9647 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9648 if (!hdd_ctx) {
9649 hdd_err("Failed to get hdd context ");
9650 return;
9651 }
9652
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009653 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309654
9655 len += scnprintf(buf + len, *size - len,
9656 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9657 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009658 "\n is_scheduler_suspended %d",
9659 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309660
9661 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9662
9663 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009664 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309665 if (adapter->dev)
9666 len += scnprintf(buf + len, *size - len,
9667 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009668 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309669 "\n device_mode: %d", adapter->device_mode);
9670 switch (adapter->device_mode) {
9671 case QDF_STA_MODE:
9672 case QDF_P2P_CLIENT_MODE:
9673 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9674 len += scnprintf(buf + len, *size - len,
9675 "\n connState: %d",
9676 hdd_sta_ctx->conn_info.connState);
9677 break;
9678
9679 default:
9680 break;
9681 }
9682 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9683 adapter_node = next;
9684 }
9685
9686 *size -= len;
9687 *buf_ptr += len;
9688}
9689
9690/**
9691 * hdd_register_debug_callback() - registration function for hdd layer
9692 * to print hdd state information
9693 *
9694 * Return: None
9695 */
9696static void hdd_register_debug_callback(void)
9697{
9698 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9699}
9700
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309701/*
9702 * wlan_init_bug_report_lock() - Initialize bug report lock
9703 *
9704 * This function is used to create bug report lock
9705 *
9706 * Return: None
9707 */
9708static void wlan_init_bug_report_lock(void)
9709{
9710 p_cds_contextType p_cds_context;
9711
9712 p_cds_context = cds_get_global_context();
9713 if (!p_cds_context) {
9714 hdd_err("cds context is NULL");
9715 return;
9716 }
9717
9718 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9719}
9720
Mohit Khannaf8f96822017-05-17 17:11:59 -07009721void hdd_dp_trace_init(struct hdd_config *config)
9722{
9723
9724 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9725 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9726 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9727 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9728 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9729 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9730 uint8_t num_entries = 0;
9731
9732 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9733 &num_entries, sizeof(config_params));
9734
9735 /* calculating, num bw timer intervals in a second (1000ms) */
9736 if (config->busBandwidthComputeInterval)
9737 thresh_time_limit =
9738 (1000 / config->busBandwidthComputeInterval);
9739 else
9740 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9741
9742 switch (num_entries) {
9743 case 4:
9744 proto_bitmap = config_params[3];
9745 case 3:
9746 verbosity = config_params[2];
9747 case 2:
9748 thresh = config_params[1];
9749 case 1:
9750 live_mode = config_params[0];
9751 default:
9752 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9753 live_mode, thresh, thresh_time_limit,
9754 verbosity, proto_bitmap);
9755 };
9756
9757 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9758 verbosity, proto_bitmap);
9759
9760}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309761/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009762 * hdd_wlan_startup() - HDD init function
9763 * @dev: Pointer to the underlying device
9764 *
9765 * This is the driver startup code executed once a WLAN device has been detected
9766 *
9767 * Return: 0 for success, < 0 for failure
9768 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309769int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009770{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309771 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009772 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009773 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009774 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009775
9776 ENTER();
9777
Arun Khandavallifae92942016-08-01 13:31:08 +05309778 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009779
9780 if (IS_ERR(hdd_ctx))
9781 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009782
Abhishek Singhe9068f12017-03-31 14:14:52 +05309783 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9784 DEFAULT_PSOC_ID);
9785 if (ret) {
9786 hdd_err("Psoc creation fails!");
9787 QDF_BUG(0);
9788 goto err_hdd_free_context;
9789 }
9790
Arun Khandavallifae92942016-08-01 13:31:08 +05309791 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9792 hdd_iface_change_callback, (void *)hdd_ctx);
9793
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309794 qdf_nbuf_init_replenish_timer();
9795
Arun Khandavallifae92942016-08-01 13:31:08 +05309796 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309797#ifdef FEATURE_WLAN_CH_AVOID
9798 mutex_init(&hdd_ctx->avoid_freq_lock);
9799#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309800
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009801 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009802 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309803
Jeff Johnson957bc272017-02-02 08:54:48 -08009804 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309805 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009806 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009807 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009808 }
9809
Yingying Tang80e15f32016-09-27 18:23:01 +08009810 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009811
Anurag Chouhan6d760662016-02-20 16:05:43 +05309812 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009813
9814 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009815 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309816 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009817 }
9818
Prashanth Bhatta07998752016-04-28 12:35:33 -07009819 ret = hdd_wiphy_init(hdd_ctx);
9820 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009821 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309822 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009823 }
9824
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309825 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009826 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309827
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309828 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009829 goto err_wiphy_unregister;
9830
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309831 wlan_hdd_init_chan_info(hdd_ctx);
9832
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009833 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009834
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309835 ret = hdd_register_notifiers(hdd_ctx);
9836 if (ret)
9837 goto err_ipa_cleanup;
9838
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009839 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009840
Jeff Johnson957bc272017-02-02 08:54:48 -08009841 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9842 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009843 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009844 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009845 }
9846
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009847 hdd_release_rtnl_lock();
9848 rtnl_held = false;
9849
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009850 wlan_hdd_update_11n_mode(hdd_ctx->config);
9851
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009852#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309853 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309854 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009855 hdd_skip_acs_scan_timer_handler,
9856 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309857 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009858 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009859 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009860#endif
9861
Prashanth Bhattaab004382016-10-11 16:08:11 -07009862 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009863
Jeff Johnson9afc5012016-09-23 13:56:27 -07009864 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009865
Nirav Shahbd36b062016-07-18 11:12:59 +05309866 if (hdd_ctx->rps)
9867 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009868
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309869 status = wlansap_global_init();
9870 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009871 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009872
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009873 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309874 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009875
Arun Khandavallifae92942016-08-01 13:31:08 +05309876 if (hdd_ctx->config->fIsImpsEnabled)
9877 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -07009878 else
9879 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309880
Mukul Sharma07bd8752017-10-10 16:58:14 +05309881 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309882 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309883 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309884 hdd_prevent_suspend_timeout(
9885 hdd_ctx->config->iface_change_wait_time,
9886 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
9887 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309888
Sachin Ahujadddd2632017-03-07 19:07:24 +05309889 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009890 goto success;
9891
Jeff Johnson957bc272017-02-02 08:54:48 -08009892err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009893 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009894
Jeff Johnson46bde382017-02-01 15:31:16 -08009895err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309896 if (rtnl_held)
9897 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009898
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309899 unregister_netdevice_notifier(&hdd_netdev_notifier);
9900
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309901err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309902 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009903
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009904err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009905 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009906
Arun Khandavallifae92942016-08-01 13:31:08 +05309907err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009908 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309909
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009910err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309911 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009912 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309913 if (!QDF_IS_STATUS_SUCCESS(status)) {
9914 hdd_err("Failed to close CDS Scheduler");
9915 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9916 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009917 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009918
Houston Hoffman47a4a052016-11-14 23:22:44 -08009919 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009920 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009921 hdd_exit_netlink_services(hdd_ctx);
9922
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309923 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009924
Dustin Brown20912462017-06-07 13:48:25 -07009925 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9926
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009927err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309928 if (cds_is_fw_down())
9929 hdd_err("Not setting the complete event as fw is down");
9930 else
9931 hdd_start_complete(ret);
9932
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309933 qdf_nbuf_deinit_replenish_timer();
Arun Khandavallifae92942016-08-01 13:31:08 +05309934 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9935 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009936 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009937 return -EIO;
9938
9939success:
9940 EXIT();
9941 return 0;
9942}
9943
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009944/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309945 * hdd_wlan_update_target_info() - update target type info
9946 * @hdd_ctx: HDD context
9947 * @context: hif context
9948 *
9949 * Update target info received from firmware in hdd context
9950 * Return:None
9951 */
9952
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009953void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309954{
9955 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9956
9957 if (!tgt_info) {
9958 hdd_err("Target info is Null");
9959 return;
9960 }
9961
9962 hdd_ctx->target_type = tgt_info->target_type;
9963}
9964
9965/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05309966 * hdd_get_nud_stats_cb() - callback api to update the stats
9967 * received from the firmware
9968 * @data: pointer to adapter.
9969 * @rsp: pointer to data received from FW.
9970 *
9971 * This is called when wlan driver received response event for
9972 * get arp stats to firmware.
9973 *
9974 * Return: None
9975 */
9976static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
9977{
9978 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
9979 struct hdd_nud_stats_context *context;
9980 int status;
9981 struct hdd_adapter *adapter = NULL;
9982
9983 ENTER();
9984
9985 if (!rsp) {
9986 hdd_err("data is null");
9987 return;
9988 }
9989
9990 status = wlan_hdd_validate_context(hdd_ctx);
9991 if (0 != status)
9992 return;
9993
9994 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
9995 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
9996 hdd_err("Invalid adapter or adapter has invalid magic");
9997 return;
9998 }
9999
10000 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10001 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10002 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10003 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10004 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10005 rsp->out_of_order_arp_rsp_drop_cnt);
10006 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10007 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10008 hdd_notice("rsp->ba_session_establishment_status :%x",
10009 rsp->ba_session_establishment_status);
10010
10011 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10012 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10013 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10014 adapter->dad |= rsp->dad_detected;
10015 adapter->con_status = rsp->connect_status;
10016
10017 spin_lock(&hdd_context_lock);
10018 context = &hdd_ctx->nud_stats_context;
10019 complete(&context->response_event);
10020 spin_unlock(&hdd_context_lock);
10021
10022 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010023}
10024
10025/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010026 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010027 * @hdd_ctx: HDD context
10028 *
10029 * Register the HDD callbacks to CDS/SME.
10030 *
10031 * Return: 0 for success or Error code for failure
10032 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010033int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010034{
10035 QDF_STATUS status;
10036 int ret = 0;
10037
10038 ENTER();
10039
10040 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10041
10042 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10043 hdd_send_oem_data_rsp_msg);
10044
10045 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10046 wlan_hdd_cfg80211_fw_mem_dump_cb);
10047 if (!QDF_IS_STATUS_SUCCESS(status)) {
10048 hdd_err("Failed to register memdump callback");
10049 ret = -EINVAL;
10050 return ret;
10051 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010052 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10053 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010054 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10055 sme_nan_register_callback(hdd_ctx->hHal,
10056 wlan_hdd_cfg80211_nan_callback);
10057 sme_stats_ext_register_callback(hdd_ctx->hHal,
10058 wlan_hdd_cfg80211_stats_ext_callback);
10059
10060 sme_ext_scan_register_callback(hdd_ctx->hHal,
10061 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010062 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10063 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010064
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010065 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10066 hdd_rssi_threshold_breached);
10067
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010068 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10069
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010070 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10071 wlan_hdd_cfg80211_link_layer_stats_callback);
10072
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010073 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10074
Zhang Qianca38fb12016-12-23 11:10:48 +080010075 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10076 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10077
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010078 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10079 hdd_lost_link_info_cb);
10080 /* print error and not block the startup process */
10081 if (!QDF_IS_STATUS_SUCCESS(status))
10082 hdd_err("set lost link info callback failed");
10083
Poddar, Siddarth34872782017-08-10 14:08:51 +053010084 ret = hdd_register_data_stall_detect_cb();
10085 if (ret) {
10086 hdd_err("Register data stall detect detect callback failed.");
10087 return ret;
10088 }
10089
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010090 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10091
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010092 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010093 hdd_set_connection_in_progress,
10094 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010095
10096 status = sme_congestion_register_callback(hdd_ctx->hHal,
10097 hdd_update_cca_info_cb);
10098 if (!QDF_IS_STATUS_SUCCESS(status))
10099 hdd_err("set congestion callback failed");
10100
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010101 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10102 hdd_bt_activity_cb);
10103 if (!QDF_IS_STATUS_SUCCESS(status))
10104 hdd_err("set bt activity info callback failed");
10105
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010106 EXIT();
10107
10108 return ret;
10109}
10110
10111/**
10112 * hdd_deregister_cb() - De-Register HDD callbacks.
10113 * @hdd_ctx: HDD context
10114 *
10115 * De-Register the HDD callbacks to CDS/SME.
10116 *
10117 * Return: void
10118 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010119void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010120{
10121 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010122 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010123
10124 ENTER();
10125
10126 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10127 if (!QDF_IS_STATUS_SUCCESS(status))
10128 hdd_err("De-register of dcc stats callback failed: %d",
10129 status);
10130
10131 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010132 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10133
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010134 sme_stats_ext_register_callback(hdd_ctx->hHal,
10135 wlan_hdd_cfg80211_stats_ext_callback);
10136
10137 sme_nan_deregister_callback(hdd_ctx->hHal);
10138 status = sme_reset_tsfcb(hdd_ctx->hHal);
10139 if (!QDF_IS_STATUS_SUCCESS(status))
10140 hdd_err("Failed to de-register tsfcb the callback:%d",
10141 status);
10142 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10143 if (!QDF_IS_STATUS_SUCCESS(status))
10144 hdd_err("Failed to de-register the fw mem dump callback: %d",
10145 status);
10146
Poddar, Siddarth34872782017-08-10 14:08:51 +053010147 ret = hdd_deregister_data_stall_detect_cb();
10148 if (ret)
10149 hdd_err("Failed to de-register data stall detect event callback");
10150
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010151 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10152 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10153
10154 EXIT();
10155}
10156
10157/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010158 * hdd_softap_sta_deauth() - handle deauth req from HDD
10159 * @adapter: Pointer to the HDD
10160 * @enable: bool value
10161 *
10162 * This to take counter measure to handle deauth req from HDD
10163 *
10164 * Return: None
10165 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010166QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010167 struct tagCsrDelStaParams *pDelStaParams)
10168{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010169 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010170
10171 ENTER();
10172
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010173 /* Ignore request to deauth bcmc station */
10174 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010175 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010176
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010177 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010178 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10179 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010180
10181 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010182 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010183}
10184
10185/**
10186 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10187 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010188 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010189 *
10190 * This to take counter measure to handle deauth req from HDD
10191 *
10192 * Return: None
10193 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010194void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010195 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010196{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010197 ENTER();
10198
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010199 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010200 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010201 return;
10202
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010203 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010204 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010205}
10206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010207/**
10208 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10209 * @hdd_ctx: HDD Context
10210 *
10211 * API to find if there is any STA or P2P-Client is connected
10212 *
10213 * Return: true if connected; false otherwise
10214 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010215QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010216{
10217 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10218}
10219
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010220/**
10221 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10222 * @adapter: HDD adapter pointer
10223 *
10224 * This function loop through each adapter and disable roaming on each STA
10225 * device mode except the input adapter.
10226 *
10227 * Note: On the input adapter roaming is not enabled yet hence no need to
10228 * disable.
10229 *
10230 * Return: None
10231 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010232void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010233{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010234 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010235 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010236 hdd_adapter_list_node_t *adapterNode = NULL;
10237 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010238 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010239
10240 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010241 hdd_ctx->config->isRoamOffloadScanEnabled &&
10242 QDF_STA_MODE == adapter->device_mode &&
10243 policy_mgr_is_sta_active_connection_exists(
10244 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010245 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010246 adapter->sessionId);
10247 /*
10248 * Loop through adapter and disable roaming for each STA device
10249 * mode except the input adapter.
10250 */
10251 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10252
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010253 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010254 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010255
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010256 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010257 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010258 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010259 adapterIdx->sessionId);
10260 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10261 (adapterIdx),
10262 adapterIdx->sessionId, 0);
10263 }
10264
10265 status = hdd_get_next_adapter(hdd_ctx,
10266 adapterNode,
10267 &pNext);
10268 adapterNode = pNext;
10269 }
10270 }
10271}
10272
10273/**
10274 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10275 * @adapter: HDD adapter pointer
10276 *
10277 * This function loop through each adapter and enable roaming on each STA
10278 * device mode except the input adapter.
10279 * Note: On the input adapter no need to enable roaming because link got
10280 * disconnected on this.
10281 *
10282 * Return: None
10283 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010284void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010285{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010286 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010287 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010288 hdd_adapter_list_node_t *adapterNode = NULL;
10289 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010290 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010291
10292 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010293 hdd_ctx->config->isRoamOffloadScanEnabled &&
10294 QDF_STA_MODE == adapter->device_mode &&
10295 policy_mgr_is_sta_active_connection_exists(
10296 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010297 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010298 adapter->sessionId);
10299 /*
10300 * Loop through adapter and enable roaming for each STA device
10301 * mode except the input adapter.
10302 */
10303 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10304
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010305 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010306 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010307
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010308 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010309 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010310 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010311 adapterIdx->sessionId);
10312 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10313 (adapterIdx),
10314 adapterIdx->sessionId,
10315 REASON_CONNECT);
10316 }
10317
10318 status = hdd_get_next_adapter(hdd_ctx,
10319 adapterNode,
10320 &pNext);
10321 adapterNode = pNext;
10322 }
10323 }
10324}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010325
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010326/**
10327 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10328 * @skb: sk buffer pointer
10329 *
10330 * Sends the bcast message to SVC multicast group with generic nl socket
10331 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10332 *
10333 * Return: None
10334 */
10335static void nl_srv_bcast_svc(struct sk_buff *skb)
10336{
10337#ifdef CNSS_GENL
10338 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10339#else
10340 nl_srv_bcast(skb);
10341#endif
10342}
10343
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010344void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010345{
10346 struct sk_buff *skb;
10347 struct nlmsghdr *nlh;
10348 tAniMsgHdr *ani_hdr;
10349 void *nl_data = NULL;
10350 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010351 struct radio_index_tlv *radio_info;
10352 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010353
10354 if (in_interrupt() || irqs_disabled() || in_atomic())
10355 flags = GFP_ATOMIC;
10356
10357 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10358
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010359 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010360 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010361
10362 nlh = (struct nlmsghdr *)skb->data;
10363 nlh->nlmsg_pid = 0; /* from kernel */
10364 nlh->nlmsg_flags = 0;
10365 nlh->nlmsg_seq = 0;
10366 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10367
10368 ani_hdr = NLMSG_DATA(nlh);
10369 ani_hdr->type = type;
10370
10371 switch (type) {
10372 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010373 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010374 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010375 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010376 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010377 ani_hdr->length = 0;
10378 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010379 break;
10380 case WLAN_SVC_WLAN_STATUS_IND:
10381 case WLAN_SVC_WLAN_VERSION_IND:
10382 case WLAN_SVC_DFS_CAC_START_IND:
10383 case WLAN_SVC_DFS_CAC_END_IND:
10384 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10385 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10386 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010387 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010388 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010389 ani_hdr->length = len;
10390 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10391 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10392 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010393 break;
10394
10395 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010396 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010397 type);
10398 kfree_skb(skb);
10399 return;
10400 }
10401
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010402 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010403 * Add radio index at the end of the svc event in TLV format
10404 * to maintain the backward compatibility with userspace
10405 * applications.
10406 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010407
10408 tlv_len = 0;
10409
10410 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10411 < WLAN_NL_MAX_PAYLOAD) {
10412 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10413 sizeof(*ani_hdr) + len);
10414 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10415 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10416 radio_info->radio = radio;
10417 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010418 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010419 "Added radio index tlv - radio index %d",
10420 radio_info->radio);
10421 }
10422
10423 nlh->nlmsg_len += tlv_len;
10424 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10425
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010426 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010427}
10428
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010429#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10430void wlan_hdd_auto_shutdown_cb(void)
10431{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010432 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010433
10434 if (!hdd_ctx)
10435 return;
10436
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010437 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010438 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10439 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010440}
10441
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010442void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010443{
10444 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010445 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010446 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010447 bool ap_connected = false, sta_connected = false;
10448 tHalHandle hal_handle;
10449
10450 hal_handle = hdd_ctx->hHal;
10451 if (hal_handle == NULL)
10452 return;
10453
10454 if (hdd_ctx->config->WlanAutoShutdown == 0)
10455 return;
10456
10457 if (enable == false) {
10458 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010459 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010460 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010461 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010462 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010463 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010464 return;
10465 }
10466
10467 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010468 if (policy_mgr_concurrent_open_sessions_running(
10469 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010470 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10471
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010472 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010473 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010474 if (adapter
10475 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010476 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010477 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10478 conn_info.connState ==
10479 eConnectionState_Associated) {
10480 sta_connected = true;
10481 break;
10482 }
10483 }
10484 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010485 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010486 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10487 bApActive == true) {
10488 ap_connected = true;
10489 break;
10490 }
10491 }
10492 status = hdd_get_next_adapter(hdd_ctx,
10493 adapterNode,
10494 &pNext);
10495 adapterNode = pNext;
10496 }
10497 }
10498
10499 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010500 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010501 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010502 }
Jeff Johnson68755312017-02-10 11:46:55 -080010503
10504 if (sme_set_auto_shutdown_timer(hal_handle,
10505 hdd_ctx->config->WlanAutoShutdown)
10506 != QDF_STATUS_SUCCESS)
10507 hdd_err("Failed to start wlan auto shutdown timer");
10508 else
10509 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10510 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010511}
10512#endif
10513
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010514struct hdd_adapter *
10515hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10516 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010517{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010518 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010519 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010520 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010521 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10522
10523 con_sap_adapter = NULL;
10524
10525 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010526 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010527 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010528 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10529 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010530 adapter != this_sap_adapter) {
10531 if (check_start_bss) {
10532 if (test_bit(SOFTAP_BSS_STARTED,
10533 &adapter->event_flags)) {
10534 con_sap_adapter = adapter;
10535 break;
10536 }
10537 } else {
10538 con_sap_adapter = adapter;
10539 break;
10540 }
10541 }
10542 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10543 adapterNode = pNext;
10544 }
10545
10546 return con_sap_adapter;
10547}
10548
10549#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010550static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010551{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010552 return adapter->device_mode == QDF_STA_MODE ||
10553 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010554}
10555
Jeff Johnson9d295242017-08-29 14:39:48 -070010556static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010557{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010558 return adapter->device_mode == QDF_SAP_MODE ||
10559 adapter->device_mode == QDF_P2P_GO_MODE;
10560}
10561
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010562static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010563{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010564 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010565 hdd_adapter_list_node_t *node;
10566
10567 status = hdd_get_front_adapter(hdd_ctx, &node);
10568 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010569 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010570
10571 if (adapter &&
10572 hdd_adapter_is_sta(adapter) &&
10573 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10574 conn_info.connState == eConnectionState_Associated) {
10575 return true;
10576 }
10577
10578 if (adapter &&
10579 hdd_adapter_is_ap(adapter) &&
10580 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10581 return true;
10582 }
10583
10584 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10585 }
10586
10587 return false;
10588}
10589
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010590static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010591{
10592 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010593
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010594 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010595 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010596 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010597
Dustin Brown5ec6b552017-03-31 12:11:40 -070010598 return is_running;
10599}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010600
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010601static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010602{
10603 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10604 hdd_ctx->bus_bw_timer_running = true;
10605 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10606 hdd_ctx->config->busBandwidthComputeInterval);
10607 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10608}
10609
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010610void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010611{
10612 ENTER();
10613
10614 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10615 hdd_debug("Bandwidth compute timer already started");
10616 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010617 }
10618
Dustin Brown5ec6b552017-03-31 12:11:40 -070010619 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10620
10621 EXIT();
10622}
10623
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010624void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010625{
10626 ENTER();
10627
10628 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10629 hdd_debug("Bandwidth compute timer already started");
10630 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010631 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010632
10633 if (hdd_any_adapter_is_assoc(hdd_ctx))
10634 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10635
10636 EXIT();
10637}
10638
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010639static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010640{
10641 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10642
10643 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10644 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10645 hdd_ctx->bus_bw_timer_running = false;
10646 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10647
10648 hdd_reset_tcp_delack(hdd_ctx);
10649}
10650
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010651void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010652{
10653 ENTER();
10654
10655 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10656 hdd_debug("Bandwidth compute timer already stopped");
10657 return;
10658 }
10659
10660 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10661
10662 EXIT();
10663}
10664
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010665void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010666{
10667 ENTER();
10668
10669 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10670 hdd_debug("Bandwidth compute timer already stopped");
10671 return;
10672 }
10673
10674 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10675 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10676
10677 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010678}
10679#endif
10680
10681/**
10682 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10683 * and sta's operating channel.
10684 * @sta_adapter: Describe the first argument to foobar.
10685 * @ap_adapter: Describe the second argument to foobar.
10686 * @roam_profile: Roam profile of AP to which STA wants to connect.
10687 * @concurrent_chnl_same: If both SAP and STA channels are same then
10688 * set this flag to true else false.
10689 *
10690 * This function checks the sap's operating channel and sta's operating channel.
10691 * if both are same then it will return false else it will restart the sap in
10692 * sta's channel and return true.
10693 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010694 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010695 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010696QDF_STATUS
10697wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10698 struct hdd_adapter *ap_adapter,
10699 tCsrRoamProfile *roam_profile,
10700 tScanResultHandle *scan_cache,
10701 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010702{
Jeff Johnson87251032017-08-29 13:31:11 -070010703 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010704 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010705 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010706 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010707 *concurrent_chnl_same = true;
10708
10709 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10710 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010711 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010712 scan_cache,
10713 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010714 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010715 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010716 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10717 if (hdd_ap_ctx->operatingChannel != channel_id) {
10718 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010719 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010720 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010721 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010722 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10723 if (hdd_ap_ctx->operatingChannel != channel_id) {
10724 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010725 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010726 }
10727 }
10728 } else {
10729 /*
10730 * Lets handle worst case scenario here, Scan cache lookup is
10731 * failed so we have to stop the SAP to avoid any channel
10732 * discrepancy between SAP's channel and STA's channel.
10733 * Return the status as failure so caller function could know
10734 * that scan look up is failed.
10735 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010736 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010737 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010738 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010739 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010740}
10741
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010742/**
10743 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10744 * @ap_adapter: SAP adapter
10745 *
10746 * This function will process the stopping of sap adapter.
10747 *
10748 * Return: None
10749 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010750void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010751{
Jeff Johnson87251032017-08-29 13:31:11 -070010752 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010753 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010754 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010755 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010756
10757 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010758 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010759 return;
10760 }
10761
10762 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10763 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010764 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010765 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010767 mutex_lock(&hdd_ctx->sap_lock);
10768 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010769 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010770 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10771 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010772 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010773 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010774 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010775 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010776 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010777 qdf_stop_bss_event,
10778 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010779 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010780 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010781 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010782 return;
10783 }
10784 }
10785 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010786 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10787 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010788 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010789 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010790 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010791 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010792 }
10793 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010794}
10795
10796/**
10797 * wlan_hdd_start_sap() - this function starts bss of SAP.
10798 * @ap_adapter: SAP adapter
10799 *
10800 * This function will process the starting of sap adapter.
10801 *
10802 * Return: None
10803 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010804void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010805{
Jeff Johnson87251032017-08-29 13:31:11 -070010806 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010807 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010808 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010809 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010810 tsap_Config_t *sap_config;
10811
10812 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010813 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010814 return;
10815 }
10816
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010817 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010818 hdd_err("SoftAp role has not been enabled");
10819 return;
10820 }
10821
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010822 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10823 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10824 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10825 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10826
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010827 mutex_lock(&hdd_ctx->sap_lock);
10828 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10829 goto end;
10830
10831 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010832 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010833 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10834 goto end;
10835 }
10836
Wei Song2f76f642016-11-18 16:32:53 +080010837 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010838 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10839 &hdd_ap_ctx->sapConfig,
10840 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010841 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010842 goto end;
10843
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010844 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010845 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010846 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010847 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010848 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010849 goto end;
10850 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010851 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010852 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010853 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010854 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10855 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010856 ap_adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010857end:
10858 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010859 /* SAP context and beacon cleanup will happen during driver unload
10860 * in hdd_stop_adapter
10861 */
10862 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10863
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010864}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010865
10866/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010867 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10868 * mac scan config
10869 * @status: Status of set antenna mode
10870 *
10871 * Callback on setting the dual mac configuration
10872 *
10873 * Return: None
10874 */
10875void wlan_hdd_soc_set_antenna_mode_cb(
10876 enum set_antenna_mode_status status)
10877{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010878 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010879
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010880 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010881
10882 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10883 if (0 != wlan_hdd_validate_context(hdd_ctx))
10884 return;
10885
10886 /* Signal the completion of set dual mac config */
10887 complete(&hdd_ctx->set_antenna_mode_cmpl);
10888}
10889
10890/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010891 * hdd_get_fw_version() - Get FW version
10892 * @hdd_ctx: pointer to HDD context.
10893 * @major_spid: FW version - major spid.
10894 * @minor_spid: FW version - minor spid
10895 * @ssid: FW version - ssid
10896 * @crmid: FW version - crmid
10897 *
10898 * This function is called to get the firmware build version stored
10899 * as part of the HDD context
10900 *
10901 * Return: None
10902 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010903void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010904 uint32_t *major_spid, uint32_t *minor_spid,
10905 uint32_t *siid, uint32_t *crmid)
10906{
10907 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10908 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10909 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10910 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10911}
10912
10913#ifdef QCA_CONFIG_SMP
10914/**
10915 * wlan_hdd_get_cpu() - get cpu_index
10916 *
10917 * Return: cpu_index
10918 */
10919int wlan_hdd_get_cpu(void)
10920{
10921 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010922
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010923 put_cpu();
10924 return cpu_index;
10925}
10926#endif
10927
10928/**
10929 * hdd_get_fwpath() - get framework path
10930 *
10931 * This function is used to get the string written by
10932 * userspace to start the wlan driver
10933 *
10934 * Return: string
10935 */
10936const char *hdd_get_fwpath(void)
10937{
10938 return fwpath.string;
10939}
10940
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010941static int hdd_qdf_print_init(void)
10942{
10943 int qdf_print_idx;
10944 QDF_STATUS status;
10945
10946 status = qdf_print_setup();
10947 if (status != QDF_STATUS_SUCCESS) {
10948 pr_err("qdf_print_setup failed\n");
10949 return -EINVAL;
10950 }
10951
10952 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10953
10954 if (qdf_print_idx < 0) {
10955 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10956 qdf_print_idx);
10957 return -EINVAL;
10958 }
10959
10960 qdf_set_pidx(qdf_print_idx);
10961
10962 return 0;
10963}
10964
10965static void hdd_qdf_print_deinit(void)
10966{
10967 int qdf_print_idx;
10968
10969 qdf_print_idx = qdf_get_pidx();
10970 qdf_print_ctrl_cleanup(qdf_print_idx);
10971}
10972
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010973/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010974 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010975 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010976 * This function initilizes CDS global context with the help of cds_init. This
10977 * has to be the first function called after probe to get a valid global
10978 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010979 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010980 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010981 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010982int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010983{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070010984 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010985 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010986
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070010987 status = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053010988
10989 wlan_init_bug_report_lock();
10990
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010991#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10992 wlan_logging_sock_init_svc();
10993#endif
10994
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070010995 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010996 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010997 ret = -ENOMEM;
10998 goto err_out;
10999 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011000
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011001 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11002 (void *)hdd_drv_ops_inactivity_handler, NULL,
11003 QDF_TIMER_TYPE_SW);
11004
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011005 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011006 hdd_qdf_print_init();
11007
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011008 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011009
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011010err_out:
11011 return ret;
11012}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011013
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011014/**
11015 * hdd_deinit() - Deinitialize Driver
11016 *
11017 * This function frees CDS global context with the help of cds_deinit. This
11018 * has to be the last function call in remove callback to free the global
11019 * context.
11020 */
11021void hdd_deinit(void)
11022{
Dustin Brownedce4a52017-05-10 11:59:15 -070011023 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011024 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011025
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011026 hdd_qdf_print_deinit();
11027
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011028#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11029 wlan_logging_sock_deinit_svc();
11030#endif
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011031
11032 wlan_destroy_bug_report_lock();
11033 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011034}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011035
Yue Ma6e7b1a02017-04-03 14:17:46 -070011036#ifdef QCA_WIFI_NAPIER_EMULATION
11037#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11038#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011039#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011040#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011041
Sachin Ahujadddd2632017-03-07 19:07:24 +053011042static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11043 struct file *file)
11044{
11045 return 0;
11046}
11047
11048static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11049 const char __user *user_buf,
11050 size_t count,
11051 loff_t *f_pos)
11052{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011053 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011054 static const char wlan_off_str[] = "OFF";
11055 static const char wlan_on_str[] = "ON";
11056 int ret;
11057 unsigned long rc;
11058
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011059 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011060 pr_err("Failed to read buffer\n");
11061 return -EINVAL;
11062 }
11063
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011064 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011065 pr_debug("Wifi turning off from UI\n");
11066 goto exit;
11067 }
11068
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011069 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011070 pr_err("Invalid value received from framework");
11071 goto exit;
11072 }
11073
11074 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011075 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011076 rc = wait_for_completion_timeout(&wlan_start_comp,
11077 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11078 if (!rc) {
11079 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11080 ret = -EINVAL;
11081 hdd_start_complete(ret);
11082 return ret;
11083 }
11084
11085 hdd_start_complete(0);
11086 }
11087
11088exit:
11089 return count;
11090}
11091
11092
11093const struct file_operations wlan_hdd_state_fops = {
11094 .owner = THIS_MODULE,
11095 .open = wlan_hdd_state_ctrl_param_open,
11096 .write = wlan_hdd_state_ctrl_param_write,
11097};
11098
11099static int wlan_hdd_state_ctrl_param_create(void)
11100{
11101 unsigned int wlan_hdd_state_major = 0;
11102 int ret;
11103 struct device *dev;
11104
11105 device = MKDEV(wlan_hdd_state_major, 0);
11106
11107 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11108 if (ret) {
11109 pr_err("Failed to register qcwlanstate");
11110 goto dev_alloc_err;
11111 }
11112 wlan_hdd_state_major = MAJOR(device);
11113
11114 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11115 if (IS_ERR(class)) {
11116 pr_err("wlan_hdd_state class_create error");
11117 goto class_err;
11118 }
11119
11120 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11121 if (IS_ERR(dev)) {
11122 pr_err("wlan_hdd_statedevice_create error");
11123 goto err_class_destroy;
11124 }
11125
11126 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11127 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11128 if (ret) {
11129 pr_err("Failed to add cdev error");
11130 goto cdev_add_err;
11131 }
11132
11133 pr_info("wlan_hdd_state %s major(%d) initialized",
11134 WLAN_MODULE_NAME, wlan_hdd_state_major);
11135
11136 return 0;
11137
11138cdev_add_err:
11139 device_destroy(class, device);
11140err_class_destroy:
11141 class_destroy(class);
11142class_err:
11143 unregister_chrdev_region(device, dev_num);
11144dev_alloc_err:
11145 return -ENODEV;
11146}
11147
11148static void wlan_hdd_state_ctrl_param_destroy(void)
11149{
11150 cdev_del(&wlan_hdd_state_cdev);
11151 device_destroy(class, device);
11152 class_destroy(class);
11153 unregister_chrdev_region(device, dev_num);
11154
11155 pr_info("Device node unregistered");
11156}
11157
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011158/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011159 * component_init - API to init cld component's
11160 *
11161 * Return: None
11162 */
11163static void component_init(void)
11164{
11165 pmo_init();
11166}
11167
11168/**
11169 * component_deinit - API to deinit cld component's
11170 *
11171 * Return: None
11172 */
11173static void component_deinit(void)
11174{
11175 pmo_deinit();
11176}
11177
11178/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011179 * __hdd_module_init - Module init helper
11180 *
11181 * Module init helper function used by both module and static driver.
11182 *
11183 * Return: 0 for success, errno on failure
11184 */
11185static int __hdd_module_init(void)
11186{
11187 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011188
Dustin Brownab482ac2017-06-09 17:00:44 -070011189 pr_err("%s: Loading driver v%s (%s)%s\n",
11190 WLAN_MODULE_NAME,
11191 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011192 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011193 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011194
Sachin Ahujadddd2632017-03-07 19:07:24 +053011195 ret = wlan_hdd_state_ctrl_param_create();
11196 if (ret) {
11197 pr_err("wlan_hdd_state_create:%x\n", ret);
11198 goto err_dev_state;
11199 }
11200
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011201 pld_init();
11202
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011203 ret = hdd_init();
11204 if (ret) {
11205 pr_err("hdd_init failed %x\n", ret);
11206 goto err_hdd_init;
11207 }
11208
Rajeev Kumar97767a02016-11-30 11:20:40 -080011209 dispatcher_init();
11210
Mukul Sharmad75a6672017-06-22 15:40:53 +053011211 /* Ensure to call post objmgr init */
11212 component_init();
11213
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011214 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011215
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011216 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011217
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011218 ret = wlan_hdd_register_driver();
11219 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011220 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11221 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011222 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011223 }
11224
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011225 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011226
11227 return 0;
11228out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011229 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011230 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011231 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011232
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011233err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011234 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011235 wlan_hdd_state_ctrl_param_destroy();
11236err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011237 return ret;
11238}
11239
11240/**
11241 * __hdd_module_exit - Module exit helper
11242 *
11243 * Module exit helper function used by both module and static driver.
11244 */
11245static void __hdd_module_exit(void)
11246{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011247
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011248 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11249 QWLAN_VERSIONSTR);
11250
bings6028ee82017-03-29 07:51:40 +080011251 cds_set_unload_in_progress(true);
11252
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011253 hdd_wait_for_recovery_completion();
11254
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011255 wlan_hdd_unregister_driver();
11256
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011257 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011258
Mukul Sharmad75a6672017-06-22 15:40:53 +053011259 /* Ensure to call prior to objmgr deinit */
11260 component_deinit();
11261
Rajeev Kumar97767a02016-11-30 11:20:40 -080011262 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011263 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011264 pld_deinit();
11265
Sachin Ahujadddd2632017-03-07 19:07:24 +053011266 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011267}
11268
Arun Khandavallifae92942016-08-01 13:31:08 +053011269#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011270/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011271 * wlan_boot_cb() - Wlan boot callback
11272 * @kobj: object whose directory we're creating the link in.
11273 * @attr: attribute the user is interacting with
11274 * @buff: the buffer containing the user data
11275 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011276 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011277 * This callback is invoked when the fs is ready to start the
11278 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011279 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011280 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011281 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011282static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011283 struct kobj_attribute *attr,
11284 const char *buf,
11285 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011286{
Arun Khandavallifae92942016-08-01 13:31:08 +053011287
Arun Khandavallifae92942016-08-01 13:31:08 +053011288 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011289 pr_err("%s: wlan driver already initialized\n", __func__);
11290 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011291 }
11292
Arun Khandavallifae92942016-08-01 13:31:08 +053011293 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011294 pr_err("%s: wlan driver initialization failed\n", __func__);
11295 return -EIO;
11296 }
11297
11298 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011299
11300 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011301}
Arun Khandavallifae92942016-08-01 13:31:08 +053011302
11303/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011304 * hdd_sysfs_cleanup() - cleanup sysfs
11305 *
11306 * Return: None
11307 *
11308 */
11309static void hdd_sysfs_cleanup(void)
11310{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011311 /* remove from group */
11312 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11313 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11314 wlan_loader->attr_group);
11315
11316 /* unlink the object from parent */
11317 kobject_del(wlan_loader->boot_wlan_obj);
11318
11319 /* free the object */
11320 kobject_put(wlan_loader->boot_wlan_obj);
11321
11322 kfree(wlan_loader->attr_group);
11323 kfree(wlan_loader);
11324
11325 wlan_loader = NULL;
11326}
11327
11328/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011329 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11330 * ready
11331 *
11332 * This is creates the syfs entry boot_wlan. Which shall be invoked
11333 * when the filesystem is ready.
11334 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011335 * QDF API cannot be used here since this function is called even before
11336 * initializing WLAN driver.
11337 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011338 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011339 */
11340static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011341{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011342 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011343
11344 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011345 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011346 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011347
11348 wlan_loader->boot_wlan_obj = NULL;
11349 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11350 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011351 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011352 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011353
11354 wlan_loader->loaded_state = 0;
11355 wlan_loader->attr_group->attrs = attrs;
11356
11357 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11358 kernel_kobj);
11359 if (!wlan_loader->boot_wlan_obj) {
11360 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011361 goto error_return;
11362 }
11363
11364 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11365 wlan_loader->attr_group);
11366 if (ret) {
11367 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11368 goto error_return;
11369 }
11370
11371 return 0;
11372
11373error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011374 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011375
11376 return ret;
11377}
11378
11379/**
11380 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11381 *
11382 * Return: 0 on success or errno on failure
11383 */
11384static int wlan_deinit_sysfs(void)
11385{
Arun Khandavallifae92942016-08-01 13:31:08 +053011386 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011387 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011388 return -EINVAL;
11389 }
11390
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011391 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011392 return 0;
11393}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011394
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011395#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011396
11397#ifdef MODULE
11398/**
11399 * __hdd_module_init - Module init helper
11400 *
11401 * Module init helper function used by both module and static driver.
11402 *
11403 * Return: 0 for success, errno on failure
11404 */
11405static int hdd_module_init(void)
11406{
Arun Khandavallifae92942016-08-01 13:31:08 +053011407 if (__hdd_module_init()) {
11408 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011409 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011410 }
11411
Dustin Brownab482ac2017-06-09 17:00:44 -070011412 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011413}
11414#else
11415static int __init hdd_module_init(void)
11416{
11417 int ret = -EINVAL;
11418
11419 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011420 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011421 pr_err("Failed to create sysfs entry for loading wlan");
11422
11423 return ret;
11424}
11425#endif
11426
11427
11428#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011429/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011430 * hdd_module_exit() - Exit function
11431 *
11432 * This is the driver exit point (invoked when module is unloaded using rmmod)
11433 *
11434 * Return: None
11435 */
11436static void __exit hdd_module_exit(void)
11437{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011438 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011439}
Arun Khandavallifae92942016-08-01 13:31:08 +053011440#else
11441static void __exit hdd_module_exit(void)
11442{
11443 __hdd_module_exit();
11444 wlan_deinit_sysfs();
11445}
11446#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011447
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011448static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11449{
11450 return param_set_copystring(kmessage, kp);
11451}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011452
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011453/**
11454 * is_con_mode_valid() check con mode is valid or not
11455 * @mode: global con mode
11456 *
11457 * Return: TRUE on success FALSE on failure
11458 */
11459static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11460{
11461 switch (mode) {
11462 case QDF_GLOBAL_MONITOR_MODE:
11463 case QDF_GLOBAL_FTM_MODE:
11464 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011465 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011466 return true;
11467 default:
11468 return false;
11469 }
11470}
11471
11472/**
11473 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11474 * @mode: global con mode
11475 *
11476 * Return: adapter mode
11477 */
11478static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11479 enum tQDF_GLOBAL_CON_MODE mode)
11480{
11481
11482 switch (mode) {
11483 case QDF_GLOBAL_MISSION_MODE:
11484 return QDF_STA_MODE;
11485 case QDF_GLOBAL_MONITOR_MODE:
11486 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011487 case QDF_GLOBAL_EPPING_MODE:
11488 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011489 case QDF_GLOBAL_FTM_MODE:
11490 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011491 case QDF_GLOBAL_QVIT_MODE:
11492 return QDF_QVIT_MODE;
11493 default:
11494 return QDF_MAX_NO_OF_MODE;
11495 }
11496}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011497
Dustin Brown27cd9942017-09-27 16:11:44 -070011498static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11499 enum tQDF_GLOBAL_CON_MODE curr_mode)
11500{
11501 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11502 return;
11503
11504 switch (curr_mode) {
11505 case QDF_GLOBAL_MISSION_MODE:
11506 case QDF_GLOBAL_MONITOR_MODE:
11507 case QDF_GLOBAL_FTM_MODE:
11508 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11509 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11510
11511 /* re-use the existing session */
11512 hdd_stop_all_adapters(hdd_ctx, false);
11513 break;
11514 default:
11515 break;
11516 }
11517}
11518
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011519static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011520 enum tQDF_GLOBAL_CON_MODE curr_mode)
11521{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011522 int driver_status;
11523
11524 driver_status = hdd_ctx->driver_status;
11525
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011526 switch (curr_mode) {
11527 case QDF_GLOBAL_MISSION_MODE:
11528 case QDF_GLOBAL_MONITOR_MODE:
11529 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011530 hdd_deinit_all_adapters(hdd_ctx, false);
11531 hdd_close_all_adapters(hdd_ctx, false);
11532 break;
11533 case QDF_GLOBAL_EPPING_MODE:
11534 epping_disable();
11535 epping_close();
11536 break;
11537 default:
11538 return;
11539 }
11540}
11541
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011542static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011543 enum tQDF_GLOBAL_CON_MODE mode)
11544{
Jeff Johnson9d295242017-08-29 14:39:48 -070011545 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011546 int ret = 0;
11547 bool rtnl_held;
11548 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11549 QDF_STATUS status;
11550
11551 if (!qdf_dev) {
11552 hdd_err("qdf device context is Null return!");
11553 return -EINVAL;
11554 }
11555
11556 rtnl_held = hdd_hold_rtnl_lock();
11557 switch (mode) {
11558 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011559 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11560 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011561 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011562 break;
11563 case QDF_GLOBAL_FTM_MODE:
11564 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11565 wlan_hdd_get_intf_addr(hdd_ctx),
11566 NET_NAME_UNKNOWN, rtnl_held);
11567 if (adapter == NULL)
11568 ret = -EINVAL;
11569 break;
11570 case QDF_GLOBAL_MONITOR_MODE:
11571 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11572 wlan_hdd_get_intf_addr(hdd_ctx),
11573 NET_NAME_UNKNOWN, rtnl_held);
11574 if (adapter == NULL)
11575 ret = -EINVAL;
11576 break;
11577 case QDF_GLOBAL_EPPING_MODE:
11578 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011579 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011580 hdd_err("Failed to open in eeping mode: %d", status);
11581 ret = -EINVAL;
11582 break;
11583 }
11584 ret = epping_enable(qdf_dev->dev);
11585 if (ret) {
11586 hdd_err("Failed to enable in epping mode : %d", ret);
11587 epping_close();
11588 }
11589 break;
11590 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011591 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011592 ret = -ENOTSUPP;
11593 break;
11594 }
11595 hdd_release_rtnl_lock();
11596 rtnl_held = false;
11597 return ret;
11598}
11599
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011600/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011601 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011602 * @kmessage: con mode name on which driver to be bring up
11603 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011604 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011605 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011606 * This function is invoked when user updates con mode using sys entry,
11607 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011608 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011609 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011610 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011611static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011612 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011613{
11614 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011615 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011616 enum tQDF_GLOBAL_CON_MODE curr_mode;
11617 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011618
Dustin Brownab6029b2017-05-24 13:04:19 -070011619 hdd_info("con_mode handler: %s", kmessage);
11620
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011621 ret = wlan_hdd_validate_context(hdd_ctx);
11622 if (ret)
11623 return ret;
11624
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011625 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011626
11627 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011628
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011629 if (!(is_con_mode_valid(con_mode))) {
11630 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011631 ret = -EINVAL;
11632 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011633 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011634
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011635 curr_mode = hdd_get_conparam();
11636 if (curr_mode == con_mode) {
11637 hdd_err("curr mode: %d is same as user triggered mode %d",
11638 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011639 ret = 0;
11640 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011641 }
11642
Dustin Brown27cd9942017-09-27 16:11:44 -070011643 /* ensure adapters are stopped */
11644 hdd_stop_present_mode(hdd_ctx, curr_mode);
11645
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011646 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011647 if (ret) {
11648 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011649 goto reset_flags;
11650 }
11651
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011652 /* Cleanup present mode before switching to new mode */
11653 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11654
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011655 hdd_set_conparam(con_mode);
11656
11657 /* Register for new con_mode & then kick_start modules again */
11658 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11659 if (ret) {
11660 hdd_err("Failed to register for new mode");
11661 goto reset_flags;
11662 }
11663
11664 adapter_mode = hdd_get_adpter_mode(con_mode);
11665 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11666 hdd_err("invalid adapter");
11667 ret = -EINVAL;
11668 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011669 }
11670
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011671 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011672 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011673 hdd_err("Failed to get adapter:%d", adapter_mode);
11674 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011675 }
11676
11677 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11678 if (ret) {
11679 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011680 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011681 }
11682
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011683 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011684 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011685 if (hdd_start_adapter(adapter)) {
11686 hdd_err("Failed to start %s adapter", kmessage);
11687 ret = -EINVAL;
11688 goto reset_flags;
11689 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011690 }
11691
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011692 hdd_info("Mode successfully changed to %s", kmessage);
11693 ret = 0;
11694
11695reset_flags:
11696 cds_set_load_in_progress(false);
11697 return ret;
11698}
11699
11700
11701static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11702{
11703 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011704 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011705
11706 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11707 ret = wlan_hdd_validate_context(hdd_ctx);
11708 if (ret)
11709 return ret;
11710
11711 cds_ssr_protect(__func__);
11712 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11713 cds_ssr_unprotect(__func__);
11714
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011715 return ret;
11716}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011717
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011718static int con_mode_handler_ftm(const char *kmessage,
11719 struct kernel_param *kp)
11720{
11721 int ret;
11722
11723 ret = param_set_int(kmessage, kp);
11724
11725 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11726 pr_err("Only FTM mode supported!");
11727 return -ENOTSUPP;
11728 }
11729
11730 hdd_set_conparam(con_mode_ftm);
11731 con_mode = con_mode_ftm;
11732
11733 return ret;
11734}
11735
Ravi Joshia307f632017-07-17 23:41:41 -070011736static int con_mode_handler_monitor(const char *kmessage,
11737 struct kernel_param *kp)
11738{
11739 int ret;
11740
11741 ret = param_set_int(kmessage, kp);
11742
11743 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11744 pr_err("Only Monitor mode supported!");
11745 return -ENOTSUPP;
11746 }
11747
11748 hdd_set_conparam(con_mode_monitor);
11749 con_mode = con_mode_monitor;
11750
11751 return ret;
11752}
11753
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011754/**
11755 * hdd_get_conparam() - driver exit point
11756 *
11757 * This is the driver exit point (invoked when module is unloaded using rmmod)
11758 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011759 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011760 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011761enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011762{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011763 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011764}
11765
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011766void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011767{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011768 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011769}
11770
Komal Seelamc11bb222016-01-27 18:57:10 +053011771/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011772 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11773 * @hdd_ctx: HDD context
11774 *
11775 * Cleans up the pre cac interface, if it exists
11776 *
11777 * Return: None
11778 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011779void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011780{
11781 uint8_t session_id;
11782 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011783 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011784
11785 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11786 if (QDF_IS_STATUS_ERROR(status)) {
11787 hdd_err("failed to get pre cac vdev id");
11788 return;
11789 }
11790
11791 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11792 if (!precac_adapter) {
11793 hdd_err("invalid pre cac adapater");
11794 return;
11795 }
11796
11797 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11798 wlan_hdd_sap_pre_cac_failure,
11799 (void *)precac_adapter);
11800 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11801
11802}
11803
11804/**
Komal Seelamec702b02016-02-24 18:42:16 +053011805 * hdd_update_ol_config - API to update ol configuration parameters
11806 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011807 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011808 * Return: void
11809 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011810static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011811{
Komal Seelamec702b02016-02-24 18:42:16 +053011812 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011813 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011814
Komal Seelamec702b02016-02-24 18:42:16 +053011815 if (!ol_ctx)
11816 return;
11817
11818 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11819 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11820 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11821 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011822 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011823
11824 ol_init_ini_config(ol_ctx, &cfg);
11825}
11826
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011827#ifdef FEATURE_RUNTIME_PM
11828/**
11829 * hdd_populate_runtime_cfg() - populate runtime configuration
11830 * @hdd_ctx: hdd context
11831 * @cfg: pointer to the configuration memory being populated
11832 *
11833 * Return: void
11834 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011835static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011836 struct hif_config_info *cfg)
11837{
11838 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11839 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11840}
11841#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011842static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011843 struct hif_config_info *cfg)
11844{
11845}
11846#endif
11847
Komal Seelamec702b02016-02-24 18:42:16 +053011848/**
11849 * hdd_update_hif_config - API to update HIF configuration parameters
11850 * @hdd_ctx: HDD Context
11851 *
11852 * Return: void
11853 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011854static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011855{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011856 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011857 struct hif_config_info cfg;
11858
11859 if (!scn)
11860 return;
11861
11862 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011863 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011864 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011865
11866 if (hdd_ctx->config->prevent_link_down)
11867 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011868}
11869
11870/**
11871 * hdd_update_config() - Initialize driver per module ini parameters
11872 * @hdd_ctx: HDD Context
11873 *
11874 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011875 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011876 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011877int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011878{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011879 int ret;
11880
Komal Seelamec702b02016-02-24 18:42:16 +053011881 hdd_update_ol_config(hdd_ctx);
11882 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011883 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11884 ret = hdd_update_cds_config_ftm(hdd_ctx);
11885 else
11886 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011887 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011888
11889 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011890}
11891
Mukul Sharma9d797a02017-01-05 20:26:03 +053011892#ifdef FEATURE_WLAN_RA_FILTERING
11893/**
11894 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11895 * @psoc_cfg: pmo psoc Configuration
11896 * @hdd_ctx: Pointer to hdd context
11897 *
11898 * Return: none
11899 */
11900static inline void hdd_ra_populate_pmo_config(
11901 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011902 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011903{
11904 psoc_cfg->ra_ratelimit_interval =
11905 hdd_ctx->config->RArateLimitInterval;
11906 psoc_cfg->ra_ratelimit_enable =
11907 hdd_ctx->config->IsRArateLimitEnabled;
11908}
11909#else
11910static inline void hdd_ra_populate_pmo_config(
11911 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011912 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011913{
11914}
11915#endif
11916/**
11917 * hdd_update_pmo_config - API to update pmo configuration parameters
11918 * @hdd_ctx: HDD context
11919 *
11920 * Return: void
11921 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011922static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011923{
11924 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11925 struct pmo_psoc_cfg psoc_cfg;
11926 QDF_STATUS status;
11927
11928 /*
11929 * Value of hdd_ctx->wowEnable can be,
11930 * 0 - Disable both magic pattern match and pattern byte match.
11931 * 1 - Enable magic pattern match on all interfaces.
11932 * 2 - Enable pattern byte match on all interfaces.
11933 * 3 - Enable both magic patter and pattern byte match on
11934 * all interfaces.
11935 */
11936 psoc_cfg.magic_ptrn_enable =
11937 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11938 psoc_cfg.ptrn_match_enable_all_vdev =
11939 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080011940 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
11941 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011942 psoc_cfg.bpf_enable =
11943 hdd_ctx->config->bpf_packet_filter_enable;
11944 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011945 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011946 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11947 if (hdd_ctx->config->fhostNSOffload)
11948 psoc_cfg.ns_offload_enable_dynamic = true;
11949 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11950 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11951 psoc_cfg.active_mode_offload =
11952 hdd_ctx->config->active_mode_offload;
11953 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11954 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011955 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11956 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11957 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11958 psoc_cfg.power_save_mode =
11959 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011960 psoc_cfg.auto_power_save_fail_mode =
11961 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011962
11963 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011964 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11965 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011966 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11967 if (status != QDF_STATUS_SUCCESS) {
11968 hdd_err("failed pmo psoc configuration");
11969 return -EINVAL;
11970 }
11971
11972 return 0;
11973}
11974
Abhishek Singhb20db962017-03-03 21:28:46 +053011975#ifdef FEATURE_WLAN_SCAN_PNO
11976static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11977 struct hdd_config *cfg)
11978{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070011979 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
11980
Abhishek Singhb20db962017-03-03 21:28:46 +053011981 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11982 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11983 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11984 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11985 pno_cfg->channel_prediction_full_scan =
11986 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070011987 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
11988 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
11989 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
11990 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053011991}
11992#else
11993static inline void
11994hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070011995 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053011996{
Abhishek Singhb20db962017-03-03 21:28:46 +053011997}
11998#endif
11999
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012000void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12001 struct hdd_config *cfg)
12002{
12003 uint8_t i = 0;
12004
12005 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12006 if (!ie_whitelist->white_list)
12007 return;
12008
12009 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12010 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12011 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12012 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12013 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12014 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12015 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12016 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12017
12018 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12019 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12020 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12021}
12022
Abhishek Singh257a9482017-03-06 16:52:39 +053012023/**
12024 * hdd_update_scan_config - API to update scan configuration parameters
12025 * @hdd_ctx: HDD context
12026 *
12027 * Return: 0 if success else err
12028 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012029static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012030{
12031 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12032 struct scan_user_cfg scan_cfg;
12033 struct hdd_config *cfg = hdd_ctx->config;
12034 QDF_STATUS status;
12035
12036 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12037 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12038 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12039 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12040 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12041 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12042 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012043 /* convert to ms */
12044 scan_cfg.scan_cache_aging_time =
12045 cfg->scanAgingTimeout * 1000;
12046 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12047 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12048 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12049 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012050 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012051 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012052 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Abhishek Singh257a9482017-03-06 16:52:39 +053012053
Abhishek Singhb20db962017-03-03 21:28:46 +053012054 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012055 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012056
Abhishek Singh257a9482017-03-06 16:52:39 +053012057 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12058 if (status != QDF_STATUS_SUCCESS) {
12059 hdd_err("failed pmo psoc configuration");
12060 return -EINVAL;
12061 }
12062
12063 return 0;
12064}
Abhishek Singh257a9482017-03-06 16:52:39 +053012065
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012066static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012067{
12068 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12069 struct tdls_start_params tdls_cfg;
12070 struct tdls_user_config *config = &tdls_cfg.config;
12071 struct hdd_config *cfg = hdd_ctx->config;
12072 QDF_STATUS status;
12073
12074 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12075 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12076 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12077 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12078 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12079 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12080 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12081 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12082 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12083 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12084 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12085 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12086 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12087 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12088 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12089 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12090 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12091 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12092 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12093 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12094 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12095 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12096 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12097 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12098 (cfg->fEnableTDLSImplicitTrigger ?
12099 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12100 (cfg->fTDLSExternalControl ?
12101 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12102
12103 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12104 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12105 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12106 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012107 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012108 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012109 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12110 tdls_cfg.tdls_evt_cb_data = psoc;
12111 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12112 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12113 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012114 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12115 tdls_cfg.tdls_wmm_cb_data = psoc;
12116 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12117 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012118 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012119
12120 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12121 if (status != QDF_STATUS_SUCCESS) {
12122 hdd_err("failed pmo psoc configuration");
12123 return -EINVAL;
12124 }
12125
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012126 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012127 /* enable napier specific tdls data path */
12128 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012129
Frank Liud4b2fa02017-03-29 11:46:48 +080012130 return 0;
12131}
Frank Liud4b2fa02017-03-29 11:46:48 +080012132
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012133int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012134{
12135 int ret;
12136
12137 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012138 if (ret)
12139 return ret;
12140 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012141 if (ret)
12142 return ret;
12143 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012144
12145 return ret;
12146}
12147
Agrawal Ashish65634612016-08-18 13:24:32 +053012148/**
12149 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12150 * @mode : cfg80211 DFS mode
12151 *
12152 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12153 */
12154enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12155{
12156 switch (mode) {
12157 case DFS_MODE_ENABLE:
12158 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012159 case DFS_MODE_DISABLE:
12160 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012161 case DFS_MODE_DEPRIORITIZE:
12162 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012163 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012164 hdd_debug("ACS dfs mode is NONE");
12165 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012166 }
12167}
12168
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012169/**
12170 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12171 * @hddctx: pointer to hdd context
12172 * @set_value: enable/disable
12173 *
12174 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12175 * Host(even though it is duplicate). When Host send vendor command
12176 * disable,FW doesn't perform any action. Whenever any change in
12177 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12178 *
12179 * return - 0 on success, appropriate error values on failure.
12180 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012181int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012182{
12183 QDF_STATUS status;
12184
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012185 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012186 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012187
12188 if (!hddctx->config->goptimize_chan_avoid_event) {
12189 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12190 return -EINVAL;
12191 }
12192
12193 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12194 if (!QDF_IS_STATUS_SUCCESS(status)) {
12195 hdd_err("Failed to send chan avoid command to SME");
12196 return -EINVAL;
12197 }
12198 return 0;
12199}
Agrawal Ashish65634612016-08-18 13:24:32 +053012200
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012201/**
12202 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12203 * @value: value to set
12204 *
12205 * This function will set the passed value to roaming in progress flag.
12206 *
12207 * Return: None
12208 */
12209void hdd_set_roaming_in_progress(bool value)
12210{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012211 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012212
12213 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12214 if (!hdd_ctx) {
12215 hdd_err("HDD context is NULL");
12216 return;
12217 }
12218
12219 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012220 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012221}
12222
12223/**
12224 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012225 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012226 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012227 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012228 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012229bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012230{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012231 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012232 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012233
12234 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12235 if (!hdd_ctx) {
12236 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012237 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012238 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012239 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12240 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012241 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12242 hdd_ctx->roaming_in_progress);
12243
12244 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012245}
12246
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012247/**
12248 * hdd_is_connection_in_progress() - check if connection is in
12249 * progress
12250 * @session_id: session id
12251 * @reason: scan reject reason
12252 *
12253 * Go through each adapter and check if Connection is in progress
12254 *
12255 * Return: true if connection is in progress else false
12256 */
12257bool hdd_is_connection_in_progress(uint8_t *session_id,
12258 enum scan_reject_states *reason)
12259{
12260 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012261 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012262 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012263 QDF_STATUS status = 0;
12264 uint8_t sta_id = 0;
12265 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012266 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012267
12268 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12269 if (!hdd_ctx) {
12270 hdd_err("HDD context is NULL");
12271 return false;
12272 }
12273
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012274 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12275 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012276 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012277 if (!adapter)
12278 goto end;
12279
12280 hdd_info("Adapter with device mode %s(%d) exists",
12281 hdd_device_mode_to_string(adapter->device_mode),
12282 adapter->device_mode);
12283 if (((QDF_STA_MODE == adapter->device_mode)
12284 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12285 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12286 && (eConnectionState_Connecting ==
12287 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12288 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012289 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012290 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12291 adapter->sessionId);
12292 if (session_id && reason) {
12293 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012294 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012295 }
12296 return true;
12297 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012298 /*
12299 * sme_neighbor_middle_of_roaming is for LFR2
12300 * hdd_is_roaming_in_progress is for LFR3
12301 */
12302 if (((QDF_STA_MODE == adapter->device_mode) &&
12303 sme_neighbor_middle_of_roaming(
12304 WLAN_HDD_GET_HAL_CTX(adapter),
12305 adapter->sessionId)) ||
12306 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012307 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012308 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12309 adapter->sessionId);
12310 if (session_id && reason) {
12311 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012312 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012313 }
12314 return true;
12315 }
12316 if ((QDF_STA_MODE == adapter->device_mode) ||
12317 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12318 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12319 hdd_sta_ctx =
12320 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12321 if ((eConnectionState_Associated ==
12322 hdd_sta_ctx->conn_info.connState)
12323 && (false ==
12324 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12325 sta_mac = (uint8_t *)
12326 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012327 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012328 " is in middle of WPS/EAPOL exchange.",
12329 MAC_ADDR_ARRAY(sta_mac));
12330 if (session_id && reason) {
12331 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012332 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012333 }
12334 return true;
12335 }
12336 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12337 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12338 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12339 sta_id++) {
12340 if (!((adapter->aStaInfo[sta_id].isUsed)
12341 && (OL_TXRX_PEER_STATE_CONN ==
12342 adapter->aStaInfo[sta_id].tlSTAState)))
12343 continue;
12344
12345 sta_mac = (uint8_t *)
12346 &(adapter->aStaInfo[sta_id].
12347 macAddrSTA.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012348 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012349 " of SAP/GO is in middle of WPS/EAPOL exchange",
12350 MAC_ADDR_ARRAY(sta_mac));
12351 if (session_id && reason) {
12352 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012353 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012354 }
12355 return true;
12356 }
12357 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012358 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012359 return true;
12360 }
12361 }
12362end:
12363 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12364 adapter_node = next;
12365 }
12366 return false;
12367}
12368
12369/**
12370 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012371 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012372 *
12373 * Return: None
12374 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012375void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012376{
Jeff Johnson87251032017-08-29 13:31:11 -070012377 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012378 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012379 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012380 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012381 tsap_Config_t *sap_config;
12382 void *sap_ctx;
12383
12384 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12385 sap_config = &hdd_ap_ctx->sapConfig;
12386 sap_ctx = hdd_ap_ctx->sapContext;
12387
12388 mutex_lock(&hdd_ctx->sap_lock);
12389 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12390 wlan_hdd_del_station(ap_adapter);
12391 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12392 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12393 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12394 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12395 qdf_status =
12396 qdf_wait_single_event(&hostapd_state->
12397 qdf_stop_bss_event,
12398 SME_CMD_TIMEOUT_VALUE);
12399
12400 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012401 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012402 goto end;
12403 }
12404 }
12405 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012406 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012407 ap_adapter->device_mode, ap_adapter->sessionId);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012408 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012409
12410 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012411 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012412 wlansap_reset_sap_config_add_ie(sap_config,
12413 eUPDATE_IE_ALL);
12414 goto end;
12415 }
12416
12417 qdf_event_reset(&hostapd_state->qdf_event);
12418 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12419 sap_config,
12420 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012421 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012422 wlansap_reset_sap_config_add_ie(sap_config,
12423 eUPDATE_IE_ALL);
12424 goto end;
12425 }
12426
Jeff Johnson6867ec32017-09-29 20:30:20 -070012427 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012428 qdf_status =
12429 qdf_wait_single_event(&hostapd_state->qdf_event,
12430 SME_CMD_TIMEOUT_VALUE);
12431 wlansap_reset_sap_config_add_ie(sap_config,
12432 eUPDATE_IE_ALL);
12433 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012434 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012435 goto end;
12436 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012437 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012438 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12439 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012440 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12441 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012442 ap_adapter->sessionId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012443 }
12444end:
12445 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012446}
12447
12448/**
12449 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12450 * with non dfs acs
12451 *
12452 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12453 *
12454 * Return: None
12455 */
12456void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12457{
Jeff Johnson9d295242017-08-29 14:39:48 -070012458 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012459 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012460 cds_context_type *cds_ctx;
12461
12462 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12463 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012464 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012465 return;
12466 }
12467
12468 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12469 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012470 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012471 return;
12472 }
12473
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012474 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12475 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012476 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012477 return;
12478 }
12479
12480 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012481 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12482 &ap_adapter->event_flags) &&
12483 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12484 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012485
Jeff Johnson6867ec32017-09-29 20:30:20 -070012486 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012487 ap_adapter->sessionCtx.ap.sapConfig.channel =
12488 AUTO_CHANNEL_SELECT;
12489 ap_adapter->sessionCtx.ap.sapConfig.
12490 acs_cfg.acs_mode = true;
12491
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012492 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012493 }
12494}
12495
12496/**
12497 * hdd_set_connection_in_progress() - to set the connection in
12498 * progress flag
12499 * @value: value to set
12500 *
12501 * This function will set the passed value to connection in progress flag.
12502 * If value is previously being set to true then no need to set it again.
12503 *
12504 * Return: true if value is being set correctly and false otherwise.
12505 */
12506bool hdd_set_connection_in_progress(bool value)
12507{
12508 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012509 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012510
12511 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12512 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012513 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012514 return false;
12515 }
12516
12517 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12518 /*
12519 * if the value is set to true previously and if someone is
12520 * trying to make it true again then it could be some race
12521 * condition being triggered. Avoid this situation by returning
12522 * false
12523 */
12524 if (hdd_ctx->connection_in_progress && value)
12525 status = false;
12526 else
12527 hdd_ctx->connection_in_progress = value;
12528 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12529 return status;
12530}
12531
Jeff Johnson9d295242017-08-29 14:39:48 -070012532int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012533{
12534 if (!adapter) {
12535 hdd_err("Invalid adapter");
12536 return -EINVAL;
12537 }
12538 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012539 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012540 WMA_VDEV_MCC_SET_TIME_QUOTA,
12541 set_value, VDEV_CMD);
12542 return 0;
12543
12544}
12545
Jeff Johnson9d295242017-08-29 14:39:48 -070012546int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012547{
12548 if (!adapter) {
12549 hdd_err("Invalid adapter");
12550 return -EINVAL;
12551 }
12552
12553 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012554 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012555 WMA_VDEV_MCC_SET_TIME_LATENCY,
12556 set_value, VDEV_CMD);
12557 return 0;
12558}
12559
Jeff Johnson9d295242017-08-29 14:39:48 -070012560struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012561 *psoc, uint8_t vdev_id)
12562{
Jeff Johnson9d295242017-08-29 14:39:48 -070012563 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012564 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012565
12566 /*
12567 * Currently PSOC is not being used. But this logic will
12568 * change once we have the converged implementation of
12569 * HDD context per PSOC in place. This would break if
12570 * multiple vdev objects reuse the vdev id.
12571 */
12572 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12573 if (!adapter)
12574 hdd_err("Get adapter by vdev id failed");
12575
12576 return adapter;
12577}
12578
Jeff Johnson9d295242017-08-29 14:39:48 -070012579int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012580 int8_t *rssi, int8_t *snr)
12581{
12582 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012583 struct hdd_wext_state *wext_state =
12584 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012585 tCsrRoamProfile *profile = &wext_state->roamProfile;
12586
12587 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12588 profile, bssid, rssi, snr);
12589 if (QDF_STATUS_SUCCESS != status) {
12590 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12591 return -EINVAL;
12592 }
12593
12594 return 0;
12595}
12596
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012597/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012598 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12599 * @adapter - HDD adapter
12600 * @tos - type of service
12601 * @status - status of the traffic
12602 *
12603 * Return: 0 on success and non zero value on failure
12604 */
12605
12606int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12607 bool is_tos_active)
12608{
12609 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012610 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012611 uint32_t max_off_chan_time = 0;
12612 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012613 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012614 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012615
12616 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12617 ret = wlan_hdd_validate_context(hdd_ctx);
12618
12619 if (ret < 0) {
12620 hdd_err("failed to set limit off chan params");
12621 return ret;
12622 }
12623
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012624 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12625
12626 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012627 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012628 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012629 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012630
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012631 if (adapter->active_ac) {
12632 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012633 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012634 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12635 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12636 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012637 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012638 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012639 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12640 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12641 PM_LATENCY);
12642 } else {
12643 /*ignore this command if only BE/BK is active */
12644 is_tos_active = false;
12645 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12646 hdd_ctx->config->conc_system_pref);
12647 }
12648 } else {
12649 /* No active tos */
12650 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12651 hdd_ctx->config->conc_system_pref);
12652 }
12653
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012654 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12655 is_tos_active, max_off_chan_time,
12656 hdd_ctx->config->nRestTimeConc, true);
12657 if (!QDF_IS_STATUS_SUCCESS(status)) {
12658 hdd_err("failed to set limit off chan params");
12659 ret = -EINVAL;
12660 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012661
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012662 return ret;
12663}
12664
12665/**
12666 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
12667 * @adapter - HDD adapter
12668 *
12669 * Return: 0 on success and non zero value on failure
12670 */
12671int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
12672{
12673 struct hdd_context *hdd_ctx;
12674 int ret;
12675 QDF_STATUS status;
12676 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
12677
12678 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12679 ret = wlan_hdd_validate_context(hdd_ctx);
12680 if (ret < 0)
12681 return ret;
12682
12683 /* set the system preferece to default */
12684 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12685 hdd_ctx->config->conc_system_pref);
12686
12687 /* clear the bitmap */
12688 adapter->active_ac = 0;
12689
12690 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
12691 adapter->sessionId, adapter->active_ac);
12692
12693 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12694 false, 0, 0, false);
12695 if (!QDF_IS_STATUS_SUCCESS(status)) {
12696 hdd_err("failed to reset limit off chan params");
12697 ret = -EINVAL;
12698 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012699
12700 return ret;
12701}
12702
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012703/**
12704 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12705 * @drv_op: Enum indicating driver op
12706 *
12707 * Return: none
12708 */
12709void hdd_start_driver_ops_timer(int drv_op)
12710{
12711 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12712 switch (drv_op) {
12713 case eHDD_DRV_OP_PROBE:
12714 memcpy(drv_ops_string, "probe", sizeof("probe"));
12715 break;
12716 case eHDD_DRV_OP_REMOVE:
12717 memcpy(drv_ops_string, "remove", sizeof("remove"));
12718 break;
12719 case eHDD_DRV_OP_SHUTDOWN:
12720 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12721 break;
12722 case eHDD_DRV_OP_REINIT:
12723 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12724 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053012725 case eHDD_DRV_OP_IFF_UP:
12726 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
12727 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012728 }
12729
12730 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12731 HDD_OPS_INACTIVITY_TIMEOUT);
12732}
12733
12734/**
12735 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12736 *
12737 * Return: none
12738 */
12739void hdd_stop_driver_ops_timer(void)
12740{
12741 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12742}
12743
12744/**
12745 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12746 * inactivity timer
12747 *
12748 * Return: None
12749 */
12750void hdd_drv_ops_inactivity_handler(void)
12751{
12752 hdd_err("%s: %d Sec timer expired while in .%s",
12753 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12754
12755 /* Driver shutdown is stuck, no recovery possible at this point */
12756 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12757 sizeof("shutdown")))
12758 QDF_BUG(0);
12759
12760 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012761 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012762 else
12763 QDF_BUG(0);
12764}
12765
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012766void hdd_pld_ipa_uc_shutdown_pipes(void)
12767{
12768 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12769
12770 if (!hdd_ctx)
12771 return;
12772
12773 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12774}
12775
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012776/* Register the module init/exit functions */
12777module_init(hdd_module_init);
12778module_exit(hdd_module_exit);
12779
12780MODULE_LICENSE("Dual BSD/GPL");
12781MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12782MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12783
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012784module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12785 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012786
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012787module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12788 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12789
Ravi Joshia307f632017-07-17 23:41:41 -070012790module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12791 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12792
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012793module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12794 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12795
12796module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12797
12798module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12799
12800module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);