blob: e607a01a7e1d1ca0b81b83bbac2ca74239580a70 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnsond9f08602016-12-02 11:31:30 -08002 * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_main.c
30 *
31 * WLAN Host Device Driver implementation
32 *
33 */
34
35/* Include Files */
36#include <wlan_hdd_includes.h>
37#include <cds_api.h>
38#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053039#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include <linux/etherdevice.h>
41#include <linux/firmware.h>
42#include <wlan_hdd_tx_rx.h>
43#include <wni_api.h>
44#include <wlan_hdd_cfg.h>
45#include <wlan_ptt_sock_svc.h>
46#include <dbglog_host.h>
47#include <wlan_logging_sock_svc.h>
48#include <wlan_hdd_wowl.h>
49#include <wlan_hdd_misc.h>
50#include <wlan_hdd_wext.h>
51#include "wlan_hdd_trace.h"
52#include "wlan_hdd_ioctl.h"
53#include "wlan_hdd_ftm.h"
54#include "wlan_hdd_power.h"
55#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070056#include "wlan_hdd_scan.h"
Jeff Johnsonce0032c2017-01-20 07:18:27 -080057#include "wlan_hdd_request_manager.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053058#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053059#include "qdf_trace.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070060#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080061#include <cdp_txrx_misc.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062
63#include <net/addrconf.h>
64#include <linux/wireless.h>
65#include <net/cfg80211.h>
66#include <linux/inetdevice.h>
67#include <net/addrconf.h>
68#include "wlan_hdd_cfg80211.h"
69#include "wlan_hdd_ext_scan.h"
70#include "wlan_hdd_p2p.h"
71#include <linux/rtnetlink.h>
72#include "sap_api.h"
73#include <linux/semaphore.h>
74#include <linux/ctype.h>
75#include <linux/compat.h>
76#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077#include <soc/qcom/subsystem_restart.h>
78#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#include <wlan_hdd_hostapd.h>
80#include <wlan_hdd_softap_tx_rx.h>
81#include "cfg_api.h"
82#include "qwlan_version.h"
83#include "wma_types.h"
84#include "wlan_hdd_tdls.h"
85#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053086#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070088#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070089#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080090#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#include "wlan_hdd_nan.h"
92#include "wlan_hdd_debugfs.h"
93#include "wlan_hdd_driver_ops.h"
94#include "epping_main.h"
95#include "wlan_hdd_memdump.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053096#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097
98#include <wlan_hdd_ipa.h>
99#include "hif.h"
100#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800101#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700102#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800103#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530104#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700105#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700106#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530107#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700108#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530109#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800110#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800111#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530112#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800113#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800114#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530115#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530116#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800117#include "os_if_wifi_pos.h"
118#include "wifi_pos_api.h"
119#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800120#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700121#include "os_if_nan.h"
122#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700123#include "wlan_reg_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700124#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530125#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530126#include "enet.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800127
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530128#ifdef CNSS_GENL
129#include <net/cnss_nl.h>
130#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800131#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530132
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800133#ifdef MODULE
134#define WLAN_MODULE_NAME module_name(THIS_MODULE)
135#else
136#define WLAN_MODULE_NAME "wlan"
137#endif
138
139#ifdef TIMER_MANAGER
140#define TIMER_MANAGER_STR " +TIMER_MANAGER"
141#else
142#define TIMER_MANAGER_STR ""
143#endif
144
145#ifdef MEMORY_DEBUG
146#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
147#else
148#define MEMORY_DEBUG_STR ""
149#endif
150
Sachin Ahujadddd2632017-03-07 19:07:24 +0530151int wlan_start_ret_val;
152static DECLARE_COMPLETION(wlan_start_comp);
153static unsigned int dev_num = 1;
154static struct cdev wlan_hdd_state_cdev;
155static struct class *class;
156static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530157#ifndef MODULE
158static struct gwlan_loader *wlan_loader;
159static ssize_t wlan_boot_cb(struct kobject *kobj,
160 struct kobj_attribute *attr,
161 const char *buf, size_t count);
162struct gwlan_loader {
163 bool loaded_state;
164 struct kobject *boot_wlan_obj;
165 struct attribute_group *attr_group;
166};
167
168static struct kobj_attribute wlan_boot_attribute =
169 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
170
171static struct attribute *attrs[] = {
172 &wlan_boot_attribute.attr,
173 NULL,
174};
175
176#define MODULE_INITIALIZED 1
177#endif
178
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530179#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
180#define MAX_OPS_NAME_STRING_SIZE 20
181
182static qdf_timer_t hdd_drv_ops_inactivity_timer;
183static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800185/* the Android framework expects this param even though we don't use it */
186#define BUF_LEN 20
187static char fwpath_buffer[BUF_LEN];
188static struct kparam_string fwpath = {
189 .string = fwpath_buffer,
190 .maxlen = BUF_LEN,
191};
192
193static char *country_code;
194static int enable_11d = -1;
195static int enable_dfs_chan_scan = -1;
196
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800197/*
198 * spinlock for synchronizing asynchronous request/response
199 * (full description of use in wlan_hdd_main.h)
200 */
201DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530202DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800203
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800204#define WLAN_NLINK_CESIUM 30
205
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530206static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800207
208#define WOW_MAX_FILTER_LISTS 1
209#define WOW_MAX_FILTERS_PER_LIST 4
210#define WOW_MIN_PATTERN_SIZE 6
211#define WOW_MAX_PATTERN_SIZE 64
212
213#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
214static const struct wiphy_wowlan_support wowlan_support_reg_init = {
215 .flags = WIPHY_WOWLAN_ANY |
216 WIPHY_WOWLAN_MAGIC_PKT |
217 WIPHY_WOWLAN_DISCONNECT |
218 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
219 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
220 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
221 WIPHY_WOWLAN_4WAY_HANDSHAKE |
222 WIPHY_WOWLAN_RFKILL_RELEASE,
223 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
224 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
225 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
226};
227#endif
228
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700229static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
230 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
231 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
232 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
233 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
234 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
235 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
236 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
237 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
242 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
243 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
244 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
245 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
246 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700264 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700265 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700266};
267
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530268int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
269 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
270 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
271 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
272 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
273};
274
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800275/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530276struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800277
278struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800279#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700280static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800281#endif
282
Sachin Ahujadddd2632017-03-07 19:07:24 +0530283void hdd_start_complete(int ret)
284{
285 wlan_start_ret_val = ret;
286
287 complete(&wlan_start_comp);
288}
289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800290/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530291 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700292 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530293 *
294 * Return: none
295 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700296static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530297{
Jeff Johnson9d295242017-08-29 14:39:48 -0700298 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530299 hdd_adapter_list_node_t *adapter_node, *next;
300 QDF_STATUS status = QDF_STATUS_SUCCESS;
301
302 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
303 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -0700304 adapter = adapter_node->adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530305 if (NULL != adapter)
306 hdd_send_rps_ind(adapter);
307 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
308 adapter_node = next;
309 }
310}
311
312/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800313 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
314 * @vdev_id: vdev_id
315 * @action: action type
316 * @reason: reason type
317 *
318 * Return: none
319 */
320void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
321 enum netif_action_type action, enum netif_reason_type reason)
322{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700323 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700324 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800325
326 if (!hdd_ctx) {
327 hdd_err("hdd ctx is NULL");
328 return;
329 }
330 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
331
332 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800333}
334
335/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700336 * Store WLAN driver version and timestamp info in global variables such that
337 * crash debugger can extract them from driver debug symbol and crashdump for
338 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800339 */
340uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700341
342#ifndef BUILD_TIMESTAMP
343#define BUILD_TIMESTAMP ""
344#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700345uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800346
347/**
348 * hdd_device_mode_to_string() - return string conversion of device mode
349 * @device_mode: device mode
350 *
351 * This utility function helps log string conversion of device mode.
352 *
353 * Return: string conversion of device mode, if match found;
354 * "Unknown" otherwise.
355 */
356const char *hdd_device_mode_to_string(uint8_t device_mode)
357{
358 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800359 CASE_RETURN_STRING(QDF_STA_MODE);
360 CASE_RETURN_STRING(QDF_SAP_MODE);
361 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
362 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
363 CASE_RETURN_STRING(QDF_FTM_MODE);
364 CASE_RETURN_STRING(QDF_IBSS_MODE);
365 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
366 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700367 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800368 default:
369 return "Unknown";
370 }
371}
372
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530373/**
374 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
375 * @adapter: HDD adapter
376 * @chan_number: Channel number
377 * @chan_bw: Bandwidth
378 *
379 * Checks if the given bandwidth is valid for the given channel number.
380 *
381 * Return: 0 for success, non-zero for failure
382 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700383int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530384 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800385 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530386{
387 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
388 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
389 bool found = false;
390 tHalHandle hal;
391
392 hal = WLAN_HDD_GET_HAL_CTX(adapter);
393 if (!hal) {
394 hdd_err("Invalid HAL context");
395 return -EINVAL;
396 }
397
398 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
399 hdd_err("No valid channel list");
400 return -EOPNOTSUPP;
401 }
402
403 for (i = 0; i < len; i++) {
404 if (chan[i] == chan_number) {
405 found = true;
406 break;
407 }
408 }
409
410 if (found == false) {
411 hdd_err("Channel not in driver's valid channel list");
412 return -EOPNOTSUPP;
413 }
414
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700415 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
416 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530417 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
418 return -EINVAL;
419 }
420
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700421 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530422 if (chan_bw == CH_WIDTH_80MHZ) {
423 hdd_err("BW80 not possible in 2.4GHz band");
424 return -EINVAL;
425 }
426 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
427 (chan_bw != CH_WIDTH_MAX)) {
428 hdd_err("Only BW20 possible on channel 14");
429 return -EINVAL;
430 }
431 }
432
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700433 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530434 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
435 (chan_bw != CH_WIDTH_MAX)) {
436 hdd_err("Only BW20 possible on channel 165");
437 return -EINVAL;
438 }
439 }
440
441 return 0;
442}
443
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530444/**
445 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
446 *
447 * Block the unloading of the driver (or) interface up until the
448 * cds recovery is completed
449 *
450 * Return: true for recovery completion else false
451 */
452static bool hdd_wait_for_recovery_completion(void)
453{
454 int retry = 0;
455
456 /* Wait for recovery to complete */
457 while (cds_is_driver_recovering()) {
458 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
459 hdd_err("Recovery in progress; wait here!!!");
460 msleep(1000);
461 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
462 hdd_err("SSR never completed, error");
463 /*
464 * Trigger the bug_on in the internal builds, in the
465 * customer builds self-recovery will be enabled
466 * in those cases just return error.
467 */
468 if (cds_is_self_recovery_enabled())
469 return false;
470 QDF_BUG(0);
471 }
472 }
473
474 hdd_info("Recovery completed successfully!");
475 return true;
476}
477
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800478static int __hdd_netdev_notifier_call(struct notifier_block *nb,
479 unsigned long state, void *data)
480{
481#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
482 struct netdev_notifier_info *dev_notif_info = data;
483 struct net_device *dev = dev_notif_info->dev;
484#else
485 struct net_device *dev = data;
486#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700487 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700488 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800489
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800490 ENTER_DEV(dev);
491
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800492 /* Make sure that this callback corresponds to our device. */
493 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
494 return NOTIFY_DONE;
495
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530496 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700498 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800499 return NOTIFY_DONE;
500 }
501
502 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700503 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800504 return NOTIFY_DONE;
505 }
506
507 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
508 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800509 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530510 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800511 return NOTIFY_DONE;
512 }
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530513 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800514 return NOTIFY_DONE;
515
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800516 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800517 dev->name, state);
518
519 switch (state) {
520 case NETDEV_REGISTER:
521 break;
522
523 case NETDEV_UNREGISTER:
524 break;
525
526 case NETDEV_UP:
527 sme_ch_avoid_update_req(hdd_ctx->hHal);
528 break;
529
530 case NETDEV_DOWN:
531 break;
532
533 case NETDEV_CHANGE:
534 if (true == adapter->isLinkUpSvcNeeded)
535 complete(&adapter->linkup_event_var);
536 break;
537
538 case NETDEV_GOING_DOWN:
539 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530540 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
541 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800542 } else {
hqueaa33ee2017-05-04 17:56:35 +0800543 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800544 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800545 }
546 break;
547
548 default:
549 break;
550 }
551
552 return NOTIFY_DONE;
553}
554
555/**
556 * hdd_netdev_notifier_call() - netdev notifier callback function
557 * @nb: pointer to notifier block
558 * @state: state
559 * @ndev: ndev pointer
560 *
561 * Return: 0 on success, error number otherwise.
562 */
563static int hdd_netdev_notifier_call(struct notifier_block *nb,
564 unsigned long state,
565 void *ndev)
566{
567 int ret;
568
569 cds_ssr_protect(__func__);
570 ret = __hdd_netdev_notifier_call(nb, state, ndev);
571 cds_ssr_unprotect(__func__);
572
573 return ret;
574}
575
576struct notifier_block hdd_netdev_notifier = {
577 .notifier_call = hdd_netdev_notifier_call,
578};
579
580/* variable to hold the insmod parameters */
581static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800582
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530583static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700584int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530585
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800586/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800587static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800588
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530589/**
590 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
591 * @ch_width: NL channel width
592 *
593 * Converts the NL channel width to the driver's internal representation
594 *
595 * Return: Converted channel width. In case of non matching NL channel width,
596 * CH_WIDTH_MAX will be returned.
597 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800598enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530599{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800600 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700601
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800602 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530603 switch (ch_width) {
604 case NL80211_CHAN_WIDTH_20_NOHT:
605 case NL80211_CHAN_WIDTH_20:
606 return CH_WIDTH_20MHZ;
607 case NL80211_CHAN_WIDTH_40:
608 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530609 case NL80211_CHAN_WIDTH_80:
610 return CH_WIDTH_80MHZ;
611 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800612 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
613 return CH_WIDTH_80P80MHZ;
614 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
615 return CH_WIDTH_160MHZ;
616 else
617 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530618 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800619 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
620 return CH_WIDTH_160MHZ;
621 else
622 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530623 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800624 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530625 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800626 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530627 default:
628 hdd_err("Invalid channel width %d, setting to default",
629 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800630 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530631 }
632}
633
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530634/* wlan_hdd_find_opclass() - Find operating class for a channel
635 * @hal: handler to HAL
636 * @channel: channel id
637 * @bw_offset: bandwidth offset
638 *
639 * Function invokes sme api to find the operating class
640 *
641 * Return: operating class
642 */
643uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
644 uint8_t bw_offset)
645{
646 uint8_t opclass = 0;
647
648 sme_get_opclass(hal, channel, bw_offset, &opclass);
649 return opclass;
650}
651
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800652/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530653 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530654 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800655 * @bitmask: Bitmask of log levels to be enabled
656 *
657 * Called immediately after the cfg.ini is read in order to configure
658 * the desired trace levels.
659 *
660 * Return: None
661 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530662int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800663{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530664 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530665 int qdf_print_idx = -1;
666 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800667 /*
668 * if the bitmask is the default value, then a bitmask was not
669 * specified in cfg.ini, so leave the logging level alone (it
670 * will remain at the "compiled in" default value)
671 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700672 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530673 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800674
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530675 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800676
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530677 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530678 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530679 QDF_TRACE_LEVEL_NONE, 0);
680
681 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530682 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800683 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530684 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800685 while (0 != bitmask) {
686 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530687 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530688 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530689 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530690 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700692
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693 level++;
694 bitmask >>= 1;
695 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530696 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800697}
698
699/**
Chris Guo1751acf2017-07-03 14:09:01 +0800700 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
701 * @hdd_ctx: HDD context pointer
702 *
703 * Return: 0 if the context is valid. Error code otherwise
704 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700705int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800706{
707 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
708 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
709 return -ENODEV;
710 }
711
712 if (cds_is_driver_recovering()) {
713 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
714 (void *)_RET_IP_, cds_get_driver_state());
715 return -EAGAIN;
716 }
717
718 if (hdd_ctx->start_modules_in_progress ||
719 hdd_ctx->stop_modules_in_progress) {
720 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
721 (void *)_RET_IP_);
722 return -EAGAIN;
723 }
724
725 return 0;
726}
727
728
729/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800730 * wlan_hdd_validate_context() - check the HDD context
731 * @hdd_ctx: HDD context pointer
732 *
733 * Return: 0 if the context is valid. Error code otherwise
734 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700735int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800737 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530738 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739 return -ENODEV;
740 }
741
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800742 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800743 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530744 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745 return -EAGAIN;
746 }
747
Srinivas Girigowda576b2352017-08-25 14:44:26 -0700748 if (cds_is_load_or_unload_in_progress())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800749 return -EAGAIN;
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530750
751 if (hdd_ctx->start_modules_in_progress ||
752 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800753 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530754 (void *)_RET_IP_);
755 return -EAGAIN;
756 }
757
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530758 if (cds_is_driver_in_bad_state()) {
759 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
760 (void *)_RET_IP_, cds_get_driver_state());
761 return -ENODEV;
762 }
763
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764 return 0;
765}
766
Jeff Johnson9d295242017-08-29 14:39:48 -0700767int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700768{
769 if (!adapter) {
770 hdd_err("adapter is null");
771 return -EINVAL;
772 }
773
774 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
775 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
776 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
777 return -EINVAL;
778 }
779
780 if (!adapter->dev) {
781 hdd_err("adapter net_device is null");
782 return -EINVAL;
783 }
784
785 if (!(adapter->dev->flags & IFF_UP)) {
786 hdd_info("adapter net_device is not up");
787 return -EAGAIN;
788 }
789
790 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
791 hdd_info("adapter session is not open");
792 return -EAGAIN;
793 }
794
795 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
796 hdd_err("bad adapter session Id: %u", adapter->sessionId);
797 return -EINVAL;
798 }
799
800 return 0;
801}
802
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530804 * wlan_hdd_validate_modules_state() - Check modules status
805 * @hdd_ctx: HDD context pointer
806 *
807 * Check's the driver module's state and returns true if the
808 * modules are enabled returns false if modules are closed.
809 *
810 * Return: True if modules are enabled or false.
811 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700812bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530813{
814 mutex_lock(&hdd_ctx->iface_change_lock);
815 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
816 mutex_unlock(&hdd_ctx->iface_change_lock);
817 hdd_notice("Modules not enabled, Present status: %d",
818 hdd_ctx->driver_status);
819 return false;
820 }
821 mutex_unlock(&hdd_ctx->iface_change_lock);
822 return true;
823}
824
825/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700827 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828 *
829 * This function sets the IBSS power save config parameters to WMA
830 * which will send it to firmware if FW supports IBSS power save
831 * before vdev start.
832 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530833 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834 * on failure.
835 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700836QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837{
838 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700839 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840
841 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700842 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530843 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800844 }
845
Naveen Rawat247a8682017-06-05 15:00:31 -0700846 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
848 hdd_ctx->config->ibssATIMWinSize,
849 VDEV_CMD);
850 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700851 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530852 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 }
854
Naveen Rawat247a8682017-06-05 15:00:31 -0700855 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
857 hdd_ctx->config->isIbssPowerSaveAllowed,
858 VDEV_CMD);
859 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700860 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
861 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530862 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 }
864
Naveen Rawat247a8682017-06-05 15:00:31 -0700865 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
867 hdd_ctx->config->
868 isIbssPowerCollapseAllowed, VDEV_CMD);
869 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700870 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
871 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530872 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873 }
874
Naveen Rawat247a8682017-06-05 15:00:31 -0700875 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
877 hdd_ctx->config->isIbssAwakeOnTxRx,
878 VDEV_CMD);
879 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700880 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530881 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800882 }
883
Naveen Rawat247a8682017-06-05 15:00:31 -0700884 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
886 hdd_ctx->config->ibssInactivityCount,
887 VDEV_CMD);
888 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700889 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530890 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800891 }
892
Naveen Rawat247a8682017-06-05 15:00:31 -0700893 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
895 hdd_ctx->config->ibssTxSpEndInactivityTime,
896 VDEV_CMD);
897 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700898 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
899 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530900 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 }
902
Naveen Rawat247a8682017-06-05 15:00:31 -0700903 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
905 hdd_ctx->config->ibssPsWarmupTime,
906 VDEV_CMD);
907 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700908 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
909 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530910 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 }
912
Naveen Rawat247a8682017-06-05 15:00:31 -0700913 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
915 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
916 VDEV_CMD);
917 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700918 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
919 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530920 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 }
922
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530923 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924}
925
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800926#define INTF_MACADDR_MASK 0x7
927
928/**
929 * hdd_update_macaddr() - update mac address
930 * @config: hdd configuration
931 * @hw_macaddr: mac address
932 *
933 * Mac address for multiple virtual interface is found as following
934 * i) The mac address of the first interface is just the actual hw mac address.
935 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
936 * define the mac address for the remaining interfaces and locally
937 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
938 * supported virtual interfaces, right now this is 0x07 (meaning 8
939 * interface).
940 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
941 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
942 *
943 * Return: None
944 */
945void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530946 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800947{
948 int8_t i;
949 uint8_t macaddr_b3, tmp_br3;
950
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530951 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530952 QDF_MAC_ADDR_SIZE);
953 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530954 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530955 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 macaddr_b3 = config->intfMacAddr[i].bytes[3];
957 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
958 INTF_MACADDR_MASK;
959 macaddr_b3 += tmp_br3;
960
961 /* XOR-ing bit-24 of the mac address. This will give enough
962 * mac address range before collision
963 */
964 macaddr_b3 ^= (1 << 7);
965
966 /* Set locally administered bit */
967 config->intfMacAddr[i].bytes[0] |= 0x02;
968 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800969 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800970 MAC_ADDRESS_STR, i,
971 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
972 }
973}
974
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700975static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800976 struct wma_tgt_services *cfg)
977{
978 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800979
980 /* Set up UAPSD */
981 config->apUapsdEnabled &= cfg->uapsd;
982
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800983 /* 11AX mode support */
984 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
985 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
986 config->dot11Mode = eHDD_DOT11_MODE_11ac;
987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988 /* 11AC mode support */
989 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
990 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
991 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992
993 /* ARP offload: override user setting if invalid */
994 config->fhostArpOffload &= cfg->arp_offload;
995
996#ifdef FEATURE_WLAN_SCAN_PNO
997 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800998 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999 if (cfg->pno_offload)
1000 config->PnoOffload = true;
1001#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002#ifdef FEATURE_WLAN_TDLS
1003 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301004 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1005 cfg->en_tdls_offchan;
1006 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1007 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001008 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001010 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001011 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1014 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1015#endif
Will Huang496b36c2017-07-11 16:38:50 +08001016 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001017 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018
1019}
1020
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001021/**
1022 * hdd_update_vdev_nss() - sets the vdev nss
1023 * @hdd_ctx: HDD context
1024 *
1025 * Sets the Nss per vdev type based on INI
1026 *
1027 * Return: None
1028 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001029static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001030{
1031 struct hdd_config *cfg_ini = hdd_ctx->config;
1032 uint8_t max_supp_nss = 1;
1033
Naveen Rawat10b1c152017-01-18 11:16:06 -08001034 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001035 max_supp_nss = 2;
1036
1037 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1038 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1039
1040 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1041 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1042}
1043
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301044/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301045 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1046 * @hdd_ctx: HDD context
1047 *
1048 * Updates wiphy vhtcap fields
1049 *
1050 * Return: None
1051 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001052static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301053{
1054 struct ieee80211_supported_band *band_5g =
1055 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1056 uint32_t val;
1057
1058 if (!band_5g) {
1059 hdd_debug("5GHz band disabled, skipping capability population");
1060 return;
1061 }
1062
1063 val = hdd_ctx->config->txBFCsnValue;
1064 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1065
1066 val = NUM_OF_SOUNDING_DIMENSIONS;
1067 band_5g->vht_cap.cap |=
1068 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1069
1070 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1071 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1072}
1073
1074/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301075 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1076 * @hdd_ctx: HDD context
1077 *
1078 * Sets the DBS capability as per INI and firmware capability
1079 *
1080 * Return: None
1081 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001082static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301083{
1084 struct hdd_config *cfg_ini = hdd_ctx->config;
1085 uint8_t hw_dbs_capable = 0;
1086
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001087 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1088 ((cfg_ini->dual_mac_feature_disable ==
1089 ENABLE_DBS_CXN_AND_SCAN) ||
1090 (cfg_ini->dual_mac_feature_disable ==
1091 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301092 hw_dbs_capable = 1;
1093
1094 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1095}
1096
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001097static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001098 struct wma_tgt_ht_cap *cfg)
1099{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301100 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001101 uint32_t value, val32;
1102 uint16_t val16;
1103 struct hdd_config *pconfig = hdd_ctx->config;
1104 tSirMacHTCapabilityInfo *phtCapInfo;
1105 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1106 uint8_t enable_tx_stbc;
1107
1108 /* check and update RX STBC */
1109 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1110 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1111
1112 /* get the MPDU density */
1113 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1114
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301115 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001116 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117 value = 0;
1118 }
1119
1120 /*
1121 * MPDU density:
1122 * override user's setting if value is larger
1123 * than the one supported by target
1124 */
1125 if (value > cfg->mpdu_density) {
1126 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1127 cfg->mpdu_density);
1128
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301129 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001130 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131 }
1132
1133 /* get the HT capability info */
1134 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301135 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001136 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001137 return;
1138 }
1139 val16 = (uint16_t) val32;
1140 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1141
1142 /* Set the LDPC capability */
1143 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1144
1145 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1146 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1147
1148 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1149 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1150
1151 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1152 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1153
1154 enable_tx_stbc = pconfig->enableTxSTBC;
1155
1156 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1157 pconfig->enable2x2 = 1;
1158 } else {
1159 pconfig->enable2x2 = 0;
1160 enable_tx_stbc = 0;
1161
1162 /* 1x1 */
1163 /* Update Rx Highest Long GI data Rate */
1164 if (sme_cfg_set_int(hdd_ctx->hHal,
1165 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001166 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301167 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001168 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001169 }
1170
1171 /* Update Tx Highest Long GI data Rate */
1172 if (sme_cfg_set_int
1173 (hdd_ctx->hHal,
1174 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001175 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301176 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001177 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178 }
1179 }
1180 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1181 enable_tx_stbc = 0;
1182 phtCapInfo->txSTBC = enable_tx_stbc;
1183
1184 val32 = val16;
1185 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301186 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001187 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001188#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1189 value = SIZE_OF_SUPPORTED_MCS_SET;
1190 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301191 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001192 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193
1194 if (pconfig->enable2x2) {
1195 for (value = 0; value < cfg->num_rf_chains; value++)
1196 mcs_set[value] =
1197 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1198
1199 status =
1200 sme_cfg_set_str(hdd_ctx->hHal,
1201 WNI_CFG_SUPPORTED_MCS_SET,
1202 mcs_set,
1203 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301204 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001205 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001206 }
1207 }
1208#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1209}
1210
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001211static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212 struct wma_tgt_vht_cap *cfg)
1213{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301214 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001215 uint32_t value = 0;
1216 struct hdd_config *pconfig = hdd_ctx->config;
1217 struct wiphy *wiphy = hdd_ctx->wiphy;
1218 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001219 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001220 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001221 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001222 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001223
Dustin Brown5e06bd32016-10-04 12:49:10 -07001224 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001225 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001226 return;
1227 }
1228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001229 /* Get the current MPDU length */
1230 status =
1231 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1232 &value);
1233
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301234 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001235 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 value = 0;
1237 }
1238
1239 /*
1240 * VHT max MPDU length:
1241 * override if user configured value is too high
1242 * that the target cannot support
1243 */
1244 if (value > cfg->vht_max_mpdu) {
1245 status = sme_cfg_set_int(hdd_ctx->hHal,
1246 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1247 cfg->vht_max_mpdu);
1248
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001249 if (status == QDF_STATUS_E_FAILURE)
1250 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251 }
1252
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001253 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1254 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1255
1256 if (pconfig->enable2x2)
1257 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1258
1259 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1260 QDF_STATUS_E_FAILURE) {
1261 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1262 }
1263
1264 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1265 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1266 if (pconfig->enable2x2)
1267 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1268
1269 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1270 QDF_STATUS_E_FAILURE) {
1271 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1272 }
1273
1274 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1275 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1276 if (pconfig->enable2x2)
1277 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1278
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001279 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001280 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1281
1282 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1283 QDF_STATUS_E_FAILURE) {
1284 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1285 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001286 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001287 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001288 &value);
1289
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301290 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001291 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001292 value = 0;
1293 }
1294
jiad4a7a33c2017-08-08 15:32:24 +08001295 /* Set HW RX LDPC capability */
1296 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1297 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001298 status = sme_cfg_set_int(hdd_ctx->hHal,
1299 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001300 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001301
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001302 if (status == QDF_STATUS_E_FAILURE)
1303 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001304 }
1305
1306 /* Get current GI 80 value */
1307 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1308 &value);
1309
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301310 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001311 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001312 value = 0;
1313 }
1314
1315 /* set the Guard interval 80MHz */
1316 if (value && !cfg->vht_short_gi_80) {
1317 status = sme_cfg_set_int(hdd_ctx->hHal,
1318 WNI_CFG_VHT_SHORT_GI_80MHZ,
1319 cfg->vht_short_gi_80);
1320
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001321 if (status == QDF_STATUS_E_FAILURE)
1322 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 }
1324
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325 /* Get VHT TX STBC cap */
1326 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1327
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301328 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001329 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001330 value = 0;
1331 }
1332
1333 /* VHT TX STBC cap */
1334 if (value && !cfg->vht_tx_stbc) {
1335 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1336 cfg->vht_tx_stbc);
1337
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001338 if (status == QDF_STATUS_E_FAILURE)
1339 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001340 }
1341
1342 /* Get VHT RX STBC cap */
1343 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1344
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301345 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001346 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 value = 0;
1348 }
1349
1350 /* VHT RX STBC cap */
1351 if (value && !cfg->vht_rx_stbc) {
1352 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1353 cfg->vht_rx_stbc);
1354
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001355 if (status == QDF_STATUS_E_FAILURE)
1356 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001357 }
1358
1359 /* Get VHT SU Beamformer cap */
1360 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1361 &value);
1362
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301363 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001364 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 value = 0;
1366 }
1367
1368 /* set VHT SU Beamformer cap */
1369 if (value && !cfg->vht_su_bformer) {
1370 status = sme_cfg_set_int(hdd_ctx->hHal,
1371 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1372 cfg->vht_su_bformer);
1373
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001374 if (status == QDF_STATUS_E_FAILURE)
1375 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001376 }
1377
1378 /* check and update SU BEAMFORMEE capabality */
1379 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1380 pconfig->enableTxBF = cfg->vht_su_bformee;
1381
1382 status = sme_cfg_set_int(hdd_ctx->hHal,
1383 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1384 pconfig->enableTxBF);
1385
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001386 if (status == QDF_STATUS_E_FAILURE)
1387 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001388
1389 /* Get VHT MU Beamformer cap */
1390 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1391 &value);
1392
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301393 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001394 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001395 value = 0;
1396 }
1397
1398 /* set VHT MU Beamformer cap */
1399 if (value && !cfg->vht_mu_bformer) {
1400 status = sme_cfg_set_int(hdd_ctx->hHal,
1401 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1402 cfg->vht_mu_bformer);
1403
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001404 if (status == QDF_STATUS_E_FAILURE)
1405 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406 }
1407
1408 /* Get VHT MU Beamformee cap */
1409 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1410 &value);
1411
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301412 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001413 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001414 value = 0;
1415 }
1416
1417 /* set VHT MU Beamformee cap */
1418 if (value && !cfg->vht_mu_bformee) {
1419 status = sme_cfg_set_int(hdd_ctx->hHal,
1420 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1421 cfg->vht_mu_bformee);
1422
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001423 if (status == QDF_STATUS_E_FAILURE)
1424 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001425 }
1426
1427 /* Get VHT MAX AMPDU Len exp */
1428 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1429 &value);
1430
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301431 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001432 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001433 value = 0;
1434 }
1435
1436 /*
1437 * VHT max AMPDU len exp:
1438 * override if user configured value is too high
1439 * that the target cannot support.
1440 * Even though Rome publish ampdu_len=7, it can
1441 * only support 4 because of some h/w bug.
1442 */
1443
1444 if (value > cfg->vht_max_ampdu_len_exp) {
1445 status = sme_cfg_set_int(hdd_ctx->hHal,
1446 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1447 cfg->vht_max_ampdu_len_exp);
1448
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001449 if (status == QDF_STATUS_E_FAILURE)
1450 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451 }
1452
1453 /* Get VHT TXOP PS CAP */
1454 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1455
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301456 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001457 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 value = 0;
1459 }
1460
1461 /* set VHT TXOP PS cap */
1462 if (value && !cfg->vht_txop_ps) {
1463 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1464 cfg->vht_txop_ps);
1465
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001466 if (status == QDF_STATUS_E_FAILURE)
1467 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 }
1469
1470 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1471 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1472 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1473 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1474 else
1475 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1476
1477
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001478 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1479 status = sme_cfg_set_int(hdd_ctx->hHal,
1480 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1481 VHT_CAP_160_AND_80P80_SUPP);
1482 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001483 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001484 band_5g->vht_cap.cap |=
1485 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001486 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1487 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1488 status = sme_cfg_set_int(hdd_ctx->hHal,
1489 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1490 VHT_CAP_160_SUPP);
1491 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001492 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001493 band_5g->vht_cap.cap |=
1494 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001495 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1496 }
1497 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1498 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301499 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001500 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301501 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001502 &value);
1503 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301504 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001505 value = 0;
1506 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301507 /* set the Guard interval 160MHz */
1508 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001509 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301510 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1511 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001512
1513 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301514 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001515 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516
1517 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1518 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1519
1520 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1521 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1522 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1523 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1524
1525 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1526 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1527
1528 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1529 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1530 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1531 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1532 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1533 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1534
1535 band_5g->vht_cap.cap |=
1536 (cfg->vht_max_ampdu_len_exp <<
1537 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1538
1539 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1540 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1541 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1542 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1543 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1544 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1545 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1546 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1547
1548 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1549 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1550
1551}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001553/**
1554 * hdd_generate_macaddr_auto() - Auto-generate mac address
1555 * @hdd_ctx: Pointer to the HDD context
1556 *
1557 * Auto-generate mac address using device serial number.
1558 * Keep the first 3 bytes of OUI as before and replace
1559 * the last 3 bytes with the lower 3 bytes of serial number.
1560 *
1561 * Return: 0 for success
1562 * Non zero failure code for errors
1563 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001564static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001565{
1566 unsigned int serialno = 0;
1567 struct qdf_mac_addr mac_addr = {
1568 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1569 };
1570
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001571 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001572 if (serialno == 0)
1573 return -EINVAL;
1574
1575 serialno &= 0x00ffffff;
1576
1577 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1578 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1579 mac_addr.bytes[5] = serialno & 0xff;
1580
1581 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1582 return 0;
1583}
1584
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301585/**
1586 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1587 * configuration to cfg_ini in HDD
1588 * @hdd_ctx: Pointer to hdd_ctx
1589 * @cfg: target configuration
1590 *
1591 * Return: None
1592 */
1593#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001594static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301595 struct wma_tgt_cfg *cfg)
1596{
1597 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1598}
1599#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001600static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301601 struct wma_tgt_cfg *cfg)
1602{
1603}
1604#endif
1605
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001606void hdd_update_tgt_cfg(void *context, void *param)
1607{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001608 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001609 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001610 struct wma_tgt_cfg *cfg = param;
1611 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001612 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301613 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301614
Yue Mae3e86ab2017-05-08 10:48:24 -07001615 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301616 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1617 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1618 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1619 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1620 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001621 /* Restore pdev to MAC/WMA contexts */
1622 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001623 } else {
1624 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1625 if (ret) {
1626 hdd_err("pdev creation fails!");
1627 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301628 } else
1629 hdd_debug("New pdev has been created with pdev_id = %u",
1630 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301631 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001632
Naveen Rawat64e477e2016-05-20 10:34:56 -07001633 if (cds_cfg) {
1634 if (hdd_ctx->config->enable_sub_20_channel_width !=
1635 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1636 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1637 cds_cfg->sub_20_channel_width =
1638 WLAN_SUB_20_CH_WIDTH_NONE;
1639 } else {
1640 cds_cfg->sub_20_channel_width =
1641 hdd_ctx->config->enable_sub_20_channel_width;
1642 }
1643 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644
1645 /* first store the INI band capability */
1646 temp_band_cap = hdd_ctx->config->nBandCapability;
1647
1648 hdd_ctx->config->nBandCapability = cfg->band_cap;
1649
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001650 /*
1651 * now overwrite the target band capability with INI
1652 * setting if INI setting is a subset
1653 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001654
1655 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1656 (temp_band_cap != eCSR_BAND_ALL))
1657 hdd_ctx->config->nBandCapability = temp_band_cap;
1658 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1659 (temp_band_cap != eCSR_BAND_ALL) &&
1660 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001661 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001662 }
1663
Amar Singhal58b45ef2017-08-01 13:43:54 -07001664 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1665
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301666 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001667 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1668 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1669 }
1670
1671 /* This can be extended to other configurations like ht, vht cap... */
1672
Anurag Chouhanc5548422016-02-24 18:33:27 +05301673 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001675 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001677 static struct qdf_mac_addr default_mac_addr = {
1678 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1679 };
1680 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1681 &default_mac_addr)) {
1682 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1683 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1684 MAC_ADDRESS_STR,
1685 MAC_ADDR_ARRAY(hdd_ctx->config->
1686 intfMacAddr[0].bytes));
1687 } else {
1688 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1689 MAC_ADDRESS_STR,
1690 MAC_ADDR_ARRAY(hdd_ctx->config->
1691 intfMacAddr[0].bytes));
1692 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001693 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 }
1695
1696 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001697 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001698
1699 hdd_ctx->max_intf_count = cfg->max_intf_count;
1700
Jeff Johnsonc875e242016-09-23 18:12:34 -07001701 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001702 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001703
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1705 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1706
1707 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1708
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001709 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001710 if (cfg->services.en_11ax) {
1711 hdd_info("11AX: 11ax is enabled - update HDD config");
1712 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1713 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001714
1715 hdd_update_vdev_nss(hdd_ctx);
1716
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301717 hdd_update_hw_dbs_capable(hdd_ctx);
1718
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001719 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001720 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001721 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001722 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001723
Nitesh Shahe50711f2017-04-26 16:30:45 +05301724 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1725 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1726 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001727 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001728 hdd_ctx->current_antenna_mode);
1729
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001730 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1731 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301732 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301733
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301734 if ((hdd_ctx->config->txBFCsnValue >
1735 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1736 !cfg->tx_bfee_8ss_enabled)
1737 hdd_ctx->config->txBFCsnValue =
1738 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1739
1740 if (sme_cfg_set_int(hdd_ctx->hHal,
1741 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1742 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1743 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1744
1745
1746 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1747 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1748 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301749
1750 /*
1751 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1752 */
1753 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301754
1755 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1756
Arun Khandavallid454d422016-08-17 12:47:05 +05301757 /*
1758 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1759 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1760 * configure the STA mode wow pattern.
1761 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301762 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301763 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301764
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301765 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1766
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001767 /* Configure NAN datapath features */
1768 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001769 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001770}
1771
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001772bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001773{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001774 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001775 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301776 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001777 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001778
Arif Hussaincd151632017-02-11 16:57:19 -08001779 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001780 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001781 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301782 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001783 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784
Arif Hussaincd151632017-02-11 16:57:19 -08001785 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1786 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001787 adapter = adapterNode->adapter;
Arif Hussaincd151632017-02-11 16:57:19 -08001788 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1789
1790 if ((QDF_SAP_MODE == adapter->device_mode ||
1791 QDF_P2P_GO_MODE == adapter->device_mode) &&
1792 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1793 ap_ctx->operatingChannel))) {
1794 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1795 true;
1796 hdd_info("tx blocked for session: %d",
1797 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301798 }
Arif Hussaincd151632017-02-11 16:57:19 -08001799 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1800 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001801 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301802
1803 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001804}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001805
1806/**
1807 * hdd_is_valid_mac_address() - validate MAC address
1808 * @pMacAddr: Pointer to the input MAC address
1809 *
1810 * This function validates whether the given MAC address is valid or not
1811 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1812 * where X is the hexa decimal digit character and separated by ':'
1813 * This algorithm works even if MAC address is not separated by ':'
1814 *
1815 * This code checks given input string mac contains exactly 12 hexadecimal
1816 * digits and a separator colon : appears in the input string only after
1817 * an even number of hex digits.
1818 *
1819 * Return: 1 for valid and 0 for invalid
1820 */
1821bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1822{
1823 int xdigit = 0;
1824 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001825
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001826 while (*pMacAddr) {
1827 if (isxdigit(*pMacAddr)) {
1828 xdigit++;
1829 } else if (':' == *pMacAddr) {
1830 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1831 break;
1832
1833 ++separator;
1834 } else {
1835 /* Invalid MAC found */
1836 return 0;
1837 }
1838 ++pMacAddr;
1839 }
1840 return xdigit == 12 && (separator == 5 || separator == 0);
1841}
1842
1843/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301844 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1845 * @dev: Handle to struct net_device to be updated.
1846 *
1847 * Return: None
1848 */
1849static void hdd_mon_mode_ether_setup(struct net_device *dev)
1850{
1851 dev->header_ops = NULL;
1852 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1853 dev->hard_header_len = ETH_HLEN;
1854 dev->mtu = ETH_DATA_LEN;
1855 dev->addr_len = ETH_ALEN;
1856 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1857 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1858 dev->priv_flags |= IFF_TX_SKB_SHARING;
1859
1860 memset(dev->broadcast, 0xFF, ETH_ALEN);
1861}
1862
1863/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001864 * __hdd__mon_open() - HDD Open function
1865 * @dev: Pointer to net_device structure
1866 *
1867 * This is called in response to ifconfig up
1868 *
1869 * Return: 0 for success; non-zero for failure
1870 */
1871static int __hdd_mon_open(struct net_device *dev)
1872{
1873 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001874 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1875 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001876
1877 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001878
1879 ret = wlan_hdd_validate_context(hdd_ctx);
1880 if (ret)
1881 return ret;
1882
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301883 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001884
1885 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1886 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1887 if (ret) {
1888 hdd_err("Failed to start WLAN modules return");
1889 return ret;
1890 }
1891 hdd_err("hdd_wlan_start_modules() successful !");
1892
1893 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1894 ret = hdd_start_adapter(adapter);
1895 if (ret) {
1896 hdd_err("Failed to start adapter :%d",
1897 adapter->device_mode);
1898 return ret;
1899 }
1900 hdd_err("hdd_start_adapters() successful !");
1901 }
1902 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1903 }
1904
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001905 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001906
1907 if (!ret)
1908 ret = hdd_enable_monitor_mode(dev);
1909
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001910 return ret;
1911}
1912
1913/**
1914 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1915 * @dev: Pointer to net_device structure
1916 *
1917 * This is called in response to ifconfig up
1918 *
1919 * Return: 0 for success; non-zero for failure
1920 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001921static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001922{
1923 int ret;
1924
1925 cds_ssr_protect(__func__);
1926 ret = __hdd_mon_open(dev);
1927 cds_ssr_unprotect(__func__);
1928
1929 return ret;
1930}
1931
1932/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301933 * hdd_start_adapter() - Wrapper function for device specific adapter
1934 * @adapter: pointer to HDD adapter
1935 *
1936 * This function is called to start the device specific adapter for
1937 * the mode passed in the adapter's device_mode.
1938 *
1939 * Return: 0 for success; non-zero for failure
1940 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001941int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05301942{
1943
1944 int ret;
1945 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1946
1947 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001948 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301949
1950 switch (device_mode) {
1951 case QDF_P2P_CLIENT_MODE:
1952 case QDF_P2P_DEVICE_MODE:
1953 case QDF_OCB_MODE:
1954 case QDF_STA_MODE:
1955 case QDF_MONITOR_MODE:
1956 ret = hdd_start_station_adapter(adapter);
1957 if (ret)
1958 goto err_start_adapter;
1959 break;
1960 case QDF_P2P_GO_MODE:
1961 case QDF_SAP_MODE:
1962 ret = hdd_start_ap_adapter(adapter);
1963 if (ret)
1964 goto err_start_adapter;
1965 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301966 case QDF_IBSS_MODE:
1967 /*
1968 * For IBSS interface is initialized as part of
1969 * hdd_init_station_mode()
1970 */
1971 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301972 case QDF_FTM_MODE:
1973 ret = hdd_start_ftm_adapter(adapter);
1974 if (ret)
1975 goto err_start_adapter;
1976 break;
1977 default:
1978 hdd_err("Invalid session type %d", device_mode);
1979 QDF_ASSERT(0);
1980 goto err_start_adapter;
1981 }
1982 if (hdd_set_fw_params(adapter))
1983 hdd_err("Failed to set the FW params for the adapter!");
1984
1985 /*
1986 * Action frame registered in one adapter which will
1987 * applicable to all interfaces
1988 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05301989 ret = wlan_hdd_cfg80211_register_frames(adapter);
1990 if (ret < 0) {
1991 hdd_err("Failed to register frames - ret %d", ret);
1992 goto err_start_adapter;
1993 }
1994
Arun Khandavallifae92942016-08-01 13:31:08 +05301995 EXIT();
1996 return 0;
1997err_start_adapter:
1998 return -EINVAL;
1999}
2000
2001/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302002 * hdd_enable_power_management() - API to Enable Power Management
2003 *
2004 * API invokes Bus Interface Layer power management functionality
2005 *
2006 * Return: None
2007 */
2008static void hdd_enable_power_management(void)
2009{
2010 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2011
2012 if (!hif_ctx) {
2013 hdd_err("Bus Interface Context is Invalid");
2014 return;
2015 }
2016
2017 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2018}
2019
2020/**
2021 * hdd_disable_power_management() - API to disable Power Management
2022 *
2023 * API disable Bus Interface Layer Power management functionality
2024 *
2025 * Return: None
2026 */
2027static void hdd_disable_power_management(void)
2028{
2029 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2030
2031 if (!hif_ctx) {
2032 hdd_err("Bus Interface Context is Invalid");
2033 return;
2034 }
2035
2036 hif_disable_power_management(hif_ctx);
2037}
2038
2039/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302040 * hdd_update_hw_sw_info() - API to update the HW/SW information
2041 *
2042 * API to update the HW and SW information in the driver
2043 *
2044 * Return: None
2045 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002046static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302047{
2048 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002049 size_t target_hw_name_len;
2050 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302051
2052 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2053 if (!hif_sc) {
2054 hdd_err("HIF context is NULL");
2055 return;
2056 }
2057
2058 /*
2059 * target hw version/revision would only be retrieved after firmware
2060 * download
2061 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002062 hif_get_hw_info(hif_sc,
2063 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302064 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002065 &target_hw_name);
2066
2067 if (hdd_ctx->target_hw_name)
2068 qdf_mem_free(hdd_ctx->target_hw_name);
2069
2070 target_hw_name_len = strlen(target_hw_name) + 1;
2071 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2072 if (hdd_ctx->target_hw_name)
2073 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2074 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302075
2076 /* Get the wlan hw/fw version */
2077 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302078}
2079
2080/**
gbian62edd7e2017-03-07 13:12:13 +08002081 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2082 * @hdd_ctx: Pointer to hdd context
2083 *
2084 * Return: none
2085 */
2086static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002087hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002088{
2089 uint8_t num_entries = 0;
2090 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2091 uint8_t *tx_sched_wrr_ac;
2092 int i;
2093 cds_context_type *cds_ctx;
2094
2095 if (NULL == hdd_ctx)
2096 return;
2097
2098 if (NULL == hdd_ctx->config) {
2099 /* Do nothing if hdd_ctx is invalid */
2100 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2101 return;
2102 }
2103
2104 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2105
2106 if (!cds_ctx) {
2107 hdd_err("Invalid CDS Context");
2108 return;
2109 }
2110
2111 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2112 switch (i) {
2113 case OL_TX_WMM_AC_BE:
2114 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2115 break;
2116 case OL_TX_WMM_AC_BK:
2117 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2118 break;
2119 case OL_TX_WMM_AC_VI:
2120 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2121 break;
2122 case OL_TX_WMM_AC_VO:
2123 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2124 break;
2125 default:
2126 tx_sched_wrr_ac = NULL;
2127 break;
2128 }
2129
2130 hdd_string_to_u8_array(tx_sched_wrr_ac,
2131 tx_sched_wrr_param,
2132 &num_entries,
2133 sizeof(tx_sched_wrr_param));
2134
2135 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2136 cds_ctx->ac_specs[i].wrr_skip_weight =
2137 tx_sched_wrr_param[0];
2138 cds_ctx->ac_specs[i].credit_threshold =
2139 tx_sched_wrr_param[1];
2140 cds_ctx->ac_specs[i].send_limit =
2141 tx_sched_wrr_param[2];
2142 cds_ctx->ac_specs[i].credit_reserve =
2143 tx_sched_wrr_param[3];
2144 cds_ctx->ac_specs[i].discard_weight =
2145 tx_sched_wrr_param[4];
2146 }
2147
2148 num_entries = 0;
2149 }
2150}
2151
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002152#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002153static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2154 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2155{
Jeff Johnson9d295242017-08-29 14:39:48 -07002156 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002157 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002158
2159 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2160 if (!adapter) {
2161 hdd_err("Adapter is NULL");
2162 return PM_MAX_NUM_OF_MODE;
2163 }
2164
2165 return policy_mgr_convert_device_mode_to_qdf_type(
2166 adapter->device_mode);
2167}
2168
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002169static void hdd_register_policy_manager_callback(
2170 struct wlan_objmgr_psoc *psoc)
2171{
2172 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002173
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002174 hdd_cbacks.sap_restart_chan_switch_cb =
2175 sap_restart_chan_switch_cb;
2176 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2177 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002178 hdd_cbacks.get_mode_for_non_connected_vdev =
2179 wlan_hdd_get_mode_for_non_connected_vdev;
2180
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002181 if (QDF_STATUS_SUCCESS !=
2182 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2183 hdd_err("HDD callback registration with policy manager failed");
2184 }
2185}
2186#else
2187static void hdd_register_policy_manager_callback(
2188 struct wlan_objmgr_psoc *psoc)
2189{
2190}
2191#endif
2192
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002193#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002194static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002195{
2196 struct nan_callbacks cb_obj = {0};
2197
2198 cb_obj.ndi_open = hdd_ndi_open;
2199 cb_obj.ndi_close = hdd_ndi_close;
2200 cb_obj.ndi_start = hdd_ndi_start;
2201 cb_obj.ndi_delete = hdd_ndi_delete;
2202 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2203 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2204
Naveen Rawat37f62c82017-03-26 22:24:43 -07002205 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2206 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002207 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002208
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002209 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2210}
2211#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002212static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002213{
2214}
2215#endif
2216
gbian62edd7e2017-03-07 13:12:13 +08002217/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302218 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2219 * @hdd_ctx: HDD context
2220 * @adapter: HDD adapter
2221 * @reinit: flag to indicate from SSR or normal path
2222 *
2223 * This function maintains the driver state machine it will be invoked from
2224 * startup, reinit and change interface. Depending on the driver state shall
2225 * perform the opening of the modules.
2226 *
2227 * Return: 0 for success; non-zero for failure
2228 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002229int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2230 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302231 bool reinit)
2232{
2233 int ret;
2234 qdf_device_t qdf_dev;
2235 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302236 bool unint = false;
2237 void *hif_ctx;
2238
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002239 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302240
2241 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2242 if (!qdf_dev) {
2243 hdd_err("QDF Device Context is Invalid return");
2244 return -EINVAL;
2245 }
2246
2247 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302248 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302249
2250 if (QDF_TIMER_STATE_RUNNING ==
2251 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2252
2253 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002254 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302255 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2256 }
2257
2258 switch (hdd_ctx->driver_status) {
2259 case DRIVER_MODULES_UNINITIALIZED:
2260 unint = true;
2261 /* Fall through dont add break here */
2262 case DRIVER_MODULES_CLOSED:
2263 if (!reinit && !unint) {
2264 ret = pld_power_on(qdf_dev->dev);
2265 if (ret) {
2266 hdd_err("Failed to Powerup the device: %d", ret);
2267 goto release_lock;
2268 }
2269 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002270
2271 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2272 hdd_ctx->config->enable_fw_log);
2273
Arun Khandavallifae92942016-08-01 13:31:08 +05302274 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2275 qdf_dev->bus_type,
2276 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2277 HIF_ENABLE_TYPE_PROBE);
2278 if (ret) {
2279 hdd_err("Failed to open hif: %d", ret);
2280 goto power_down;
2281 }
2282
2283 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302284 if (!hif_ctx) {
2285 hdd_err("hif context is null!!");
2286 goto power_down;
2287 }
2288
Arun Khandavallifae92942016-08-01 13:31:08 +05302289 status = ol_cds_init(qdf_dev, hif_ctx);
2290 if (status != QDF_STATUS_SUCCESS) {
2291 hdd_err("No Memory to Create BMI Context :%d", status);
2292 goto hif_close;
2293 }
2294
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002295 ret = hdd_update_config(hdd_ctx);
2296 if (ret) {
2297 hdd_err("Failed to update configuration :%d", ret);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002298 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002299 }
2300
gbian62edd7e2017-03-07 13:12:13 +08002301 hdd_update_cds_ac_specs_params(hdd_ctx);
2302
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302303 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302304 if (!QDF_IS_STATUS_SUCCESS(status)) {
2305 hdd_err("Failed to Open CDS: %d", status);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002306 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302307 }
2308
Mukul Sharma9d797a02017-01-05 20:26:03 +05302309 /* initalize components configurations after psoc open */
2310 ret = hdd_update_components_config(hdd_ctx);
2311 if (ret) {
2312 hdd_err("Failed to update components configs :%d",
2313 ret);
2314 goto close;
2315 }
2316
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002317 /*
2318 * NAN compoenet requires certian operations like, open adapter,
2319 * close adapter, etc. to be initiated by HDD, for those
2320 * register HDD callbacks with UMAC's NAN componenet.
2321 */
2322 hdd_nan_register_callbacks(hdd_ctx);
2323
Arun Khandavallifae92942016-08-01 13:31:08 +05302324 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2325
Jeff Johnson3a280122017-09-13 07:42:00 -07002326 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302327 if (!QDF_IS_STATUS_SUCCESS(status)) {
2328 hdd_err("Failed to pre-enable CDS: %d", status);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002329 goto close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302330 }
2331
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002332 hdd_register_policy_manager_callback(
2333 hdd_ctx->hdd_psoc);
2334
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302335 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302336 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302337
Arun Khandavallifae92942016-08-01 13:31:08 +05302338 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2339 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2340 hdd_ftm_mc_process_msg);
2341 break;
2342 }
2343 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002344 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302345 break;
2346 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302347
2348 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002349 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2350 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002351 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002352 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302353 }
2354
Arun Khandavallifae92942016-08-01 13:31:08 +05302355 /* Fall through dont add break here */
2356 case DRIVER_MODULES_OPENED:
2357 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002358 hdd_alert("adapter is Null");
2359 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302360 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302361 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2362 hdd_err("in ftm mode, no need to configure cds modules");
2363 break;
2364 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302365 if (hdd_configure_cds(hdd_ctx, adapter)) {
2366 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002367 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302368 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302369 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302370 hdd_info("Driver Modules Successfully Enabled");
2371 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2372 break;
2373 case DRIVER_MODULES_ENABLED:
2374 hdd_info("Driver modules already Enabled");
2375 break;
2376 default:
2377 hdd_err("WLAN start invoked in wrong state! :%d\n",
2378 hdd_ctx->driver_status);
2379 goto release_lock;
2380 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302381 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302382 mutex_unlock(&hdd_ctx->iface_change_lock);
2383 EXIT();
2384 return 0;
2385
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002386post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002387 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002388
Arun Khandavallifae92942016-08-01 13:31:08 +05302389close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002390 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002391 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302392
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002393ol_cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302394 ol_cds_free();
2395
2396hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002397 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2398 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302399power_down:
2400 if (!reinit && !unint)
2401 pld_power_off(qdf_dev->dev);
2402release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302403 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302404 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302405 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002406
Arun Khandavallifae92942016-08-01 13:31:08 +05302407 return -EINVAL;
2408}
2409
Naveen Rawat910726a2017-03-06 11:42:51 -08002410#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002411static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002412{
2413 int ret = os_if_wifi_pos_register_nl();
2414
2415 if (ret)
2416 hdd_err("os_if_wifi_pos_register_nl failed");
2417
2418 return ret;
2419}
2420
2421static int hdd_deactivate_wifi_pos(void)
2422{
2423 int ret = os_if_wifi_pos_deregister_nl();
2424
2425 if (ret)
2426 hdd_err("os_if_wifi_pos_deregister_nl failed");
2427
2428 return ret;
2429}
2430
2431/**
2432 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2433 * @hdd_ctx: hdd context
2434 *
2435 * Return: status of operation
2436 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002437static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002438{
2439 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2440 struct hdd_config *cfg = hdd_ctx->config;
2441
2442 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2443 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2444 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2445 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2446 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2447 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2448 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2449 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2450}
2451#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002452static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002453{
2454 return oem_activate_service(hdd_ctx);
2455}
2456
2457static int hdd_deactivate_wifi_pos(void)
2458{
2459 return 0;
2460}
2461
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002462static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002463{
2464}
2465#endif
2466
Arun Khandavallifae92942016-08-01 13:31:08 +05302467/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002468 * __hdd_open() - HDD Open function
2469 * @dev: Pointer to net_device structure
2470 *
2471 * This is called in response to ifconfig up
2472 *
2473 * Return: 0 for success; non-zero for failure
2474 */
2475static int __hdd_open(struct net_device *dev)
2476{
Jeff Johnson9d295242017-08-29 14:39:48 -07002477 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002478 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002479 int ret;
2480
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002481 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302482 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302483 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002484
Arunk Khandavallie1b3a382017-09-26 12:01:26 +05302485 if (!hdd_wait_for_recovery_completion()) {
2486 hdd_err("Recovery failed");
2487 return -EIO;
2488 }
2489
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302490 /* Nothing to be done if device is unloading */
2491 if (cds_is_driver_unloading()) {
2492 hdd_err("Driver is unloading can not open the hdd");
2493 return -EBUSY;
2494 }
2495
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302496 mutex_lock(&hdd_init_deinit_lock);
2497
2498 /*
2499 * This scenario can be hit in cases where in the wlan driver after
2500 * registering the netdevices and there is a failure in driver
2501 * initialization. So return error gracefully because the netdevices
2502 * will be de-registered as part of the load failure.
2503 */
2504
2505 if (!cds_is_driver_loaded()) {
2506 hdd_err("Failed to start the wlan driver!!");
2507 ret = -EIO;
2508 goto err_hdd_hdd_init_deinit_lock;
2509 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302510
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002511
Arun Khandavallifae92942016-08-01 13:31:08 +05302512 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2513 if (ret) {
2514 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302515 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302516 }
2517
2518
2519 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2520 ret = hdd_start_adapter(adapter);
2521 if (ret) {
2522 hdd_err("Failed to start adapter :%d",
2523 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302524 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302525 }
2526 }
2527
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002528 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2529 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002530 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002531 /* Enable TX queues only when we are connected */
2532 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302533 WLAN_START_ALL_NETIF_QUEUE,
2534 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002535 }
2536
Naveen Rawat286def52016-09-23 15:38:02 -07002537 /* Enable carrier and transmit queues for NDI */
2538 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002539 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002540 wlan_hdd_netif_queue_control(adapter,
2541 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2542 WLAN_CONTROL_PATH);
2543 }
2544
Naveen Rawat910726a2017-03-06 11:42:51 -08002545 hdd_populate_wifi_pos_cfg(hdd_ctx);
2546
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302547err_hdd_hdd_init_deinit_lock:
2548 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002549 return ret;
2550}
2551
Arun Khandavallifae92942016-08-01 13:31:08 +05302552
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002553/**
2554 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2555 * @dev: Pointer to net_device structure
2556 *
2557 * This is called in response to ifconfig up
2558 *
2559 * Return: 0 for success; non-zero for failure
2560 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002561static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002562{
2563 int ret;
2564
2565 cds_ssr_protect(__func__);
2566 ret = __hdd_open(dev);
2567 cds_ssr_unprotect(__func__);
2568
2569 return ret;
2570}
2571
2572/**
2573 * __hdd_stop() - HDD stop function
2574 * @dev: Pointer to net_device structure
2575 *
2576 * This is called in response to ifconfig down
2577 *
2578 * Return: 0 for success; non-zero for failure
2579 */
2580static int __hdd_stop(struct net_device *dev)
2581{
Jeff Johnson9d295242017-08-29 14:39:48 -07002582 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002583 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002584 int ret;
2585
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002586 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002587
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302588 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002589 adapter->sessionId, adapter->device_mode));
2590
2591 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302592 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002593 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002594
2595 /* Nothing to be done if the interface is not opened */
2596 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002597 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002598 return -ENODEV;
2599 }
2600
2601 /* Make sure the interface is marked as closed */
2602 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302603
2604 hdd_debug("Disabling Auto Power save timer");
2605 sme_ps_disable_auto_ps_timer(
2606 WLAN_HDD_GET_HAL_CTX(adapter),
2607 adapter->sessionId);
2608
2609 /*
2610 * Disable TX on the interface, after this hard_start_xmit() will not
2611 * be called on that interface
2612 */
2613 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302614 wlan_hdd_netif_queue_control(adapter,
2615 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2616 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002617
2618 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002619 * NAN data interface is different in some sense. The traffic on NDI is
2620 * bursty in nature and depends on the need to transfer. The service
2621 * layer may down the interface after the usage and up again when
2622 * required. In some sense, the NDI is expected to be available
2623 * (like SAP) iface until NDI delete request is issued by the service
2624 * layer. Skip BSS termination and adapter deletion for NAN Data
2625 * interface (NDI).
2626 */
2627 if (WLAN_HDD_IS_NDI(adapter))
2628 return 0;
2629
2630 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002631 * The interface is marked as down for outside world (aka kernel)
2632 * But the driver is pretty much alive inside. The driver needs to
2633 * tear down the existing connection on the netdev (session)
2634 * cleanup the data pipes and wait until the control plane is stabilized
2635 * for this interface. The call also needs to wait until the above
2636 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002637 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002638 * That is intentional to be able to scan if it is a STA/P2P interface
2639 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302640 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002641
2642 /* DeInit the adapter. This ensures datapath cleanup as well */
2643 hdd_deinit_adapter(hdd_ctx, adapter, true);
2644
Arun Khandavallifae92942016-08-01 13:31:08 +05302645
2646 /*
2647 * Find if any iface is up. If any iface is up then can't put device to
2648 * sleep/power save mode
2649 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302650 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002651 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302652 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302653 hdd_ctx->config->iface_change_wait_time);
Arun Khandavallifae92942016-08-01 13:31:08 +05302654 }
2655
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002656 EXIT();
2657 return 0;
2658}
2659
2660/**
2661 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2662 * @dev: pointer to net_device structure
2663 *
2664 * This is called in response to ifconfig down
2665 *
2666 * Return: 0 for success and error number for failure
2667 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002668static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002669{
2670 int ret;
2671
2672 cds_ssr_protect(__func__);
2673 ret = __hdd_stop(dev);
2674 cds_ssr_unprotect(__func__);
2675
2676 return ret;
2677}
2678
2679/**
2680 * __hdd_uninit() - HDD uninit function
2681 * @dev: Pointer to net_device structure
2682 *
2683 * This is called during the netdev unregister to uninitialize all data
2684 * associated with the device
2685 *
2686 * Return: None
2687 */
2688static void __hdd_uninit(struct net_device *dev)
2689{
Jeff Johnson9d295242017-08-29 14:39:48 -07002690 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002691 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002692
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002693 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002694
2695 do {
2696 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002697 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002698 break;
2699 }
2700
Jeff Johnson399c6272017-08-30 10:51:00 -07002701 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2702 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002703 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002704 break;
2705 }
2706
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002707 if (dev != adapter->dev)
2708 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002709
Jeff Johnson399c6272017-08-30 10:51:00 -07002710 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711
2712 /* after uninit our adapter structure will no longer be valid */
2713 adapter->dev = NULL;
2714 adapter->magic = 0;
2715 } while (0);
2716
2717 EXIT();
2718}
2719
2720/**
2721 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2722 * @dev: pointer to net_device structure
2723 *
2724 * This is called during the netdev unregister to uninitialize all data
2725 * associated with the device
2726 *
2727 * Return: none
2728 */
2729static void hdd_uninit(struct net_device *dev)
2730{
2731 cds_ssr_protect(__func__);
2732 __hdd_uninit(dev);
2733 cds_ssr_unprotect(__func__);
2734}
2735
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002736static int hdd_open_cesium_nl_sock(void)
2737{
2738#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2739 struct netlink_kernel_cfg cfg = {
2740 .groups = WLAN_NLINK_MCAST_GRP_ID,
2741 .input = NULL
2742 };
2743#endif
2744 int ret = 0;
2745
2746#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2747 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2748#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2749 THIS_MODULE,
2750#endif
2751 &cfg);
2752#else
2753 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2754 WLAN_NLINK_MCAST_GRP_ID,
2755 NULL, NULL, THIS_MODULE);
2756#endif
2757
2758 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002759 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002760 ret = -ECONNREFUSED;
2761 }
2762
2763 return ret;
2764}
2765
2766static void hdd_close_cesium_nl_sock(void)
2767{
2768 if (NULL != cesium_nl_srv_sock) {
2769 netlink_kernel_release(cesium_nl_srv_sock);
2770 cesium_nl_srv_sock = NULL;
2771 }
2772}
2773
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002774/**
2775 * __hdd_set_mac_address() - set the user specified mac address
2776 * @dev: Pointer to the net device.
2777 * @addr: Pointer to the sockaddr.
2778 *
2779 * This function sets the user specified mac address using
2780 * the command ifconfig wlanX hw ether <mac adress>.
2781 *
2782 * Return: 0 for success, non zero for failure
2783 */
2784static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2785{
Jeff Johnson9d295242017-08-29 14:39:48 -07002786 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002787 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002788 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302789 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002790 int ret;
2791
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002792 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002793
2794 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2795 ret = wlan_hdd_validate_context(hdd_ctx);
2796 if (0 != ret)
2797 return ret;
2798
2799 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2800 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2801
2802 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302803 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002804}
2805
2806/**
2807 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2808 * function from SSR
2809 * @dev: pointer to net_device structure
2810 * @addr: Pointer to the sockaddr
2811 *
2812 * This function sets the user specified mac address using
2813 * the command ifconfig wlanX hw ether <mac adress>.
2814 *
2815 * Return: 0 for success.
2816 */
2817static int hdd_set_mac_address(struct net_device *dev, void *addr)
2818{
2819 int ret;
2820
2821 cds_ssr_protect(__func__);
2822 ret = __hdd_set_mac_address(dev, addr);
2823 cds_ssr_unprotect(__func__);
2824
2825 return ret;
2826}
2827
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002828uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002829{
2830 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002831
Anurag Chouhan6d760662016-02-20 16:05:43 +05302832 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002833 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2834 break;
2835 }
2836
Anurag Chouhan6d760662016-02-20 16:05:43 +05302837 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002838 return NULL;
2839
2840 hdd_ctx->config->intfAddrMask |= (1 << i);
2841 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2842}
2843
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002844void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx, uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002845{
2846 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002847
Anurag Chouhan6d760662016-02-20 16:05:43 +05302848 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002849 if (!memcmp(releaseAddr,
2850 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2851 6)) {
2852 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2853 break;
2854 }
2855 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002856}
2857
2858#ifdef WLAN_FEATURE_PACKET_FILTERING
2859/**
2860 * __hdd_set_multicast_list() - set the multicast address list
2861 * @dev: Pointer to the WLAN device.
2862 * @skb: Pointer to OS packet (sk_buff).
2863 *
2864 * This funciton sets the multicast address list.
2865 *
2866 * Return: None
2867 */
2868static void __hdd_set_multicast_list(struct net_device *dev)
2869{
Jeff Johnson9d295242017-08-29 14:39:48 -07002870 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002871 int i = 0, status;
2872 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002873 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302874 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2875 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2876 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002877
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002878 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302879 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302880 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302881
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002882 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302883 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302884 goto out;
2885
Dustin Brownc788acb2017-08-01 17:43:51 -07002886 status = hdd_validate_adapter(adapter);
2887 if (status)
2888 goto out;
2889
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302890 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2891 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002892 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302893 goto out;
2894 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002895
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302896 /* Delete already configured multicast address list */
2897 if (adapter->mc_addr_list.mc_cnt > 0) {
2898 hdd_info("clear previously configured MC address list");
2899 hdd_disable_and_flush_mc_addr_list(adapter,
2900 pmo_mc_list_change_notify);
2901 }
2902
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002904 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302905 hdd_disable_and_flush_mc_addr_list(adapter,
2906 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002907 } else {
2908 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302909 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002910 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302911 pmo_ucfg_max_mc_addr_supported(psoc));
2912 hdd_disable_and_flush_mc_addr_list(adapter,
2913 pmo_mc_list_change_notify);
2914 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002915 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002916 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002917 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302918 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002919 if (i == mc_count)
2920 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302921 memset(&(mc_list_request->mc_addr[i].bytes),
2922 0, ETH_ALEN);
2923 memcpy(&(mc_list_request->mc_addr[i].bytes),
2924 ha->addr, ETH_ALEN);
2925 hdd_info("mlist[%d] = %pM", i,
2926 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002927 i++;
2928 }
2929 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302930
2931 mc_list_request->psoc = psoc;
2932 mc_list_request->vdev_id = adapter->sessionId;
2933 mc_list_request->count = mc_count;
2934 status = hdd_cache_mc_addr_list(mc_list_request);
2935 if (status == 0) {
2936 hdd_enable_mc_addr_filtering(adapter,
2937 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002938 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302939 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002940 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302941out:
2942 if (mc_list_request)
2943 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302944 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002945}
2946
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302947
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002948/**
2949 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2950 * @dev: pointer to net_device
2951 *
2952 * Return: none
2953 */
2954static void hdd_set_multicast_list(struct net_device *dev)
2955{
2956 cds_ssr_protect(__func__);
2957 __hdd_set_multicast_list(dev);
2958 cds_ssr_unprotect(__func__);
2959}
2960#endif
2961
2962/**
2963 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2964 * @dev: Pointer to the WLAN device.
2965 * @skb: Pointer to OS packet (sk_buff).
2966 *
2967 * This function is registered with the Linux OS for network
2968 * core to decide which queue to use first.
2969 *
2970 * Return: ac, Queue Index/access category corresponding to UP in IP header
2971 */
2972static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2973#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2974 , void *accel_priv
2975#endif
2976#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2977 , select_queue_fallback_t fallback
2978#endif
2979)
2980{
2981 return hdd_wmm_select_queue(dev, skb);
2982}
2983
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002984static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002985 .ndo_open = hdd_open,
2986 .ndo_stop = hdd_stop,
2987 .ndo_uninit = hdd_uninit,
2988 .ndo_start_xmit = hdd_hard_start_xmit,
2989 .ndo_tx_timeout = hdd_tx_timeout,
2990 .ndo_get_stats = hdd_get_stats,
2991 .ndo_do_ioctl = hdd_ioctl,
2992 .ndo_set_mac_address = hdd_set_mac_address,
2993 .ndo_select_queue = hdd_select_queue,
2994#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002995 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002996#endif
2997};
2998
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002999/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003000static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003001 .ndo_open = hdd_mon_open,
3002 .ndo_stop = hdd_stop,
3003 .ndo_get_stats = hdd_get_stats,
3004};
3005
3006/**
3007 * hdd_set_station_ops() - update net_device ops for monitor mode
3008 * @pWlanDev: Handle to struct net_device to be updated.
3009 * Return: None
3010 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003011void hdd_set_station_ops(struct net_device *pWlanDev)
3012{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003013 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
3014 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
3015 else
3016 pWlanDev->netdev_ops = &wlan_drv_ops;
3017}
3018
Komal Seelama89be8d2016-09-29 11:09:26 +05303019#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05303020/**
3021 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
3022 * @hdd_ctx: HDD context
3023 *
3024 * Return: None
3025 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003026static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05303027{
3028 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
3029
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003030 qdf_runtime_lock_init(&ctx->roc);
3031 qdf_runtime_lock_init(&ctx->dfs);
Komal Seelam8634b772016-09-29 12:12:24 +05303032}
3033
3034/**
3035 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
3036 * @hdd_ctx: HDD Context
3037 *
3038 * Return: None
3039 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003040static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05303041{
3042 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
3043
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003044 qdf_runtime_lock_deinit(&ctx->roc);
3045 qdf_runtime_lock_deinit(&ctx->dfs);
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05303046
3047 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05303048}
3049
Jeff Johnson9d295242017-08-29 14:39:48 -07003050static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05303051{
3052 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
3053
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003054 qdf_runtime_lock_init(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05303055}
3056
Jeff Johnson9d295242017-08-29 14:39:48 -07003057static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05303058{
3059 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
3060
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003061 qdf_runtime_lock_deinit(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05303062}
3063#else /* FEATURE_RUNTIME_PM */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003064static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
3065static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Jeff Johnson9d295242017-08-29 14:39:48 -07003066static inline void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
3067static inline void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05303068#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003069/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003070 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3071 * @hdd_ctx: global hdd context
3072 * @macAddr: mac address to assign to the interface
3073 * @name: User-visible name of the interface
3074 *
3075 * hdd adapter pointer would point to the netdev->priv space, this function
3076 * would retrive the pointer, and setup the hdd adapter configuration.
3077 *
3078 * Return: the pointer to hdd adapter, otherwise NULL
3079 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003080static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003081 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003082 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003083 const char *name)
3084{
3085 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003086 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003087 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003088 /*
3089 * cfg80211 initialization and registration....
3090 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003091 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003092#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3093 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003094#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003095 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3096 hdd_mon_mode_ether_setup : ether_setup),
3097 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003098
3099 if (pWlanDev != NULL) {
3100
3101 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003102 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003103
Jeff Johnson9d295242017-08-29 14:39:48 -07003104 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303105 sta_ctx = &adapter->sessionCtx.station;
3106 qdf_mem_set(sta_ctx->conn_info.staId,
3107 sizeof(sta_ctx->conn_info.staId),
3108 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003109 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003110 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003111 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303112 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003113
3114 init_completion(&adapter->session_open_comp_var);
3115 init_completion(&adapter->session_close_comp_var);
3116 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303117 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003118 init_completion(&adapter->linkup_event_var);
3119 init_completion(&adapter->cancel_rem_on_chan_var);
3120 init_completion(&adapter->rem_on_chan_ready_event);
3121 init_completion(&adapter->sta_authorized_event);
3122 init_completion(&adapter->offchannel_tx_event);
3123 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003124 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003125 init_completion(&adapter->change_country_code);
3126
3127
3128 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303129 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003130
3131 adapter->offloads_configured = false;
3132 adapter->isLinkUpSvcNeeded = false;
3133 adapter->higherDtimTransition = true;
3134 /* Init the net_device structure */
3135 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3136
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303137 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303139 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003140 sizeof(tSirMacAddr));
3141 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003142
3143 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3144 pWlanDev->features |=
3145 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3146 pWlanDev->features |= NETIF_F_RXCSUM;
3147
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003148 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3149
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150 hdd_set_station_ops(adapter->dev);
3151
Dustin Brownc81dd412017-08-15 16:26:28 -07003152 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003154 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003155 adapter->wdev.wiphy = hdd_ctx->wiphy;
3156 adapter->wdev.netdev = pWlanDev;
3157 /* set pWlanDev's parent to underlying device */
3158 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3159 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303160 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003161 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303162 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003163 }
3164
3165 return adapter;
3166}
3167
Jeff Johnson9d295242017-08-29 14:39:48 -07003168static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003170 struct net_device *dev = adapter->dev;
3171 int ret;
3172
3173 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003174
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003175 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003176 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3177
3178 ret = dev_alloc_name(dev, dev->name);
3179 if (ret < 0) {
3180 hdd_err(
3181 "unable to get dev name: %s, err = 0x%x",
3182 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303183 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003184 }
3185 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003186
3187 ret = register_netdevice(dev);
3188 if (ret) {
3189 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3190 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303191 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192 }
3193 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003194 ret = register_netdev(dev);
3195 if (ret) {
3196 hdd_err("register_netdev(%s) failed, err = 0x%x",
3197 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303198 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199 }
3200 }
3201 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3202
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003203 EXIT();
3204
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303205 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206}
3207
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003208QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003209{
Jeff Johnson9d295242017-08-29 14:39:48 -07003210 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211
3212 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003213 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303214 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215 }
3216
3217 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003218 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303219 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220 }
3221
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003222 /*
3223 * For NAN Data interface, the close session results in the final
3224 * indication to the userspace
3225 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003226 if (adapter->device_mode == QDF_NDI_MODE)
3227 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003229 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3230
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003231 /*
3232 * We can be blocked while waiting for scheduled work to be
3233 * flushed, and the adapter structure can potentially be freed, in
3234 * which case the magic will have been reset. So make sure the
3235 * magic is still good, and hence the adapter structure is still
3236 * valid, before signaling completion
3237 */
3238 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3239 complete(&adapter->session_close_comp_var);
3240
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303241 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003242}
3243
Jeff Johnson9d295242017-08-29 14:39:48 -07003244int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003245{
Dustin Brownd28772b2017-03-17 14:16:07 -07003246 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003247
Dustin Brownd28772b2017-03-17 14:16:07 -07003248 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003249 if (QDF_IS_STATUS_ERROR(status))
3250 return qdf_status_to_os_return(status);
3251
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003252 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003253 if (QDF_IS_STATUS_ERROR(status))
3254 return qdf_status_to_os_return(status);
3255
3256 if (wma_capability_enhanced_mcast_filter())
3257 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3258 else
3259 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003260
3261 return qdf_status_to_os_return(status);
3262}
3263
Jeff Johnson9d295242017-08-29 14:39:48 -07003264int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003265{
3266 QDF_STATUS status;
3267 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003268 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003269 unsigned long rc;
3270
3271 hdd_info("destroying vdev %d", adapter->sessionId);
3272
3273 /* vdev created sanity check */
3274 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3275 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3276 return -EINVAL;
3277 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003278 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003279 /*
3280 * In SSR case, there is no need to destroy vdev in firmware since
3281 * it has already asserted. vdev can be released directly.
3282 */
3283 if (cds_is_driver_recovering())
3284 goto release_vdev;
3285
Dustin Brownd28772b2017-03-17 14:16:07 -07003286 /* close sme session (destroy vdev in firmware via legacy API) */
3287 INIT_COMPLETION(adapter->session_close_comp_var);
3288 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3289 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3290 hdd_sme_close_session_callback, adapter);
3291 if (QDF_IS_STATUS_ERROR(status)) {
3292 hdd_err("failed to close sme session: %d", status);
3293 return qdf_status_to_os_return(status);
3294 }
3295
3296 /* block on a completion variable until sme session is closed */
3297 rc = wait_for_completion_timeout(
3298 &adapter->session_close_comp_var,
3299 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3300 if (!rc) {
3301 hdd_err("timed out waiting for close sme session: %ld", rc);
3302 if (adapter->device_mode == QDF_NDI_MODE)
3303 hdd_ndp_session_end_handler(adapter);
3304 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3305 return -ETIMEDOUT;
3306 }
Yue Maf9782842017-05-08 12:49:49 -07003307release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003308 /* do vdev logical destroy via objmgr */
3309 errno = hdd_objmgr_destroy_vdev(adapter);
3310 if (errno) {
3311 hdd_err("failed to destroy objmgr vdev: %d", errno);
3312 return errno;
3313 }
3314
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003315 /* now that sme session is closed, allow physical vdev destroy */
3316 errno = hdd_objmgr_release_vdev(adapter);
3317 if (errno) {
3318 hdd_err("failed to release objmgr vdev: %d", errno);
3319 return errno;
3320 }
3321
Dustin Brownd28772b2017-03-17 14:16:07 -07003322 hdd_info("vdev destroyed successfully");
3323
3324 return 0;
3325}
3326
Jeff Johnson9d295242017-08-29 14:39:48 -07003327int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003328{
3329 QDF_STATUS status;
3330 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003331 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003332 uint32_t type;
3333 uint32_t sub_type;
3334 unsigned long rc;
3335
3336 hdd_info("creating new vdev");
3337
3338 /* determine vdev (sub)type */
3339 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303340 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003341 hdd_err("failed to get vdev type: %d", status);
3342 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003343 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003344
3345 /* do vdev create via objmgr */
3346 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003347 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003348 if (errno) {
3349 hdd_err("failed to create objmgr vdev: %d", errno);
3350 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003351 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003352
3353 /* Open a SME session (prepare vdev in firmware via legacy API) */
3354 INIT_COMPLETION(adapter->session_open_comp_var);
3355 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3356 (uint8_t *)&adapter->macAddressCurrent,
3357 adapter->sessionId, type, sub_type);
3358 if (QDF_IS_STATUS_ERROR(status)) {
3359 hdd_err("failed to open sme session: %d", status);
3360 errno = qdf_status_to_os_return(status);
3361 goto objmgr_vdev_destroy;
3362 }
3363
3364 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003365 rc = wait_for_completion_timeout(
3366 &adapter->session_open_comp_var,
3367 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3368 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003369 hdd_err("timed out waiting for open sme session: %ld", rc);
3370 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303371 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3372 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003373 }
3374
3375 /* firmware ready for component communication, raise vdev_ready event */
3376 errno = hdd_vdev_ready(adapter);
3377 if (errno) {
3378 hdd_err("failed to dispatch vdev ready event: %d", errno);
3379 goto hdd_vdev_destroy;
3380 }
3381
3382 hdd_info("vdev %d created successfully", adapter->sessionId);
3383
3384 return 0;
3385
3386 /*
3387 * Due to legacy constraints, we need to destroy in the same order as
3388 * create. So, split error handling into 2 cases to accommodate.
3389 */
3390
3391objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003392 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003393
3394 return errno;
3395
3396hdd_vdev_destroy:
3397 QDF_BUG(!hdd_vdev_destroy(adapter));
3398
3399 return errno;
3400}
3401
Jeff Johnson9d295242017-08-29 14:39:48 -07003402QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003403{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003404 struct hdd_station_ctx *sta_ctx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003405 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003406 QDF_STATUS status;
3407 int ret_val;
3408
3409 ret_val = hdd_vdev_create(adapter);
3410 if (ret_val) {
3411 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303412 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003413 }
3414
Dustin Brownd28772b2017-03-17 14:16:07 -07003415 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3416 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3417 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003418 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003419
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003420 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003421 status = hdd_register_wext(adapter->dev);
3422 if (QDF_IS_STATUS_ERROR(status)) {
3423 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003424 goto error_register_wext;
3425 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003426 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003427
Jeff Johnsond377dce2017-10-04 10:32:42 -07003428 qdf_mem_set(sta_ctx->conn_info.staId,
3429 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303430
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003431 /* set fast roaming capability in sme session */
3432 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3433 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003435 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436 hdd_ctx->config->OperatingChannel;
3437
3438 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003439 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440
3441 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303442 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003443 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444 status, status);
3445 goto error_init_txrx;
3446 }
3447
3448 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3449
3450 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303451 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003452 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453 status, status);
3454 goto error_wmm_init;
3455 }
3456
3457 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3458
Naveen Rawat247a8682017-06-05 15:00:31 -07003459 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 WMI_PDEV_PARAM_BURST_ENABLE,
3461 hdd_ctx->config->enableSifsBurst,
3462 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003463 if (ret_val)
3464 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003466 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303467 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469error_wmm_init:
3470 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3471 hdd_deinit_tx_rx(adapter);
3472error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003473 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003475 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477 return status;
3478}
3479
Jeff Johnson9d295242017-08-29 14:39:48 -07003480void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003481{
Jeff Johnson5e4b93c2017-09-30 18:09:16 -07003482 struct hdd_cfg80211_state *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483
3484 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3485
3486 if (NULL != cfgState->buf) {
3487 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003488
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489 rc = wait_for_completion_timeout(
3490 &adapter->tx_action_cnf_event,
3491 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3492 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003493 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303494 /*
3495 * Inform tx status as FAILURE to upper layer and free
3496 * cfgState->buf
3497 */
3498 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499 }
3500 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501}
3502
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303503/**
3504 * hdd_station_adapter_deinit() - De-initialize the station adapter
3505 * @hdd_ctx: global hdd context
3506 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003507 * @rtnl_held: Used to indicate whether or not the caller is holding
3508 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303509 *
3510 * This function De-initializes the STA/P2P/OCB adapter.
3511 *
3512 * Return: None.
3513 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003514static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003515 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003516 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303517{
3518 ENTER_DEV(adapter->dev);
3519
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303520 if (adapter->dev) {
3521 if (rtnl_held)
3522 adapter->dev->wireless_handlers = NULL;
3523 else {
3524 rtnl_lock();
3525 adapter->dev->wireless_handlers = NULL;
3526 rtnl_unlock();
3527 }
3528 }
3529
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303530 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3531 hdd_deinit_tx_rx(adapter);
3532 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3533 }
3534
3535 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3536 hdd_wmm_adapter_close(adapter);
3537 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3538 }
3539
3540 hdd_cleanup_actionframe(hdd_ctx, adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303541
3542 EXIT();
3543}
3544
3545/**
3546 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3547 * @hdd_ctx: global hdd context
3548 * @adapter: HDD adapter
3549 * @rtnl_held: the rtnl lock hold flag
3550 * This function De-initializes the AP/P2PGo adapter.
3551 *
3552 * Return: None.
3553 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003554static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003555 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003556 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303557{
3558 ENTER_DEV(adapter->dev);
3559
3560 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3561 hdd_wmm_adapter_close(adapter);
3562 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3563 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003564 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303565
3566 hdd_cleanup_actionframe(hdd_ctx, adapter);
3567
3568 hdd_unregister_hostapd(adapter, rtnl_held);
3569
3570 EXIT();
3571}
3572
Jeff Johnson9d295242017-08-29 14:39:48 -07003573void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003574 bool rtnl_held)
3575{
3576 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303577
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003578 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003579 case QDF_STA_MODE:
3580 case QDF_P2P_CLIENT_MODE:
3581 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003582 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303583 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584 break;
3585 }
3586
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003587 case QDF_SAP_MODE:
3588 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589 {
3590
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303591 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592 break;
3593 }
3594
3595 default:
3596 break;
3597 }
3598
3599 EXIT();
3600}
3601
Jeff Johnson9d295242017-08-29 14:39:48 -07003602static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003603 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604{
3605 struct net_device *pWlanDev = NULL;
3606
3607 if (adapter)
3608 pWlanDev = adapter->dev;
3609 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003610 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003611 return;
3612 }
3613
Rajeev Kumardca5f812016-02-04 17:28:06 -08003614 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303615
3616 if (adapter->scan_info.default_scan_ies) {
3617 qdf_mem_free(adapter->scan_info.default_scan_ies);
3618 adapter->scan_info.default_scan_ies = NULL;
3619 }
3620
Komal Seelama89be8d2016-09-29 11:09:26 +05303621 hdd_adapter_runtime_suspend_denit(adapter);
3622
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003623 /*
3624 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3625 * the driver is almost closed and cannot handle either control
3626 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003627 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3628 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003629 * is not right. Setting this flag helps hdd_stop() to recognize that
3630 * the interface is closed and restricts any operations on that
3631 */
3632 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3633
3634 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003635 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003636 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003637 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003638 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003639 /*
3640 * Note that the adapter is no longer valid at this point
3641 * since the memory has been reclaimed
3642 */
3643 }
3644}
3645
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003646static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003647 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003648{
3649 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003650 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303651 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003652
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303654 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003655 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303657 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003658 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303659 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 }
3661 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3662 adapterNode = pNext;
3663 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303664 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003666
Arun Khandavalli2358d522016-05-16 18:05:37 +05303667#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3668/**
3669 * hdd_set_fw_log_params() - Set log parameters to FW
3670 * @hdd_ctx: HDD Context
3671 * @adapter: HDD Adapter
3672 *
3673 * This function set the FW Debug log level based on the INI.
3674 *
3675 * Return: None
3676 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003677static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003678 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303679{
3680 uint8_t count = 0, numentries = 0,
3681 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3682 uint32_t value = 0;
3683 int ret;
3684
Arun Khandavallifae92942016-08-01 13:31:08 +05303685 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3686 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003687 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303688 return;
3689 }
3690
Arun Khandavallifae92942016-08-01 13:31:08 +05303691 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303692 hdd_ctx->fw_log_settings.dl_type =
3693 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003694 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303695 WMI_DBGLOG_TYPE,
3696 hdd_ctx->config->enableFwLogType,
3697 DBG_CMD);
3698 if (ret != 0)
3699 hdd_err("Failed to enable FW log type ret %d",
3700 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303701
3702 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303703 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003704 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303705 WMI_DBGLOG_LOG_LEVEL,
3706 hdd_ctx->config->enableFwLogLevel,
3707 DBG_CMD);
3708 if (ret != 0)
3709 hdd_err("Failed to enable FW log level ret %d",
3710 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303711
3712 hdd_string_to_u8_array(
3713 hdd_ctx->config->enableFwModuleLogLevel,
3714 moduleloglevel,
3715 &numentries,
3716 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3717
3718 while (count < numentries) {
3719 /*
3720 * FW module log level input string looks like
3721 * below:
3722 * gFwDebugModuleLoglevel=<FW Module ID>,
3723 * <Log Level>,...
3724 * For example:
3725 * gFwDebugModuleLoglevel=
3726 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3727 * Above input string means :
3728 * For FW module ID 1 enable log level 0
3729 * For FW module ID 2 enable log level 1
3730 * For FW module ID 3 enable log level 2
3731 * For FW module ID 4 enable log level 3
3732 * For FW module ID 5 enable log level 4
3733 * For FW module ID 6 enable log level 5
3734 * For FW module ID 7 enable log level 6
3735 */
3736
Nishank Aggarwale239d962017-03-03 12:26:02 +05303737 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3738 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3739 hdd_err("Module id %d and dbglog level %d input length is more than max",
3740 moduleloglevel[count],
3741 moduleloglevel[count + 1]);
3742 return;
3743 }
3744
3745 value = moduleloglevel[count] << 16;
3746 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003747 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303748 WMI_DBGLOG_MOD_LOG_LEVEL,
3749 value, DBG_CMD);
3750 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303751 hdd_err("Failed to enable FW module log level %d ret %d",
3752 value, ret);
3753
3754 count += 2;
3755 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303756
Arun Khandavalli2358d522016-05-16 18:05:37 +05303757}
3758#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003759static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003760 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303761{
3762}
3763
3764#endif
3765
3766/**
3767 * hdd_set_fw_params() - Set parameters to firmware
3768 * @adapter: HDD adapter
3769 *
3770 * This function Sets various parameters to fw once the
3771 * adapter is started.
3772 *
3773 * Return: 0 on success or errno on failure
3774 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003775int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303776{
3777 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003778 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303779
3780 ENTER_DEV(adapter->dev);
3781
3782 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3783 if (!hdd_ctx)
3784 return -EINVAL;
3785
Dustin Brown732ab9c2017-06-15 13:24:09 -07003786 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3787 hdd_debug("FTM Mode is active; nothing to do");
3788 return 0;
3789 }
3790
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303791 ret = sme_cli_set_command(adapter->sessionId,
3792 WMI_PDEV_PARAM_DTIM_SYNTH,
3793 hdd_ctx->config->enable_lprx, PDEV_CMD);
3794 if (ret) {
3795 hdd_err("Failed to set LPRx");
3796 goto error;
3797 }
3798
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303799 if (adapter->device_mode == QDF_STA_MODE) {
3800 sme_set_smps_cfg(adapter->sessionId,
3801 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3802 hdd_ctx->config->upper_brssi_thresh);
3803
3804 sme_set_smps_cfg(adapter->sessionId,
3805 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3806 hdd_ctx->config->lower_brssi_thresh);
3807
3808 sme_set_smps_cfg(adapter->sessionId,
3809 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3810 hdd_ctx->config->enable_dtim_1chrx);
3811 }
3812
Dustin Brown732ab9c2017-06-15 13:24:09 -07003813 if (hdd_ctx->config->enable2x2) {
3814 hdd_debug("configuring 2x2 mode fw params");
3815
Naveen Rawat247a8682017-06-05 15:00:31 -07003816 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003817 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3818 hdd_ctx->config->enable_cck_tx_fir_override,
3819 PDEV_CMD);
3820 if (ret) {
3821 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3822 ret);
3823 goto error;
3824 }
3825 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303826#define HDD_DTIM_1CHAIN_RX_ID 0x5
3827#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003828 hdd_debug("configuring 1x1 mode fw params");
3829
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003830 /*
3831 * Disable DTIM 1 chain Rx when in 1x1,
3832 * we are passing two value
3833 * as param_id << 29 | param_value.
3834 * Below param_value = 0(disable)
3835 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003836 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003837 WMI_STA_SMPS_PARAM_CMDID,
3838 HDD_DTIM_1CHAIN_RX_ID <<
3839 HDD_SMPS_PARAM_VALUE_S,
3840 VDEV_CMD);
3841 if (ret) {
3842 hdd_err("DTIM 1 chain set failed %d", ret);
3843 goto error;
3844 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303845
Naveen Rawat247a8682017-06-05 15:00:31 -07003846 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003847 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3848 hdd_ctx->config->txchainmask1x1,
3849 PDEV_CMD);
3850 if (ret) {
3851 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3852 ret);
3853 goto error;
3854 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303855
Naveen Rawat247a8682017-06-05 15:00:31 -07003856 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003857 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3858 hdd_ctx->config->rxchainmask1x1,
3859 PDEV_CMD);
3860 if (ret) {
3861 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3862 ret);
3863 goto error;
3864 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303865#undef HDD_DTIM_1CHAIN_RX_ID
3866#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003867 }
3868
Naveen Rawat247a8682017-06-05 15:00:31 -07003869 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003870 WMI_PDEV_PARAM_HYST_EN,
3871 hdd_ctx->config->enableMemDeepSleep,
3872 PDEV_CMD);
3873 if (ret) {
3874 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3875 goto error;
3876 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303877
Naveen Rawat247a8682017-06-05 15:00:31 -07003878 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003879 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3880 hdd_ctx->config->rts_profile,
3881 VDEV_CMD);
3882 if (ret) {
3883 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3884 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303885 }
3886
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003887 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3888
3889 ret = wma_cli_set_command(adapter->sessionId,
3890 GEN_VDEV_PARAM_AMSDU,
3891 hdd_ctx->config->max_amsdu_num,
3892 GEN_CMD);
3893 if (ret != 0) {
3894 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3895 goto error;
3896 }
3897
Arun Khandavalli2358d522016-05-16 18:05:37 +05303898 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303899 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003900
Arun Khandavalli2358d522016-05-16 18:05:37 +05303901 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303902
Arun Khandavalli2358d522016-05-16 18:05:37 +05303903error:
3904 return -EINVAL;
3905}
3906
Ryan Hsu07495ea2016-01-21 15:25:39 -08003907/**
3908 * hdd_open_adapter() - open and setup the hdd adatper
3909 * @hdd_ctx: global hdd context
3910 * @session_type: type of the interface to be created
3911 * @iface_name: User-visible name of the interface
3912 * @macAddr: MAC address to assign to the interface
3913 * @name_assign_type: the name of assign type of the netdev
3914 * @rtnl_held: the rtnl lock hold flag
3915 *
3916 * This function open and setup the hdd adpater according to the device
3917 * type request, assign the name, the mac address assigned, and then prepared
3918 * the hdd related parameters, queue, lock and ready to start.
3919 *
3920 * Return: the pointer of hdd adapter, otherwise NULL.
3921 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003922struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003924 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003925 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926{
Jeff Johnson9d295242017-08-29 14:39:48 -07003927 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303929 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Jeff Johnson5e4b93c2017-09-30 18:09:16 -07003930 struct hdd_cfg80211_state *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003932
3933 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3934 /*
3935 * Max limit reached on the number of vdevs configured by the
3936 * host. Return error
3937 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303938 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3939 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003940 return NULL;
3941 }
3942
3943 if (macAddr == NULL) {
3944 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303945 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003946 return NULL;
3947 }
3948 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303949 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303950 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3951 " already exists",
3952 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953 return NULL;
3954 }
3955
3956 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003957 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 /* Reset locally administered bit if the device mode is STA */
3959 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303960 hdd_info("locally administered bit reset in sta mode: "
3961 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003963 case QDF_P2P_CLIENT_MODE:
3964 case QDF_P2P_DEVICE_MODE:
3965 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003966 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303967 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003968 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3969 name_assign_type,
3970 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971
3972 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303973 hdd_err("failed to allocate adapter for session %d",
3974 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003975 return NULL;
3976 }
3977
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003978 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003980 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303982 else if (QDF_MONITOR_MODE == session_type)
3983 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984 else
3985 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3986
3987 adapter->device_mode = session_type;
3988
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990 /*
3991 * Workqueue which gets scheduled in IPv4 notification
3992 * callback
3993 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3995 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996
3997#ifdef WLAN_NS_OFFLOAD
3998 /*
3999 * Workqueue which gets scheduled in IPv6
4000 * notification callback.
4001 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004002 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4003 hdd_ipv6_notifier_work_queue);
4004#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304006 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004007 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304008 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004009 }
4010
4011 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004012 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304014 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4015 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304016
Ravi Joshi1a292562017-05-18 16:28:54 -07004017 /* Initialize NAN Data Interface */
4018 if (QDF_NDI_MODE == session_type) {
4019 status = hdd_init_nan_data_mode(adapter);
4020 if (QDF_STATUS_SUCCESS != status)
4021 goto err_free_netdev;
4022 }
4023
4024 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004026 case QDF_P2P_GO_MODE:
4027 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004028 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4029 name_assign_type,
4030 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004031 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004032 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304033 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004034 return NULL;
4035 }
4036
4037 adapter->wdev.iftype =
4038 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004039 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004040 NL80211_IFTYPE_P2P_GO;
4041 adapter->device_mode = session_type;
4042
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004043 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304044 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004045 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4046 goto err_free_netdev;
4047 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004048 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304050 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4051 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304053 case QDF_FTM_MODE:
4054 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4055 name_assign_type,
4056 "wlan0");
4057 if (NULL == adapter) {
4058 hdd_err("Failed to allocate adapter for FTM mode");
4059 return NULL;
4060 }
4061 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4062 adapter->device_mode = session_type;
4063 status = hdd_register_interface(adapter, rtnl_held);
4064 if (QDF_STATUS_SUCCESS != status) {
4065 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4066 goto err_free_netdev;
4067 }
4068 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004069 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304070 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304071 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4072 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304073 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004074 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004075 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304076 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077 return NULL;
4078 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004079
hqueaa33ee2017-05-04 17:56:35 +08004080 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4081
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004082 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4083 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4084
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304085 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004086 /* Add it to the hdd's session list. */
4087 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304088 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004089 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304090 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004091 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004092 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004093 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4094 }
4095 }
4096
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304097 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098 if (NULL != adapter) {
4099 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4100 adapter = NULL;
4101 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004102 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304103 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105 return NULL;
4106 }
4107
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304108 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004109 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4110 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004111
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 /* Adapter successfully added. Increment the vdev count */
4113 hdd_ctx->current_intf_count++;
4114
Jeff Johnson5880d792016-08-15 13:32:30 -07004115 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 hdd_ctx->current_intf_count);
4117
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004118 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004119 }
4120
Rajeev Kumardca5f812016-02-04 17:28:06 -08004121 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004122 hdd_err("Interface %s wow debug_fs init failed",
4123 netdev_name(adapter->dev));
4124
4125 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4126 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004127
4128 return adapter;
4129
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004131 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304132 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004133
4134 return NULL;
4135}
4136
Jeff Johnson9d295242017-08-29 14:39:48 -07004137QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004138 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139{
4140 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304141 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004142
4143 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304144 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004145 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004146 status);
4147 return status;
4148 }
4149
Jeff Johnson57eb2732017-10-02 11:40:20 -07004150 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004151 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304152 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153 break;
4154
4155 pCurrent = pNext;
4156 }
4157 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304158 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004159 /*
4160 * Here we are stopping global bus_bw timer & work per adapter.
4161 *
4162 * The reason is to fix one race condition between
4163 * bus bandwidth work and cleaning up an adapter.
4164 * Under some conditions, it is possible for the bus bandwidth
4165 * work to access a particularly destroyed adapter, leading to
4166 * use-after-free.
4167 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004168 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004169 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004170 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004171
4172 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004173 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4174 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004175 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004176 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304177 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004178 adapterNode = NULL;
4179
Dustin Brown5ec6b552017-03-31 12:11:40 -07004180 /* conditionally restart the bw timer */
4181 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4182
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004183 /* Adapter removed. Decrement vdev count */
4184 if (hdd_ctx->current_intf_count != 0)
4185 hdd_ctx->current_intf_count--;
4186
4187 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304188 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004189 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304190
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304191 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004192}
4193
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004194/**
4195 * hdd_close_all_adapters - Close all open adapters
4196 * @hdd_ctx: Hdd context
4197 * rtnl_held: True if RTNL lock held
4198 *
4199 * Close all open adapters.
4200 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304201 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004202 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004203QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004204{
4205 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304206 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004207
4208 ENTER();
4209
4210 do {
4211 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304212 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304213 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004214 pHddAdapterNode->adapter->macAddressCurrent.bytes);
4215 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004216 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304217 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304218 /* Adapter removed. Decrement vdev count */
4219 if (hdd_ctx->current_intf_count != 0)
4220 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304222 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004223
4224 EXIT();
4225
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304226 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004227}
4228
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004229void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304231 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004233
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004234 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004235 case QDF_STA_MODE:
4236 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004237 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004238 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004239 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004240 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004241 break;
4242 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004243 case QDF_SAP_MODE:
4244 case QDF_P2P_GO_MODE:
4245 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004246 {
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004247 bssid = &adapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 break;
4249 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004250 case QDF_FTM_MODE:
4251 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004252 default:
4253 /*
4254 * wlan_hdd_reset_prob_rspies should not have been called
4255 * for these kind of devices
4256 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004257 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004258 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259 return;
4260 }
4261
Anurag Chouhanc5548422016-02-24 18:33:27 +05304262 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004263 updateIE.smeSessionId = adapter->sessionId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264 updateIE.ieBufferlength = 0;
4265 updateIE.pAdditionIEBuffer = NULL;
4266 updateIE.append = true;
4267 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004268 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304270 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004271 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004272 }
4273}
4274
Jeff Johnson9d295242017-08-29 14:39:48 -07004275QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004276 const bool bCloseSession)
4277{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304278 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004279 struct hdd_wext_state *pWextState =
4280 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004281 union iwreq_data wrqu;
4282 tSirUpdateIE updateIE;
4283 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004284 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004285
4286 ENTER();
4287
Sachin Ahuja988fd102016-09-15 17:16:25 +05304288 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004289 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304290 wlan_hdd_netif_queue_control(adapter,
4291 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4292 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004293 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004294 case QDF_STA_MODE:
4295 case QDF_P2P_CLIENT_MODE:
4296 case QDF_IBSS_MODE:
4297 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004298 case QDF_NDI_MODE:
4299 if ((QDF_NDI_MODE == adapter->device_mode) ||
4300 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004301 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4302 hdd_is_connecting(
4303 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004304 INIT_COMPLETION(adapter->disconnect_comp_var);
4305 /*
4306 * For NDI do not use pWextState from sta_ctx, if needed
4307 * extract from ndi_ctx.
4308 */
4309 if (QDF_NDI_MODE == adapter->device_mode)
4310 qdf_ret_status = sme_roam_disconnect(
4311 hdd_ctx->hHal,
4312 adapter->sessionId,
4313 eCSR_DISCONNECT_REASON_NDI_DELETE);
4314 else if (pWextState->roamProfile.BSSType ==
4315 eCSR_BSS_TYPE_START_IBSS)
4316 qdf_ret_status = sme_roam_disconnect(
4317 hdd_ctx->hHal,
4318 adapter->sessionId,
4319 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004320 else if (QDF_STA_MODE == adapter->device_mode)
4321 qdf_ret_status =
4322 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004323 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004324 qdf_ret_status = sme_roam_disconnect(
4325 hdd_ctx->hHal,
4326 adapter->sessionId,
4327 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004328 /* success implies disconnect command got
4329 * queued up successfully
4330 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004331 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4332 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004333 rc = wait_for_completion_timeout(
4334 &adapter->disconnect_comp_var,
4335 msecs_to_jiffies
4336 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004337 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004338 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004340 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4341 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004342 memset(&wrqu, '\0', sizeof(wrqu));
4343 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4344 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4345 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4346 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304347 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004348 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304349 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004350
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304351 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304352 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353
4354#ifdef WLAN_OPEN_SOURCE
4355 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4356#endif
4357
4358 hdd_deregister_tx_flow_control(adapter);
4359
4360#ifdef WLAN_NS_OFFLOAD
4361#ifdef WLAN_OPEN_SOURCE
4362 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4363#endif
4364#endif
4365
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304366 if (adapter->device_mode == QDF_STA_MODE)
4367 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4368 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369 /*
4370 * It is possible that the caller of this function does not
4371 * wish to close the session
4372 */
Krunal Soni985b8132017-02-10 18:49:08 -08004373 if (true == bCloseSession) {
4374 if (0 != wlan_hdd_try_disconnect(adapter)) {
4375 hdd_err("Error: Can't disconnect adapter");
4376 return QDF_STATUS_E_FAILURE;
4377 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004378 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004379 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004380 break;
4381
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004382 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304383 /* Flush IPA exception path packets */
4384 hdd_ipa_flush(hdd_ctx);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004385 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004386 if (QDF_SAP_MODE == adapter->device_mode) {
4387 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4388 cds_flush_delayed_work(
4389 &adapter->acs_pending_work);
4390 clear_bit(ACS_PENDING, &adapter->event_flags);
4391 }
4392 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004393 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004394 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004395 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4396
4397 hdd_deregister_tx_flow_control(adapter);
4398
Kapil Guptac1224bf2017-06-22 21:22:40 +05304399 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400 mutex_lock(&hdd_ctx->sap_lock);
4401 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304402 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304403 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004404
4405 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004406 status = wlansap_stop_bss(
4407 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004408
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304409 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004410 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004411 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304412 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304413 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304414 qdf_status =
4415 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004416 qdf_stop_bss_event,
4417 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004418
Anurag Chouhance0dc992016-02-16 18:18:03 +05304419 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004420 hdd_err("failure waiting for wlansap_stop_bss %d",
4421 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 }
4423 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004424 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004425 }
4426 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004427 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4428 adapter->device_mode,
4429 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004430
Anurag Chouhanc5548422016-02-24 18:33:27 +05304431 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004432 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004433 updateIE.smeSessionId = adapter->sessionId;
4434 updateIE.ieBufferlength = 0;
4435 updateIE.pAdditionIEBuffer = NULL;
4436 updateIE.append = false;
4437 updateIE.notify = false;
4438 /* Probe bcn reset */
4439 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4440 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304441 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004442 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443 }
4444 /* Assoc resp reset */
4445 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4446 &updateIE,
4447 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304448 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004449 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004450 }
4451 /* Reset WNI_CFG_PROBE_RSP Flags */
4452 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004453 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004454 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4455 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304456 /*
4457 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4458 */
4459 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4460 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4461
Peng Xu66162de2016-02-11 17:01:20 -08004462 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004463 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004464 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004465 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004466 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004467 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004468 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004469 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004470 break;
4471 default:
4472 break;
4473 }
4474
4475 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304476 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004477}
4478
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304479/**
4480 * hdd_deinit_all_adapters - deinit all adapters
4481 * @hdd_ctx: HDD context
4482 * @rtnl_held: True if RTNL lock held
4483 *
4484 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004485void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304486{
4487 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4488 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004489 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304490
4491 ENTER();
4492
4493 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4494
4495 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004496 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304497 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4498 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4499 adapter_node = next;
4500 }
4501
4502 EXIT();
4503}
4504
Dustin Brown27cd9942017-09-27 16:11:44 -07004505QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4506 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507{
4508 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304509 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004510 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511
4512 ENTER();
4513
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304514 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4515
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004516 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4517
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304518 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004519 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004520 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004521 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4522 adapterNode = pNext;
4523 }
4524
4525 EXIT();
4526
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304527 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004528}
4529
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004530QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004531{
4532 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304533 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004534 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004535 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004536 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537
4538 ENTER();
4539
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304540 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4541
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004542 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4543
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304544 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004545 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004546 hdd_notice("Disabling queues for adapter type: %d",
4547 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304548
4549 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004550 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304551 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004552 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304553
Arun Khandavallicc544b32017-01-30 19:52:16 +05304554 if (hdd_ctx->config->sap_internal_restart &&
4555 adapter->device_mode == QDF_SAP_MODE) {
4556 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304557 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304558 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004559 if (test_bit(SOFTAP_BSS_STARTED,
4560 &adapter->event_flags)) {
4561 hdd_sap_indicate_disconnect_for_sta(adapter);
4562 hdd_cleanup_actionframe(hdd_ctx, adapter);
4563 hdd_sap_destroy_events(adapter);
4564 }
4565 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4566 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304567 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304568 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004569 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004570 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571
4572 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4573
4574 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004575 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4576 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004577 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4578 hdd_wmm_adapter_close(adapter);
4579 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4580 }
4581
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304582 if (adapter->device_mode == QDF_STA_MODE)
4583 hdd_clear_fils_connection_info(adapter);
4584
Wu Gao3545e642017-07-14 19:24:41 +08004585 if (adapter->device_mode == QDF_SAP_MODE) {
4586 /*
4587 * If adapter is SAP, set session ID to invalid
4588 * since SAP session will be cleanup during SSR.
4589 */
Wu Gao36717432016-11-21 15:09:48 +08004590 wlansap_set_invalid_session(
4591 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4592
Wu Gao3545e642017-07-14 19:24:41 +08004593 wlansap_cleanup_cac_timer(
4594 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4595 }
4596
Yue Mad5b4b9f2017-05-26 16:23:40 -07004597 /* Delete peers if any for STA and P2P client modes */
4598 if (adapter->device_mode == QDF_STA_MODE ||
4599 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004600 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004601 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004602 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004603
4604 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4605 peerMacAddr.bytes);
4606 }
4607
Yue Maf9782842017-05-08 12:49:49 -07004608 /* Destroy vdev which will be recreated during reinit. */
4609 hdd_vdev_destroy(adapter);
4610
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004611 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4612 adapterNode = pNext;
4613 }
4614
4615 EXIT();
4616
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304617 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618}
4619
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004620bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304621{
4622 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4623 QDF_STATUS status;
4624 bool close_modules = true;
4625
Arun Khandavalliba479c42017-07-26 21:29:40 +05304626 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4627 hdd_info("FTM mode, don't close the module");
4628 return false;
4629 }
4630
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304631 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4632 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4633 if (test_bit(DEVICE_IFACE_OPENED,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004634 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004635 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304636 close_modules = false;
4637 break;
4638 }
4639 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4640 adapter_node = next;
4641 }
4642
4643 return close_modules;
4644}
4645
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304646bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304647{
4648 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4649 return true;
4650 else
4651 return false;
4652}
4653
Anurag Chouhanc4092922016-09-08 15:56:11 +05304654#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004655 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304656struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4657 struct ieee80211_channel *channel,
4658 const u8 *bssid, const u8 *ssid,
4659 size_t ssid_len)
4660{
4661 return cfg80211_get_bss(wiphy, channel, bssid,
4662 ssid, ssid_len,
4663 WLAN_CAPABILITY_ESS,
4664 WLAN_CAPABILITY_ESS);
4665}
4666#else
4667struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4668 struct ieee80211_channel *channel,
4669 const u8 *bssid, const u8 *ssid,
4670 size_t ssid_len)
4671{
4672 return cfg80211_get_bss(wiphy, channel, bssid,
4673 ssid, ssid_len,
4674 IEEE80211_BSS_TYPE_ESS,
4675 IEEE80211_PRIVACY_ANY);
4676}
4677#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304678
Abhishek Singha84d3952016-09-13 13:45:05 +05304679#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304680#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4681 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4682/**
4683 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4684 * @timeout_reason: reason for connect timeout
4685 *
4686 * This function is used to convert host timeout
4687 * reason enum to kernel specific enum.
4688 *
4689 * Return: nl timeout enum
4690 */
4691static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4692 tSirResultCodes timeout_reason)
4693{
4694 switch (timeout_reason) {
4695 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4696 return NL80211_TIMEOUT_SCAN;
4697 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4698 return NL80211_TIMEOUT_AUTH;
4699 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4700 return NL80211_TIMEOUT_ASSOC;
4701 default:
4702 return NL80211_TIMEOUT_UNSPECIFIED;
4703 }
4704}
4705
4706/**
4707 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4708 * @dev: network device
4709 * @bssid: bssid to which we want to associate
4710 * @timeout_reason: reason for connect timeout
4711 *
4712 * This API is used to send connection timeout reason to supplicant
4713 *
4714 * Return: void
4715 */
4716static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4717 const u8 *bssid,
4718 tSirResultCodes timeout_reason)
4719{
4720 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004721
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304722 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4723
4724 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4725 nl_timeout_reason);
4726}
4727
4728/**
4729 * __hdd_connect_bss() - API to send connection status to supplicant
4730 * @dev: network device
4731 * @bssid: bssid to which we want to associate
4732 * @req_ie: Request Information Element
4733 * @req_ie_len: len of the req IE
4734 * @resp_ie: Response IE
4735 * @resp_ie_len: len of ht response IE
4736 * @status: status
4737 * @gfp: Kernel Flag
4738 * @timeout_reason: reason for connect timeout
4739 *
4740 * Return: void
4741 */
4742static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4743 struct cfg80211_bss *bss, const u8 *req_ie,
4744 size_t req_ie_len, const u8 *resp_ie,
4745 size_t resp_ie_len, int status, gfp_t gfp,
4746 tSirResultCodes timeout_reason)
4747{
4748 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004749
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304750 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4751
4752 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4753 resp_ie, resp_ie_len, status, gfp,
4754 nl_timeout_reason);
4755}
4756#else
4757#if defined CFG80211_CONNECT_TIMEOUT
4758static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4759 const u8 *bssid,
4760 tSirResultCodes timeout_reason)
4761{
4762 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4763}
4764#endif
4765
4766static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4767 struct cfg80211_bss *bss, const u8 *req_ie,
4768 size_t req_ie_len, const u8 *resp_ie,
4769 size_t resp_ie_len, int status, gfp_t gfp,
4770 tSirResultCodes timeout_reason)
4771{
4772 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4773 resp_ie, resp_ie_len, status, gfp);
4774}
4775#endif
4776
Abhishek Singha84d3952016-09-13 13:45:05 +05304777/**
4778 * hdd_connect_bss() - API to send connection status to supplicant
4779 * @dev: network device
4780 * @bssid: bssid to which we want to associate
4781 * @req_ie: Request Information Element
4782 * @req_ie_len: len of the req IE
4783 * @resp_ie: Response IE
4784 * @resp_ie_len: len of ht response IE
4785 * @status: status
4786 * @gfp: Kernel Flag
4787 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304788 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304789 *
4790 * The API is a wrapper to send connection status to supplicant
4791 *
4792 * Return: Void
4793 */
4794#if defined CFG80211_CONNECT_TIMEOUT
4795static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4796 struct cfg80211_bss *bss, const u8 *req_ie,
4797 size_t req_ie_len, const u8 *resp_ie,
4798 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304799 bool connect_timeout,
4800 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304801{
4802 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304803 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304804 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304805 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4806 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304807}
4808#else
4809static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4810 struct cfg80211_bss *bss, const u8 *req_ie,
4811 size_t req_ie_len, const u8 *resp_ie,
4812 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304813 bool connect_timeout,
4814 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304815{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304816 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4817 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304818}
4819#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304820
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304821#ifdef WLAN_FEATURE_FILS_SK
4822#ifdef CFG80211_CONNECT_DONE
4823#ifdef CFG80211_FILS_SK_OFFLOAD_SUPPORT
4824/**
4825 * hdd_populate_fils_params() - Populate FILS keys to connect response
4826 * @fils_params: connect response to supplicant
4827 * @fils_kek: FILS kek
4828 * @fils_kek_len: FILS kek length
4829 * @pmk: FILS PMK
4830 * @pmk_len: FILS PMK length
4831 * @pmkid: PMKID
4832 * @fils_seq_num: FILS Seq number
4833 *
4834 * Return: None
4835 */
4836static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4837 *fils_params, const uint8_t *fils_kek,
4838 size_t fils_kek_len, const uint8_t *pmk,
4839 size_t pmk_len, const uint8_t *pmkid,
4840 uint16_t fils_seq_num)
4841{
4842 /* Increament seq number to be used for next FILS */
4843 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4844 fils_params->update_erp_next_seq_num = true;
4845 fils_params->fils_kek = fils_kek;
4846 fils_params->fils_kek_len = fils_kek_len;
4847 fils_params->pmk = pmk;
4848 fils_params->pmk_len = pmk_len;
4849 fils_params->pmkid = pmkid;
4850}
4851#else
4852static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4853 *fils_params, const uint8_t
4854 *fils_kek, size_t fils_kek_len,
4855 const uint8_t *pmk, size_t pmk_len,
4856 const uint8_t *pmkid,
4857 uint16_t fils_seq_num)
4858{ }
4859#endif
4860
4861/**
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304862 * hdd_update_hlp_info() - Update HLP packet received in FILS assoc rsp
4863 * @dev: net device
4864 * @roam_fils_params: Fils join rsp params
4865 *
4866 * This API is used to send the received HLP packet in Assoc rsp(FILS AKM)
4867 * to the network layer.
4868 *
4869 * Return: None
4870 */
4871static void hdd_update_hlp_info(struct net_device *dev,
4872 struct fils_join_rsp_params *roam_fils_params)
4873{
4874 struct sk_buff *skb;
4875 uint16_t skb_len;
4876 struct llc_snap_hdr_t *llc_hdr;
4877 QDF_STATUS status;
4878 uint8_t *hlp_data = roam_fils_params->hlp_data;
4879 uint16_t hlp_data_len = roam_fils_params->hlp_data_len;
4880 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
4881
4882 /* Calculate skb length */
4883 skb_len = (2 * ETH_ALEN) + hlp_data_len;
4884 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
4885 if (skb == NULL) {
4886 hdd_err("HLP packet nbuf alloc fails");
4887 return;
4888 }
4889
4890 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
4891 QDF_MAC_ADDR_SIZE);
4892 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
4893 QDF_MAC_ADDR_SIZE);
4894
4895 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
4896 if (IS_SNAP(llc_hdr)) {
4897 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4898 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4899 }
4900
4901 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
4902
4903 /*
4904 * This HLP packet is formed from HLP info encapsulated
4905 * in assoc response frame which is AEAD encrypted.
4906 * Hence, this checksum validation can be set unnecessary.
4907 * i.e. network layer need not worry about checksum.
4908 */
4909 skb->ip_summed = CHECKSUM_UNNECESSARY;
4910
4911 status = hdd_rx_packet_cbk(padapter, skb);
4912 if (QDF_IS_STATUS_ERROR(status)) {
4913 hdd_err("Sending HLP packet fails");
4914 return;
4915 }
4916 hdd_debug("send HLP packet to netif successfully");
4917}
4918
4919/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304920 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4921 * @dev: network device
4922 * @bssid: bssid to which we want to associate
4923 * @bss: cfg80211 bss info
4924 * @roam_info: information about connected bss
4925 * @req_ie: Request Information Element
4926 * @req_ie_len: len of the req IE
4927 * @resp_ie: Response IE
4928 * @resp_ie_len: len of ht response IE
4929 * @status: status
4930 * @gfp: allocation flags
4931 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4932 * @timeout_reason: reason for connect timeout
4933 * @roam_fils_params: FILS join response params
4934 *
4935 * This API is used as wrapper to send FILS key/sequence number
4936 * params etc. to supplicant in case of FILS connection
4937 *
4938 * Return: None
4939 */
4940static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4941 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4942 const u8 *req_ie, size_t req_ie_len,
4943 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004944 gfp_t gfp, bool connect_timeout,
4945 tSirResultCodes timeout_reason,
4946 struct fils_join_rsp_params *roam_fils_params)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304947{
4948 struct cfg80211_connect_resp_params fils_params;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004949
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304950 qdf_mem_zero(&fils_params, sizeof(fils_params));
4951
4952 if (!roam_fils_params) {
4953 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4954 } else {
4955 fils_params.status = status;
4956 fils_params.bssid = bssid;
4957 fils_params.timeout_reason = timeout_reason;
4958 fils_params.req_ie = req_ie;
4959 fils_params.req_ie_len = req_ie_len;
4960 fils_params.resp_ie = resp_ie;
4961 fils_params.resp_ie_len = resp_ie_len;
4962 fils_params.bss = bss;
4963 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4964 roam_fils_params->kek_len,
4965 roam_fils_params->fils_pmk,
4966 roam_fils_params->fils_pmk_len,
4967 roam_fils_params->fils_pmkid,
4968 roam_info->fils_seq_num);
4969 }
4970 hdd_debug("FILS indicate connect status %d seq no %d",
4971 fils_params.status,
4972 fils_params.fils_erp_next_seq_num);
4973
4974 cfg80211_connect_done(dev, &fils_params, gfp);
4975
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304976 if (roam_fils_params && roam_fils_params->hlp_data_len)
4977 hdd_update_hlp_info(dev, roam_fils_params);
4978
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304979 /* Clear all the FILS key info */
4980 if (roam_fils_params && roam_fils_params->fils_pmk)
4981 qdf_mem_free(roam_fils_params->fils_pmk);
4982 if (roam_fils_params)
4983 qdf_mem_free(roam_fils_params);
4984 roam_info->fils_join_rsp = NULL;
4985}
4986#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004987static inline void
4988hdd_connect_done(struct net_device *dev, const u8 *bssid,
4989 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4990 const u8 *req_ie, size_t req_ie_len,
4991 const u8 *resp_ie, size_t resp_ie_len, u16 status,
4992 gfp_t gfp, bool connect_timeout,
4993 tSirResultCodes timeout_reason,
4994 struct fils_join_rsp_params *roam_fils_params)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304995{ }
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304996
4997static inline void hdd_update_hlp_info(struct net_device *dev,
4998 struct fils_join_rsp_params *roam_fils_params)
4999
5000{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305001#endif
5002#endif
5003
5004#if defined(CFG80211_CONNECT_DONE) && defined(WLAN_FEATURE_FILS_SK)
5005/**
5006 * hdd_fils_update_connect_results() - API to send fils connection status to
5007 * supplicant.
5008 * @dev: network device
5009 * @bssid: bssid to which we want to associate
5010 * @bss: cfg80211 bss info
5011 * @roam_info: information about connected bss
5012 * @req_ie: Request Information Element
5013 * @req_ie_len: len of the req IE
5014 * @resp_ie: Response IE
5015 * @resp_ie_len: len of ht response IE
5016 * @status: status
5017 * @gfp: allocation flags
5018 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5019 * @timeout_reason: reason for connect timeout
5020 *
5021 * The API is a wrapper to send connection status to supplicant
5022 *
5023 * Return: 0 if success else failure
5024 */
5025static int hdd_fils_update_connect_results(struct net_device *dev,
5026 const u8 *bssid,
5027 struct cfg80211_bss *bss,
5028 tCsrRoamInfo *roam_info, const u8 *req_ie,
5029 size_t req_ie_len, const u8 *resp_ie,
5030 size_t resp_ie_len, u16 status, gfp_t gfp,
5031 bool connect_timeout,
5032 tSirResultCodes timeout_reason)
5033{
5034 ENTER();
5035 if (!roam_info || !roam_info->is_fils_connection)
5036 return -EINVAL;
5037
5038 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5039 resp_ie, resp_ie_len, status, gfp, connect_timeout,
5040 timeout_reason, roam_info->fils_join_rsp);
5041 return 0;
5042}
5043#else
5044static inline int hdd_fils_update_connect_results(struct net_device *dev,
5045 const u8 *bssid,
5046 struct cfg80211_bss *bss,
5047 tCsrRoamInfo *roam_info, const u8 *req_ie,
5048 size_t req_ie_len, const u8 *resp_ie,
5049 size_t resp_ie_len, u16 status, gfp_t gfp,
5050 bool connect_timeout,
5051 tSirResultCodes timeout_reason)
5052{
5053 return -EINVAL;
5054}
5055#endif
5056
Anurag Chouhanc4092922016-09-08 15:56:11 +05305057/**
5058 * hdd_connect_result() - API to send connection status to supplicant
5059 * @dev: network device
5060 * @bssid: bssid to which we want to associate
5061 * @roam_info: information about connected bss
5062 * @req_ie: Request Information Element
5063 * @req_ie_len: len of the req IE
5064 * @resp_ie: Response IE
5065 * @resp_ie_len: len of ht response IE
5066 * @status: status
5067 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305068 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305069 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305070 *
5071 * The API is a wrapper to send connection status to supplicant
5072 * and allow runtime suspend
5073 *
5074 * Return: Void
5075 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305076void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5077 tCsrRoamInfo *roam_info, const u8 *req_ie,
5078 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305079 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305080 bool connect_timeout,
5081 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305082{
Jeff Johnson9d295242017-08-29 14:39:48 -07005083 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305084 struct cfg80211_bss *bss = NULL;
5085
5086 if (WLAN_STATUS_SUCCESS == status) {
5087 struct ieee80211_channel *chan;
5088 int freq;
5089 int chan_no = roam_info->pBssDesc->channelId;
5090
5091 if (chan_no <= 14)
5092 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005093 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305094 else
5095 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005096 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305097
5098 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5099 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5100 roam_info->u.pConnectedProfile->SSID.ssId,
5101 roam_info->u.pConnectedProfile->SSID.length);
5102 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305103
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305104 if (hdd_fils_update_connect_results(dev, bssid, bss,
5105 roam_info, req_ie, req_ie_len, resp_ie,
5106 resp_ie_len, status, gfp, connect_timeout,
5107 timeout_reason) != 0) {
5108 hdd_connect_bss(dev, bssid, bss, req_ie,
5109 req_ie_len, resp_ie, resp_ie_len,
5110 status, gfp, connect_timeout, timeout_reason);
5111 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305112
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005113 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005114 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305115}
5116#else
5117void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5118 tCsrRoamInfo *roam_info, const u8 *req_ie,
5119 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305120 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305121 bool connect_timeout,
5122 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305123{
Jeff Johnson9d295242017-08-29 14:39:48 -07005124 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305125
Anurag Chouhanc4092922016-09-08 15:56:11 +05305126 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5127 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005128
5129 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005130 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305131}
5132#endif
5133
5134
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005135QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005136{
5137 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305138 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005139 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005140#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305141 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142#endif
5143 eConnectionState connState;
5144
5145 ENTER();
5146
5147 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305148 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005149 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005150
Arun Khandavallifae92942016-08-01 13:31:08 +05305151 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305152 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305153
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005154 hdd_wmm_init(adapter);
5155
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005156 adapter->scan_info.mScanPending = false;
5157
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005158 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005159 case QDF_STA_MODE:
5160 case QDF_P2P_CLIENT_MODE:
5161 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005162
5163 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5164 ->conn_info.connState;
5165
5166 hdd_init_station_mode(adapter);
5167 /* Open the gates for HDD to receive Wext commands */
5168 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005169
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005170 /* Indicate disconnect event to supplicant
5171 * if associated previously
5172 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005173 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005174 eConnectionState_IbssConnected == connState ||
5175 eConnectionState_NotConnected == connState ||
5176 eConnectionState_IbssDisconnected == connState ||
5177 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005178 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005179
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005180 memset(&wrqu, '\0', sizeof(wrqu));
5181 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5182 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5183 wireless_send_event(adapter->dev, SIOCGIWAP,
5184 &wrqu, NULL);
5185 adapter->sessionCtx.station.
5186 hdd_ReassocScenario = false;
5187
5188 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305189 wlan_hdd_cfg80211_indicate_disconnect(
5190 adapter->dev, false,
5191 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005192 } else if (eConnectionState_Connecting == connState) {
5193 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005194 * Indicate connect failure to supplicant if we
5195 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305197 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305198 NULL, 0, NULL, 0,
5199 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005200 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005201 }
5202
5203 hdd_register_tx_flow_control(adapter,
5204 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005205 hdd_tx_resume_cb,
5206 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005207
5208 break;
5209
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005210 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005211 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305212 hdd_init_ap_mode(adapter, true);
5213
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005214 break;
5215
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005216 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005218 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005219 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5220#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005221 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005222 /* event supplicant to restart */
5223 cfg80211_del_sta(adapter->dev,
5224 (const u8 *)&bcastMac.bytes[0],
5225 GFP_KERNEL);
5226#endif
5227 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305228 case QDF_MONITOR_MODE:
5229 hdd_init_station_mode(adapter);
5230 hdd_set_mon_rx_cb(adapter->dev);
5231 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5232 adapter->mon_bandwidth);
5233 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234 default:
5235 break;
5236 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005237 /*
5238 * Action frame registered in one adapter which will
5239 * applicable to all interfaces
5240 */
5241 wlan_hdd_cfg80211_register_frames(adapter);
5242
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305243get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5245 adapterNode = pNext;
5246 }
5247
5248 EXIT();
5249
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305250 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005251}
5252
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005253QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254 hdd_adapter_list_node_t **padapterNode)
5255{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305256 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005257
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005258 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305259 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5260 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005261 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262 return status;
5263}
5264
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005265QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005266 hdd_adapter_list_node_t *adapterNode,
5267 hdd_adapter_list_node_t **pNextAdapterNode)
5268{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305269 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005270
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005271 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305272 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5273 (qdf_list_node_t *) adapterNode,
5274 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005275
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005276 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005277 return status;
5278}
5279
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005280QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005281 hdd_adapter_list_node_t *adapterNode)
5282{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305283 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005284
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005285 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305286 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005288 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005289 return status;
5290}
5291
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005292QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005293 hdd_adapter_list_node_t **padapterNode)
5294{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305295 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005296
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005297 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305298 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5299 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005300 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005301 return status;
5302}
5303
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005304QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305 hdd_adapter_list_node_t *adapterNode)
5306{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305307 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005308
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005309 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305310 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5311 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005312 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005313 return status;
5314}
5315
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005316QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005317 hdd_adapter_list_node_t *adapterNode)
5318{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305319 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005320
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005321 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305322 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5323 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005324 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005325 return status;
5326}
5327
Jeff Johnson9d295242017-08-29 14:39:48 -07005328struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005329 tSirMacAddr macAddr)
5330{
5331 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005332 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305333 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005334
5335 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5336
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305337 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005338 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005339
5340 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305341 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005342 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005343 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005344
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005345 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5346 adapterNode = pNext;
5347 }
5348
5349 return NULL;
5350
5351}
5352
Jeff Johnson9d295242017-08-29 14:39:48 -07005353struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005354 uint32_t vdev_id)
5355{
5356 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005357 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305358 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005359
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305360 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005361
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305362 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005363 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005364
5365 if (adapter->sessionId == vdev_id)
5366 return adapter;
5367
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305368 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005369 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5370 adapterNode = pNext;
5371 }
5372
Jeff Johnson5880d792016-08-15 13:32:30 -07005373 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005374
5375 return NULL;
5376}
5377
Abhishek Singh7996eb72015-12-30 17:24:02 +05305378/**
5379 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5380 * the sessionid
5381 * @hdd_ctx: hdd context.
5382 * @sme_session_id: sme session is for the adapter to get.
5383 *
5384 * This function is used to get the adapter with provided session id
5385 *
5386 * Return: adapter pointer if found
5387 *
5388 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005389struct hdd_adapter *hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
Abhishek Singh7996eb72015-12-30 17:24:02 +05305390 uint32_t sme_session_id)
5391{
5392 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005393 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305394 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305395
5396
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305397 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305398
5399 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305400 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005401 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305402
5403 if (adapter &&
5404 adapter->sessionId == sme_session_id)
5405 return adapter;
5406
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305407 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305408 hdd_get_next_adapter(hdd_ctx,
5409 adapter_node, &next);
5410 adapter_node = next;
5411 }
5412 return NULL;
5413}
5414
Jeff Johnson9d295242017-08-29 14:39:48 -07005415struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005416 const char *iface_name)
5417{
5418 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005419 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005420 QDF_STATUS qdf_status;
5421
5422 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5423
5424 while ((NULL != adapter_node) &&
5425 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005426 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005427
5428 if (adapter &&
5429 !qdf_str_cmp(adapter->dev->name, iface_name))
5430 return adapter;
5431
5432 qdf_status =
5433 hdd_get_next_adapter(hdd_ctx,
5434 adapter_node, &next);
5435 adapter_node = next;
5436 }
5437 return NULL;
5438}
5439
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005440/**
5441 * hdd_get_adapter() - to get adapter matching the mode
5442 * @hdd_ctx: hdd context
5443 * @mode: adapter mode
5444 *
5445 * This routine will return the pointer to adapter matching
5446 * with the passed mode.
5447 *
5448 * Return: pointer to adapter or null
5449 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005450struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005451 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005452{
5453 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005454 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305455 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005456
5457 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5458
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305459 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005460 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005461
5462 if (adapter && (mode == adapter->device_mode))
5463 return adapter;
5464
5465 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5466 adapterNode = pNext;
5467 }
5468
5469 return NULL;
5470
5471}
5472
5473/**
5474 * hdd_get_operating_channel() - return operating channel of the device mode
5475 * @hdd_ctx: Pointer to the HDD context.
5476 * @mode: Device mode for which operating channel is required.
5477 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005478 * QDF_STA_MODE,
5479 * QDF_P2P_CLIENT_MODE,
5480 * QDF_SAP_MODE,
5481 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005482 *
5483 * This API returns the operating channel of the requested device mode
5484 *
5485 * Return: channel number. "0" id the requested device is not found OR it is
5486 * not connected.
5487 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005488uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005489 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005490{
5491 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305492 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005493 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005494 uint8_t operatingChannel = 0;
5495
5496 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5497
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305498 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005499 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005500
5501 if (mode == adapter->device_mode) {
5502 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005503 case QDF_STA_MODE:
5504 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005505 if (hdd_conn_is_connected
5506 (WLAN_HDD_GET_STATION_CTX_PTR
5507 (adapter))) {
5508 operatingChannel =
5509 (WLAN_HDD_GET_STATION_CTX_PTR
5510 (adapter))->conn_info.
5511 operationChannel;
5512 }
5513 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005514 case QDF_SAP_MODE:
5515 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005516 /* softap connection info */
5517 if (test_bit
5518 (SOFTAP_BSS_STARTED,
5519 &adapter->event_flags))
5520 operatingChannel =
5521 (WLAN_HDD_GET_AP_CTX_PTR
5522 (adapter))->operatingChannel;
5523 break;
5524 default:
5525 break;
5526 }
5527
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005528 /* Found the device of interest. break the loop */
5529 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005530 }
5531
5532 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5533 adapterNode = pNext;
5534 }
5535 return operatingChannel;
5536}
5537
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005538static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005539 hdd_ctx)
5540{
5541 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305542 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005543 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005544
5545 ENTER();
5546
5547 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5548
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305549 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005550 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005551 if ((adapter->device_mode == QDF_STA_MODE) ||
5552 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5553 (adapter->device_mode == QDF_IBSS_MODE) ||
5554 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5555 (adapter->device_mode == QDF_SAP_MODE) ||
5556 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005557 wlan_hdd_cfg80211_deregister_frames(adapter);
5558 hdd_unregister_wext(adapter->dev);
5559 }
5560 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5561 adapterNode = pNext;
5562 }
5563
5564 EXIT();
5565
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305566 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005567}
5568
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005569QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005570{
5571 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305572 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005573 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005574
5575 ENTER();
5576
5577 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5578
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305579 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005580 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005581 if ((adapter->device_mode == QDF_STA_MODE) ||
5582 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5583 (adapter->device_mode == QDF_IBSS_MODE) ||
5584 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5585 (adapter->device_mode == QDF_SAP_MODE) ||
5586 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305587 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5588 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005589 }
5590 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5591 adapterNode = pNext;
5592 }
5593
5594 EXIT();
5595
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305596 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005597}
5598
Dustin Brownf27bce82016-11-03 12:52:27 -07005599/**
5600 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5601 * adapters
5602 * @hdd_ctx: The HDD context containing the adapters to operate on
5603 *
5604 * return: QDF_STATUS_SUCCESS
5605 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005606static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005607{
5608 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5609 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005610 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005611 int err;
5612
5613 ENTER();
5614
5615 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5616
5617 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005618 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005619 if ((adapter->device_mode == QDF_STA_MODE) ||
5620 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5621 (adapter->device_mode == QDF_IBSS_MODE) ||
5622 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5623 (adapter->device_mode == QDF_SAP_MODE) ||
5624 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5625 err = wlan_hdd_sched_scan_stop(adapter->dev);
5626 if (err)
5627 hdd_err("Unable to stop scheduled scan");
5628 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005629 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5630 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005631 adapter_node = next_node;
5632 }
5633
5634 EXIT();
5635
5636 return QDF_STATUS_SUCCESS;
5637}
5638
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005639#ifdef WLAN_NS_OFFLOAD
5640/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005641 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005642 * @hdd_ctx: Pointer to hdd context
5643 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005644 * Unregister for IPv6 address change notifications.
5645 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005646 * Return: None
5647 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005648static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005649{
5650 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005651}
5652
5653/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005654 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005655 * @hdd_ctx: Pointer to hdd context
5656 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005657 * Register for IPv6 address change notifications.
5658 *
5659 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005660 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005661static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005662{
5663 int ret;
5664
5665 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5666 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005667 if (ret) {
5668 hdd_err("Failed to register IPv6 notifier: %d", ret);
5669 goto out;
5670 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005672 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005673out:
5674 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005675}
5676#else
5677/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005678 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005679 * @hdd_ctx: Pointer to hdd context
5680 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005681 * Unregister for IPv6 address change notifications.
5682 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005683 * Return: None
5684 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005685static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005686{
5687}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005688
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005690 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005691 * @hdd_ctx: Pointer to hdd context
5692 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005693 * Register for IPv6 address change notifications.
5694 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005695 * Return: None
5696 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005697static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005698{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005699 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005700}
5701#endif
5702
5703/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005704 * hdd_register_notifiers - Register netdev notifiers.
5705 * @hdd_ctx: HDD context
5706 *
5707 * Register netdev notifiers like IPv4 and IPv6.
5708 *
5709 * Return: 0 on success and errno on failure
5710 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005711static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005712{
5713 int ret;
5714
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005715 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5716 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305717 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005718
5719 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5720 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5721 if (ret) {
5722 hdd_err("Failed to register IPv4 notifier: %d", ret);
5723 goto unregister_ip6_notifier;
5724 }
5725
5726 return 0;
5727
5728unregister_ip6_notifier:
5729 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005730out:
5731 return ret;
5732
5733}
5734
5735/**
5736 * hdd_unregister_notifiers - Unregister netdev notifiers.
5737 * @hdd_ctx: HDD context
5738 *
5739 * Unregister netdev notifiers like IPv4 and IPv6.
5740 *
5741 * Return: None.
5742 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005743void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005744{
5745 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5746
5747 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005748}
5749
5750/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005751 * hdd_exit_netlink_services - Exit netlink services
5752 * @hdd_ctx: HDD context
5753 *
5754 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5755 * nl service.
5756 *
5757 * Return: None.
5758 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005759static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005760{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005761 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005762 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005763 ptt_sock_deactivate_svc();
5764
5765 nl_srv_exit();
5766}
5767
5768/**
5769 * hdd_init_netlink_services- Init netlink services
5770 * @hdd_ctx: HDD context
5771 *
5772 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5773 * nl service.
5774 *
5775 * Return: 0 on success and errno on failure.
5776 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005777static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005778{
5779 int ret;
5780
Ryan Hsuceddceb2016-04-28 10:20:14 -07005781 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005782 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005783 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005784 goto out;
5785 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005786 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005787
Naveen Rawat910726a2017-03-06 11:42:51 -08005788 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005789 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005790 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005791 goto err_nl_srv;
5792 }
5793
5794 ret = ptt_sock_activate_svc();
5795 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005796 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005797 goto err_nl_srv;
5798 }
5799
5800 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005801 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005802 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005803
5804 ret = cnss_diag_activate_service();
5805 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005806 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005807 goto err_close_cesium;
5808 }
5809
5810 return 0;
5811
5812err_close_cesium:
5813 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005814 ptt_sock_deactivate_svc();
5815err_nl_srv:
5816 nl_srv_exit();
5817out:
5818 return ret;
5819}
5820
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005821/**
5822 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5823 * @hdd_ctx: HDD context.
5824 *
5825 * Destroy RX wakelock.
5826 *
5827 * Return: None.
5828 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005829static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005830{
5831 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5832}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005833
5834/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005835 * hdd_rx_wake_lock_create() - Create RX wakelock
5836 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005837 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005838 * Create RX wakelock.
5839 *
5840 * Return: None.
5841 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005842static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005843{
5844 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5845}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005846
5847/**
5848 * hdd_roc_context_init() - Init ROC context
5849 * @hdd_ctx: HDD context.
5850 *
5851 * Initialize ROC context.
5852 *
5853 * Return: 0 on success and errno on failure.
5854 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005855static int hdd_roc_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005856{
5857 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5858 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5859
5860 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5861
5862 return 0;
5863}
5864
5865/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305866 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5867 * @hdd_ctx: HDD context.
5868 *
5869 * Free memory allocations made in ROC Req Queue nodes.
5870 *
5871 * Return: None.
5872 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005873static void hdd_destroy_roc_req_q(struct hdd_context *hdd_ctx)
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305874{
Jeff Johnson52b50602017-09-30 17:54:56 -07005875 struct hdd_roc_req *hdd_roc_req;
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305876 QDF_STATUS status;
5877
5878 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5879
5880 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5881 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5882 (qdf_list_node_t **) &hdd_roc_req);
5883
5884 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305885 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5886 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305887 QDF_ASSERT(0);
5888 return;
5889 }
5890
Jeff Johnson44d8af92017-10-02 12:25:55 -07005891 if (hdd_roc_req->remain_chan_ctx)
5892 qdf_mem_free(hdd_roc_req->remain_chan_ctx);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305893
5894 qdf_mem_free(hdd_roc_req);
5895 }
5896
5897 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5898}
5899
5900/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005901 * hdd_roc_context_destroy() - Destroy ROC context
5902 * @hdd_ctx: HDD context.
5903 *
5904 * Destroy roc list and flush the pending roc work.
5905 *
5906 * Return: None.
5907 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005908static void hdd_roc_context_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005909{
5910 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305911 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005912 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005913}
5914
5915/**
Houston Hoffman160db392016-10-10 17:37:51 -07005916 * hdd_context_deinit() - Deinitialize HDD context
5917 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005918 *
Houston Hoffman160db392016-10-10 17:37:51 -07005919 * Deinitialize HDD context along with all the feature specific contexts but
5920 * do not free hdd context itself. Caller of this API is supposed to free
5921 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005922 *
Houston Hoffman160db392016-10-10 17:37:51 -07005923 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005924 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005925static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005926{
Houston Hoffman160db392016-10-10 17:37:51 -07005927 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005928
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005929 hdd_roc_context_destroy(hdd_ctx);
5930
5931 hdd_sap_context_destroy(hdd_ctx);
5932
5933 hdd_rx_wake_lock_destroy(hdd_ctx);
5934
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005935 hdd_scan_context_destroy(hdd_ctx);
5936
5937 qdf_list_destroy(&hdd_ctx->hddAdapters);
5938
Houston Hoffman160db392016-10-10 17:37:51 -07005939 return 0;
5940}
5941
5942/**
5943 * hdd_context_destroy() - Destroy HDD context
5944 * @hdd_ctx: HDD context to be destroyed.
5945 *
5946 * Free config and HDD context as well as destroy all the resources.
5947 *
5948 * Return: None
5949 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005950static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005951{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005952 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305953
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305954 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5955
Houston Hoffman160db392016-10-10 17:37:51 -07005956 hdd_context_deinit(hdd_ctx);
5957
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305958 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005959 hdd_ctx->config = NULL;
5960
5961 wiphy_free(hdd_ctx->wiphy);
5962}
5963
5964/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305965 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5966 *
5967 * This function is used to destroy bug report lock
5968 *
5969 * Return: None
5970 */
5971static void wlan_destroy_bug_report_lock(void)
5972{
5973 p_cds_contextType p_cds_context;
5974
5975 p_cds_context = cds_get_global_context();
5976 if (!p_cds_context) {
5977 hdd_err("cds context is NULL");
5978 return;
5979 }
5980
5981 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5982}
5983
5984/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005985 * hdd_wlan_exit() - HDD WLAN exit function
5986 * @hdd_ctx: Pointer to the HDD Context
5987 *
5988 * This is the driver exit point (invoked during rmmod)
5989 *
5990 * Return: None
5991 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005992static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005993{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305994 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005995 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305996 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005997
5998 ENTER();
5999
Arun Khandavallifae92942016-08-01 13:31:08 +05306000 if (QDF_TIMER_STATE_RUNNING ==
6001 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006002 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05306003 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006004 }
6005
Arun Khandavallifae92942016-08-01 13:31:08 +05306006 if (!QDF_IS_STATUS_SUCCESS
6007 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
6008 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006009
Arun Khandavallifae92942016-08-01 13:31:08 +05306010
6011 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006012
Prashanth Bhattaab004382016-10-11 16:08:11 -07006013 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006014
6015#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306016 if (QDF_TIMER_STATE_RUNNING ==
6017 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6018 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006019 }
6020
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306021 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306022 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006023 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006024 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006025 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6026 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6027 hdd_ctx->last_acs_channel_list = NULL;
6028 hdd_ctx->num_of_channels = 0;
6029 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006030#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006031
Arun Khandavallifae92942016-08-01 13:31:08 +05306032 mutex_lock(&hdd_ctx->iface_change_lock);
6033 driver_status = hdd_ctx->driver_status;
6034 mutex_unlock(&hdd_ctx->iface_change_lock);
6035
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006036 /*
6037 * Powersave Offload Case
6038 * Disable Idle Power Save Mode
6039 */
6040 hdd_set_idle_ps_config(hdd_ctx, false);
6041
Arun Khandavallifae92942016-08-01 13:31:08 +05306042 if (driver_status != DRIVER_MODULES_CLOSED) {
6043 hdd_unregister_wext_all_adapters(hdd_ctx);
6044 /*
6045 * Cancel any outstanding scan requests. We are about to close
6046 * all of our adapters, but an adapter structure is what SME
6047 * passes back to our callback function. Hence if there
6048 * are any outstanding scan requests then there is a
6049 * race condition between when the adapter is closed and
6050 * when the callback is invoked. We try to resolve that
6051 * race condition here by canceling any outstanding scans
6052 * before we close the adapters.
6053 * Note that the scans may be cancelled in an asynchronous
6054 * manner, so ideally there needs to be some kind of
6055 * synchronization. Rather than introduce a new
6056 * synchronization here, we will utilize the fact that we are
6057 * about to Request Full Power, and since that is synchronized,
6058 * the expectation is that by the time Request Full Power has
6059 * completed, all scans will be cancelled
6060 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07006061 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05306062 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006063 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006064 hdd_stop_all_adapters(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006065 }
6066
6067 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306068 * Close the scheduler before calling cds_close to make sure
6069 * no thread is scheduled after the each module close is
6070 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006071 */
Jeff Johnson7d562272017-09-13 15:12:54 -07006072 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306073 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05306074 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306075 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006076 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006077
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306078 unregister_netdevice_notifier(&hdd_netdev_notifier);
6079
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006080 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306081
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306082 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6083 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6084 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6085
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006086 /*
6087 * Close CDS
6088 * This frees pMac(HAL) context. There should not be any call
6089 * that requires pMac access after this.
6090 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006091
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006092 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006093 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006094
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006095 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006096
6097 hdd_ipa_cleanup(hdd_ctx);
6098
6099 /* Free up RoC request queue and flush workqueue */
6100 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006101
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306102 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306103 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306104 /*
6105 * If there is re_init failure wiphy would have already de-registered
6106 * check the wiphy status before un-registering again
6107 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306108 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306109 wiphy_unregister(wiphy);
6110 wlan_hdd_cfg80211_deinit(wiphy);
6111 hdd_lpass_notify_stop(hdd_ctx);
6112 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006113
Arun Khandavallifae92942016-08-01 13:31:08 +05306114 hdd_exit_netlink_services(hdd_ctx);
6115 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306116#ifdef FEATURE_WLAN_CH_AVOID
6117 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6118#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306119
6120 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6121 if (driver_status)
6122 hdd_err("Pdev delete failed");
6123
6124 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6125 if (driver_status)
6126 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006127
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006128 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006129}
6130
6131void __hdd_wlan_exit(void)
6132{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006133 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006134
6135 ENTER();
6136
Anurag Chouhan6d760662016-02-20 16:05:43 +05306137 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006138 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006139 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006140 EXIT();
6141 return;
6142 }
6143
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006144 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306145 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006146
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006147 /* Do all the cleanup before deregistering the driver */
6148 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006149
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006150 EXIT();
6151}
6152
6153#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006154/**
6155 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006156 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006157 *
6158 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6159 * Then new ACS request will do a fresh scan without reusing the cached
6160 * scan information.
6161 *
6162 * Return: void
6163 */
Tang Yingying523322d2017-01-17 23:28:43 +08006164static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006165{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006166 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006167
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006168 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006169 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006170 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6171 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6172 hdd_ctx->last_acs_channel_list = NULL;
6173 hdd_ctx->num_of_channels = 0;
6174 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006175
6176 if (!hdd_ctx->hHal)
6177 return;
6178 sme_scan_flush_result(hdd_ctx->hHal);
6179}
6180#endif
6181
6182#ifdef QCA_HT_2040_COEX
6183/**
6184 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
6185 * @adapter: pointer to adapter
6186 * @staId: station id
6187 * @macAddrSTA: station MAC address
6188 * @channel_type: channel type
6189 *
6190 * This function notifies FW with HT20/HT40 mode
6191 *
6192 * Return: 0 if successful, error number otherwise
6193 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006194int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05306195 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006196{
6197 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306198 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006199 struct hdd_context *hdd_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006200
6201 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6202
6203 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306204 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006205 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006207 if (!hdd_ctx->hHal)
6208 return -EINVAL;
6209
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306210 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306212 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006213 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006214 return -EINVAL;
6215 }
6216
6217 return 0;
6218}
6219#endif
6220
6221/**
6222 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6223 * @state: state
6224 *
6225 * This function notifies FW with modem power status
6226 *
6227 * Return: 0 if successful, error number otherwise
6228 */
6229int hdd_wlan_notify_modem_power_state(int state)
6230{
6231 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306232 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006233 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234
Anurag Chouhan6d760662016-02-20 16:05:43 +05306235 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006236 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306237 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006238 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306239
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240 if (!hdd_ctx->hHal)
6241 return -EINVAL;
6242
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306243 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6244 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006245 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006246 state);
6247 return -EINVAL;
6248 }
6249 return 0;
6250}
6251
6252/**
6253 *
6254 * hdd_post_cds_enable_config() - HDD post cds start config helper
6255 * @adapter - Pointer to the HDD
6256 *
6257 * Return: None
6258 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006259QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306261 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006262
6263 /*
6264 * Send ready indication to the HDD. This will kick off the MAC
6265 * into a 'running' state and should kick off an initial scan.
6266 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306267 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6268 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006269 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6270 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306271 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006272 }
6273
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306274 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006275}
6276
6277/* wake lock APIs for HDD */
6278void hdd_prevent_suspend(uint32_t reason)
6279{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306280 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006281}
6282
6283void hdd_allow_suspend(uint32_t reason)
6284{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306285 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006286}
6287
6288void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6289{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306290 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6291 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006292}
6293
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006294/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006295QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006296{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006297
Amar Singhal6f8592b2017-04-26 14:31:58 -07006298 return sme_init_chan_list(hdd_ctx->hHal,
6299 hdd_ctx->reg.alpha2,
6300 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301}
6302
6303/**
6304 * hdd_is_5g_supported() - check if hardware supports 5GHz
6305 * @hdd_ctx: Pointer to the hdd context
6306 *
6307 * HDD function to know if hardware supports 5GHz
6308 *
6309 * Return: true if hardware supports 5GHz
6310 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006311bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006312{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006313 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006314 return true;
6315
Amar Singhal58b45ef2017-08-01 13:43:54 -07006316 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006317 return true;
6318 else
6319 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006320}
6321
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006322static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006323{
6324 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006325 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006326
6327 wiphy = hdd_ctx->wiphy;
6328
6329 /*
6330 * The channel information in
6331 * wiphy needs to be initialized before wiphy registration
6332 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006333 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6334 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006335 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006336 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006337 }
6338
6339#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6340 wiphy->wowlan = &wowlan_support_reg_init;
6341#else
6342 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6343 WIPHY_WOWLAN_MAGIC_PKT |
6344 WIPHY_WOWLAN_DISCONNECT |
6345 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6346 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6347 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6348 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6349 WIPHY_WOWLAN_RFKILL_RELEASE;
6350
6351 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6352 WOW_MAX_FILTERS_PER_LIST);
6353 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6354 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6355#endif
6356
6357 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006358 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306359 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006360 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306361 return ret_val;
6362 }
6363
Amar Singhal5cccafe2017-02-15 12:42:58 -08006364 if (!hdd_ctx->reg_offload)
6365 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366
Amar Singhale4f28ee2015-10-21 14:36:56 -07006367 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006368}
6369
Ravi Joshie2331e82015-07-01 18:18:54 -07006370/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006371 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006372 * @hdd_ctx - handle to hdd context
6373 * @tx_packets - transmit packet count
6374 * @rx_packets - receive packet count
6375 *
6376 * The function controls the bus bandwidth and dynamic control of
6377 * tcp delayed ack configuration
6378 *
6379 * Returns: None
6380 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006381#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006382static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006383 const uint64_t tx_packets,
6384 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006385{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006386 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006387 uint64_t temp_rx = 0;
6388 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006389 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006390 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006391 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006392 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006393 uint16_t index = 0;
6394 bool vote_level_change = false;
6395 bool rx_level_change = false;
6396 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006397
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006398 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006399 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006400 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006401 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006402 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006403 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006404 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006405 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006406
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006407 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006408 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6409 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006410 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006411 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006412 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306413 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306414 if (hdd_ctx->hbw_requested) {
6415 pld_remove_pm_qos(hdd_ctx->parent_dev);
6416 hdd_ctx->hbw_requested = false;
6417 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306418 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006419 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306420 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306421 if (!hdd_ctx->hbw_requested) {
6422 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6423 hdd_ctx->hbw_requested = true;
6424 }
6425
Nirav Shah3bbfa512016-05-12 16:43:49 +05306426 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006427 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306428 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006429 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006430 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006431
Mohit Khannaf8f96822017-05-17 17:11:59 -07006432 qdf_dp_trace_throttle_live_mode(
6433 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6434
Mohit Khannae71e2262015-11-10 09:37:24 -08006435 /* fine-tuning parameters for RX Flows */
6436 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6437
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006438 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006439
Ravi Joshifed83572016-10-07 16:20:37 -07006440 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6441 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6442 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6443 next_rx_level = WLAN_SVC_TP_HIGH;
6444 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006445 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006446 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006447 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006448 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006449
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006451 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006452 next_rx_level, temp_rx);
6453 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006454 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006455 /* Send throughput indication only if it is enabled.
6456 * Disabling tcp_del_ack will revert the tcp stack behavior
6457 * to default delayed ack. Note that this will disable the
6458 * dynamic delayed ack mechanism across the system
6459 */
6460 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306461 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6462 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006463 &next_rx_level,
6464 sizeof(next_rx_level));
6465 }
6466
Mohit Khannae71e2262015-11-10 09:37:24 -08006467 /* fine-tuning parameters for TX Flows */
6468 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6469 hdd_ctx->prev_tx = tx_packets;
6470 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6471 next_tx_level = WLAN_SVC_TP_HIGH;
6472 else
6473 next_tx_level = WLAN_SVC_TP_LOW;
6474
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006475 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006476 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6477 next_tx_level, temp_tx);
6478 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006479 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306480 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6481 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006482 &next_tx_level,
6483 sizeof(next_tx_level));
6484 }
6485
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006486 index = hdd_ctx->hdd_txrx_hist_idx;
6487
6488 if (vote_level_change || tx_level_change || rx_level_change) {
6489 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6490 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6491 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6492 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6493 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6494 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6495 hdd_ctx->hdd_txrx_hist_idx++;
6496 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6497 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006498}
6499
6500#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306501static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006502{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006503 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306504 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006505 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306506 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306507 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6508 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006509 uint64_t total_tx = 0, total_rx = 0;
6510 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306511 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306512 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006513 bool connected = false;
6514 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6515
Prashanth Bhattaab004382016-10-11 16:08:11 -07006516 if (wlan_hdd_validate_context(hdd_ctx))
6517 return;
6518
Jingxiang Gec64e1932017-08-22 14:38:59 +08006519 if (hdd_ctx->isWiphySuspended)
6520 goto restart_timer;
6521
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006522 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306523 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006524 status =
6525 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6526
Jeff Johnson57eb2732017-10-02 11:40:20 -07006527 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006528 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006529 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306530 /*
6531 * Validate magic so we don't end up accessing
6532 * an invalid adapter.
6533 */
6534 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6535 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006536
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006537 if ((adapter->device_mode == QDF_STA_MODE ||
6538 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006539 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6540 != eConnectionState_Associated) {
6541
6542 continue;
6543 }
6544
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006545 if ((adapter->device_mode == QDF_SAP_MODE ||
6546 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006547 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6548
6549 continue;
6550 }
6551
6552 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6553 adapter->prev_tx_packets);
6554 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6555 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306556
6557 if (adapter->device_mode == QDF_SAP_MODE ||
6558 adapter->device_mode == QDF_P2P_GO_MODE ||
6559 adapter->device_mode == QDF_IBSS_MODE) {
6560
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006561 ret = cdp_get_intra_bss_fwd_pkts_count(
6562 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306563 adapter->sessionId,
6564 &fwd_tx_packets, &fwd_rx_packets);
6565 if (ret == A_OK) {
6566 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6567 fwd_tx_packets,
6568 adapter->prev_fwd_tx_packets);
6569 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6570 fwd_tx_packets,
6571 adapter->prev_fwd_rx_packets);
6572 }
6573 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006574
6575 total_rx += adapter->stats.rx_packets;
6576 total_tx += adapter->stats.tx_packets;
6577
6578 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6579 adapter->prev_tx_packets = adapter->stats.tx_packets;
6580 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306581 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6582 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006583 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6584 connected = true;
6585 }
6586
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306587 /* add intra bss forwarded tx and rx packets */
6588 tx_packets += fwd_tx_packets_diff;
6589 rx_packets += fwd_rx_packets_diff;
6590
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006591 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6592 tx_packets += (uint64_t)ipa_tx_packets;
6593 rx_packets += (uint64_t)ipa_rx_packets;
6594
6595 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006596 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006597 return;
6598 }
6599
Yuanyuan Liu13738502016-04-06 17:41:37 -07006600 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006601
6602 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6603 hdd_ipa_uc_stat_request(adapter, 2);
6604
Jingxiang Gec64e1932017-08-22 14:38:59 +08006605restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006606 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006607 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006608 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306609 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006610 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006611 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006612}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006613
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306614/**
6615 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6616 * @arg: Argument of timer function
6617 *
6618 * Schedule a workqueue in this function where all the processing is done.
6619 *
6620 * Return: None.
6621 */
6622static void __hdd_bus_bw_cbk(void *arg)
6623{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006624 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306625
6626 if (wlan_hdd_validate_context(hdd_ctx))
6627 return;
6628
6629 schedule_work(&hdd_ctx->bus_bw_work);
6630}
6631
6632/**
6633 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6634 * @arg: Argument of timer function
6635 *
6636 * Return: None.
6637 */
6638static void hdd_bus_bw_cbk(void *arg)
6639{
6640 cds_ssr_protect(__func__);
6641 __hdd_bus_bw_cbk(arg);
6642 cds_ssr_unprotect(__func__);
6643}
6644
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006645int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006646{
6647 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306648 INIT_WORK(&hdd_ctx->bus_bw_work,
6649 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006650 hdd_ctx->bus_bw_timer_running = false;
6651 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306652 qdf_timer_init(NULL,
6653 &hdd_ctx->bus_bw_timer,
6654 hdd_bus_bw_cbk, (void *)hdd_ctx,
6655 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006656
6657 return 0;
6658}
6659
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006660void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006661{
Dustin Brownfce08d12017-01-17 16:29:38 -08006662 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006663 hdd_reset_tcp_delack(hdd_ctx);
6664
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006665 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306666 cancel_work_sync(&hdd_ctx->bus_bw_work);
6667 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006668 hdd_ctx->bus_bw_timer_running = false;
6669 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006670}
Lin Baic5c06882017-09-21 13:58:43 +08006671
6672void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6673{
6674 if (hdd_ctx)
6675 cancel_work_sync(&hdd_ctx->bus_bw_work);
6676}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006677#endif
6678
6679/**
Nirav Shahed34b212016-04-25 10:59:16 +05306680 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6681 * @hdd_ctx: hdd context
6682 *
6683 * Return: 0 for success or error code
6684 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006685static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306686{
6687 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6688 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6689 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006690 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306691 return -ENOMEM;
6692 }
6693 return 0;
6694}
6695
6696/**
6697 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6698 * @hdd_ctx: hdd context
6699 *
6700 * Return: none
6701 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006702void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306703{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306704 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6705 return;
6706
6707 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6708 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306709}
6710
Nirav Shahda008342016-05-17 18:50:40 +05306711static uint8_t *convert_level_to_string(uint32_t level)
6712{
6713 switch (level) {
6714 /* initialize the wlan sub system */
6715 case WLAN_SVC_TP_NONE:
6716 return "NONE";
6717 case WLAN_SVC_TP_LOW:
6718 return "LOW";
6719 case WLAN_SVC_TP_MEDIUM:
6720 return "MED";
6721 case WLAN_SVC_TP_HIGH:
6722 return "HIGH";
6723 default:
6724 return "INVAL";
6725 }
6726}
6727
Nirav Shahed34b212016-04-25 10:59:16 +05306728
6729/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006730 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6731 * @hdd_ctx: hdd context
6732 *
6733 * Return: none
6734 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006735void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006736{
6737 int i;
6738
6739#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006740 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306741 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006742 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006743 hdd_ctx->config->busBandwidthHighThreshold,
6744 hdd_ctx->config->busBandwidthMediumThreshold,
6745 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006746 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306747 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006748 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006749 hdd_ctx->config->tcpDelackThresholdHigh,
6750 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006751 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306752 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006753#endif
6754
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006755 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306756 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6757
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006758 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006759
6760 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006761 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006762 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006763 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006764 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6765 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006766 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006767 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6768 convert_level_to_string(
6769 hdd_ctx->hdd_txrx_hist[i].
6770 next_vote_level),
6771 convert_level_to_string(
6772 hdd_ctx->hdd_txrx_hist[i].
6773 next_rx_level),
6774 convert_level_to_string(
6775 hdd_ctx->hdd_txrx_hist[i].
6776 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006777 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778}
6779
6780/**
6781 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6782 * @hdd_ctx: hdd context
6783 *
6784 * Return: none
6785 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006786void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006787{
6788 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306789 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6790 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006791}
6792
6793/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006794 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006795 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006796 *
6797 * Return: none
6798 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006799void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800{
6801
Jeff Johnson9d295242017-08-29 14:39:48 -07006802 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006803 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306804 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006805 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306806 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807
6808 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306809 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006810 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006811
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006812 hdd_debug("Netif queue operation statistics:");
6813 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306814 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006815 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306816 curr_time = qdf_system_ticks();
6817 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306818 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306819 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306820 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306821 unpause = adapter->total_unpause_time;
6822 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306823 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306824 pause = adapter->total_pause_time;
6825 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006826 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306827 qdf_system_ticks_to_msecs(total),
6828 qdf_system_ticks_to_msecs(pause),
6829 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006830 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006831
Nirav Shahda008342016-05-17 18:50:40 +05306832 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6833 qdf_time_t pause_delta = 0;
6834
6835 if (adapter->pause_map & (1 << i))
6836 pause_delta = delta;
6837
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006838 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006839 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006840 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006841 hdd_reason_type_to_string(i),
6842 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306843 adapter->queue_oper_stats[i].unpause_count,
6844 qdf_system_ticks_to_msecs(
6845 adapter->queue_oper_stats[i].total_pause_time +
6846 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006847 }
6848
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006849 hdd_debug("Netif queue operation history:");
6850 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306851 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6852
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006853 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006854
6855 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006856 /* using hdd_log to avoid printing function name */
6857 if (adapter->queue_oper_history[i].time == 0)
6858 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006859 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006860 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306861 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862 adapter->queue_oper_history[i].time),
6863 hdd_action_type_to_string(
6864 adapter->queue_oper_history[i].netif_action),
6865 hdd_reason_type_to_string(
6866 adapter->queue_oper_history[i].netif_reason),
6867 adapter->queue_oper_history[i].pause_map);
6868 }
6869
6870 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6871 adapter_node = next;
6872 }
6873
6874
6875}
6876
6877/**
6878 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6879 * @hdd_ctx: hdd context
6880 *
6881 * Return: none
6882 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006883void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006884{
Jeff Johnson9d295242017-08-29 14:39:48 -07006885 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006886 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306887 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888
6889 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306890 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006891 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006892
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306893 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006894 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306895 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006896 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306897 adapter->history_index = 0;
6898 adapter->start_time = adapter->last_time = qdf_system_ticks();
6899 adapter->total_pause_time = 0;
6900 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006901 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6902 adapter_node = next;
6903 }
6904}
6905
6906/**
6907 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6908 * @halHandle: Hal handle
6909 * @pContext: Pointer to the context
6910 * @sessionId: Session ID
6911 * @scanId: Scan ID
6912 * @status: Status
6913 *
6914 * This is the callback to be executed when 11d scan is completed to flush out
6915 * the scan results
6916 *
6917 * 11d scan is done during driver load and is a passive scan on all
6918 * channels supported by the device, 11d scans may find some APs on
6919 * frequencies which are forbidden to be used in the regulatory domain
6920 * the device is operating in. If these APs are notified to the supplicant
6921 * it may try to connect to these APs, thus flush out all the scan results
6922 * which are present in SME after 11d scan is done.
6923 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306924 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006925 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306926static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006927 uint8_t sessionId, uint32_t scanId,
6928 eCsrScanStatus status)
6929{
6930 ENTER();
6931
6932 sme_scan_flush_result(halHandle);
6933
6934 EXIT();
6935
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306936 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006937}
6938
6939#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6940/**
6941 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6942 * @hdd_ctx: hdd global context
6943 *
6944 * Return: none
6945 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006946static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006947{
6948 uint8_t i;
6949
6950 mutex_init(&hdd_ctx->op_ctx.op_lock);
6951 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6952 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6953 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6954 }
6955}
6956#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006957static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006958{
6959}
6960#endif
6961
Yingying Tang95409972016-10-20 15:16:15 +08006962#ifdef WLAN_FEATURE_WOW_PULSE
6963/**
6964 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006965 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006966 * @enable: enable or disable this behaviour
6967 *
6968 * Return: int
6969 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006970static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006971{
6972 struct hdd_config *pcfg_ini = phddctx->config;
6973 struct wow_pulse_mode wow_pulse_set_info;
6974 QDF_STATUS status;
6975
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006976 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006977
6978 if (false == phddctx->config->wow_pulse_support)
6979 return 0;
6980
6981 /* prepare the request to send to SME */
6982 if (enable == true) {
6983 wow_pulse_set_info.wow_pulse_enable = true;
6984 wow_pulse_set_info.wow_pulse_pin =
6985 pcfg_ini->wow_pulse_pin;
6986 wow_pulse_set_info.wow_pulse_interval_low =
6987 pcfg_ini->wow_pulse_interval_low;
6988 wow_pulse_set_info.wow_pulse_interval_high =
6989 pcfg_ini->wow_pulse_interval_high;
6990 } else {
6991 wow_pulse_set_info.wow_pulse_enable = false;
6992 wow_pulse_set_info.wow_pulse_pin = 0;
6993 wow_pulse_set_info.wow_pulse_interval_low = 0;
6994 wow_pulse_set_info.wow_pulse_interval_high = 0;
6995 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006996 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006997 wow_pulse_set_info.wow_pulse_enable,
6998 wow_pulse_set_info.wow_pulse_pin,
6999 wow_pulse_set_info.wow_pulse_interval_low,
7000 wow_pulse_set_info.wow_pulse_interval_high);
7001
7002 status = sme_set_wow_pulse(&wow_pulse_set_info);
7003 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007004 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007005 return -EIO;
7006 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007007 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007008 return 0;
7009}
7010#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007011static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007012{
7013 return 0;
7014}
7015#endif
7016
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007017#ifdef WLAN_FEATURE_FASTPATH
7018/**
7019 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7020 * @hdd_cfg: hdd config
7021 * @context: lower layer context
7022 *
7023 * Return: none
7024 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307025void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007026 void *context)
7027{
7028 if (hdd_cfg->fastpath_enable)
7029 hif_enable_fastpath(context);
7030}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007031#endif
7032
Yuanyuan Liu13738502016-04-06 17:41:37 -07007033#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007034/**
7035 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007036 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007037 * @level: thermal level
7038 *
7039 * Change IPA data path to SW path when the thermal throttle level greater
7040 * than 0, and restore the original data path when throttle level is 0
7041 *
7042 * Return: none
7043 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007044static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007045{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007046 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007047
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007048 /* Change IPA to SW path when throttle level greater than 0 */
7049 if (level > THROTTLE_LEVEL_0)
7050 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7051 else
7052 /* restore original concurrency mode */
7053 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7054}
7055
7056/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307057 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7058 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307059 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007060 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307061 * Get a safe channel to restart SAP. PCL already takes into account the
7062 * unsafe channels. So, the PCL is validated with the ACS range to provide
7063 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007064 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307065 * Return: Channel number to restart SAP in case of success. In case of any
7066 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007067 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307068static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007069 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007070{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307071 struct sir_pcl_list pcl;
7072 QDF_STATUS status;
7073 uint32_t i, j;
7074 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007075 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307076 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007077
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307078 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7079 if (!hdd_ctx) {
7080 hdd_err("invalid HDD context");
7081 return INVALID_CHANNEL_ID;
7082 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007083
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307084 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7085 if (!hal_handle) {
7086 hdd_err("invalid HAL handle");
7087 return INVALID_CHANNEL_ID;
7088 }
7089
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007090 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7091 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007092 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7093 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307094 if (QDF_IS_STATUS_ERROR(status)) {
7095 hdd_err("Get PCL failed");
7096 return INVALID_CHANNEL_ID;
7097 }
7098
Frank Liudc2cefb2017-06-21 15:38:18 +08007099 /*
7100 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7101 * channel is unsafe channel, the pcl may be empty, instead of return,
7102 * try to choose a safe channel from acs range.
7103 */
7104 if (!pcl.pcl_len)
7105 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307106
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007107 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307108 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7109 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7110
7111 /* PCL already takes unsafe channel into account */
7112 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007113 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307114 if ((pcl.pcl_list[i] >=
7115 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7116 (pcl.pcl_list[i] <=
7117 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007118 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307119 return pcl.pcl_list[i];
7120 }
7121 }
7122
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007123 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307124
7125 /* Try for safe channel from all valid channel */
7126 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007127 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307128 &pcl.pcl_len);
7129 if (QDF_IS_STATUS_ERROR(status)) {
7130 hdd_err("error in getting valid channel list");
7131 return INVALID_CHANNEL_ID;
7132 }
7133
7134 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007135 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307136 found = false;
7137 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007138 if (pcl.pcl_list[i] ==
7139 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007140 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307141 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007142 break;
7143 }
7144 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307145
7146 if (found)
7147 continue;
7148
7149 if ((pcl.pcl_list[i] >=
7150 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7151 (pcl.pcl_list[i] <=
7152 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007153 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307154 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007155 }
7156 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307157
7158 return INVALID_CHANNEL_ID;
7159}
7160
7161/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007162 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307163 * @adapter: AP adapter
7164 * @channel: Channel
7165 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007166 * Moves the SAP interface by invoking the function which
7167 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307168 *
7169 * Return: None
7170 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007171void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307172{
Jeff Johnson87251032017-08-29 13:31:11 -07007173 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307174 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007175 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307176
7177 if (!adapter) {
7178 hdd_err("invalid adapter");
7179 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007180 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307181
7182 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7183
7184 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7185 if (!hal_handle) {
7186 hdd_err("invalid HAL handle");
7187 return;
7188 }
7189
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007190 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7191
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307192 hdd_ap_ctx->sapConfig.channel = channel;
7193 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7194 hdd_ap_ctx->sapConfig.ch_width_orig;
7195
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007196 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307197 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7198
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007199 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7200 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307201 hdd_ap_ctx->sapConfig.sec_ch,
7202 &hdd_ap_ctx->sapConfig.ch_params);
7203
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007204 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7205 adapter->sessionId, channel,
7206 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007207}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307208
Jeff Johnson9d295242017-08-29 14:39:48 -07007209int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307210{
7211 struct hdd_external_acs_timer_context *timer_context;
7212
7213 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7214
7215 if (QDF_TIMER_STATE_RUNNING ==
7216 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7217 ap.vendor_acs_timer)) {
7218 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7219 }
7220 timer_context = (struct hdd_external_acs_timer_context *)
7221 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7222 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307223 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307224 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307225 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7226 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307227 hdd_notice("Updated ACS config to nl with reason %d", reason);
7228
7229 return 0;
7230}
7231
Agrawal Ashish467dde42016-09-08 18:44:22 +05307232/**
7233 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7234 * @hdd_ctx: hdd context pointer
7235 *
7236 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7237 * and if ACS is enabled, driver will ask userspace to restart the
7238 * sap. User space on LTE coex indication restart driver.
7239 *
7240 * Return - none
7241 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007242void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307243{
7244 QDF_STATUS status;
7245 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007246 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307247 uint32_t i;
7248 bool found = false;
7249 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007250
Agrawal Ashish467dde42016-09-08 18:44:22 +05307251 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7252 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007253 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307254
7255 if (!adapter_temp) {
7256 hdd_err("adapter is NULL, moving to next one");
7257 goto next_adapater;
7258 }
7259
7260 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7261 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007262 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307263 adapter_temp->device_mode,
7264 adapter_temp->sessionCtx.ap.sapConfig.
7265 acs_cfg.acs_mode);
7266 goto next_adapater;
7267 }
7268
7269 found = false;
7270 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007271 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307272 hdd_ctxt->unsafe_channel_list[i]) {
7273 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007274 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307275 adapter_temp->sessionCtx.ap.operatingChannel);
7276 break;
7277 }
7278 }
7279
7280 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007281 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307282 adapter_temp->sessionCtx.ap.operatingChannel);
7283 goto next_adapater;
7284 }
7285
Kapil Gupta8878ad92017-02-13 11:56:04 +05307286 if (hdd_ctxt->config->vendor_acs_support &&
7287 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7288 hdd_update_acs_timer_reason(adapter_temp,
7289 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7290 goto next_adapater;
7291 } else
7292 restart_chan =
7293 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307294 adapter_temp);
7295 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007296 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307297 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007298 /*
7299 * SAP restart due to unsafe channel. While
7300 * restarting the SAP, make sure to clear
7301 * acs_channel, channel to reset to
7302 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307303 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007304 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307305 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7306 adapter_temp->sessionCtx.ap.sapConfig.channel =
7307 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007308 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307309 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7310 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007311 hdd_debug("driver to start sap: %d",
7312 hdd_ctxt->config->sap_internal_restart);
7313 if (hdd_ctxt->config->sap_internal_restart)
7314 hdd_switch_sap_channel(adapter_temp, restart_chan);
7315 else
7316 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307317 }
7318
7319next_adapater:
7320 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7321 adapter_node = next;
7322 }
7323}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307324
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007325/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007326 * hdd_init_channel_avoidance() - Initialize channel avoidance
7327 * @hdd_ctx: HDD global context
7328 *
7329 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007330 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007331 * down to the lower layers. Then subscribe to subsequent channel
7332 * avoidance events.
7333 *
7334 * Return: None
7335 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007336static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007337{
7338 uint16_t unsafe_channel_count;
7339 int index;
7340
Yuanyuan Liu13738502016-04-06 17:41:37 -07007341 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7342 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007343 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007344 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007345
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007346 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007347 hdd_ctx->unsafe_channel_count);
7348
Anurag Chouhan6d760662016-02-20 16:05:43 +05307349 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007350 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007351
7352 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007353 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007354 hdd_ctx->unsafe_channel_list[index]);
7355
7356 }
7357
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007358}
Dustin Brown676a2322017-08-15 13:16:13 -07007359
Jeff Johnson9d295242017-08-29 14:39:48 -07007360static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007361 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007362{
7363 uint8_t restart_chan;
7364
7365 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7366 if (!restart_chan) {
7367 hdd_alert("fail to restart SAP");
7368 return;
7369 }
7370
7371 /* SAP restart due to unsafe channel. While restarting
7372 * the SAP, make sure to clear acs_channel, channel to
7373 * reset to 0. Otherwise these settings will override
7374 * the ACS while restart.
7375 */
7376 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7377 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7378
7379 hdd_debug("sending coex indication");
7380
7381 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7382 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7383 hdd_switch_sap_channel(adapter, restart_chan);
7384}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007385
7386int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7387 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7388{
7389 uint32_t size;
7390 uint16_t *unsafe_list;
7391 uint16_t chan_count;
7392
7393 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7394 return -EINVAL;
7395
7396 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7397 NUM_CHANNELS);
7398 if (chan_count) {
7399 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7400 unsafe_list = qdf_mem_malloc(size);
7401 if (!unsafe_list) {
7402 hdd_err("No memory for unsafe chan list size%d",
7403 size);
7404 return -ENOMEM;
7405 }
7406 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7407 } else {
7408 unsafe_list = NULL;
7409 }
7410
7411 *local_unsafe_list = unsafe_list;
7412 *local_unsafe_list_count = chan_count;
7413
7414 return 0;
7415}
7416
7417bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7418 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7419{
7420 int i, j;
7421
7422 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7423 return true;
7424 if (local_unsafe_list_count == 0)
7425 return false;
7426 for (i = 0; i < local_unsafe_list_count; i++) {
7427 for (j = 0; j < local_unsafe_list_count; j++)
7428 if (local_unsafe_list[i] ==
7429 hdd_ctx->unsafe_channel_list[j])
7430 break;
7431 if (j >= local_unsafe_list_count)
7432 break;
7433 }
7434 if (i >= local_unsafe_list_count) {
7435 hdd_info("unsafe chan list same");
7436 return false;
7437 }
7438
7439 return true;
7440}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007441#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007442static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007443{
7444}
Dustin Brown676a2322017-08-15 13:16:13 -07007445
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007446static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007447{
7448}
Dustin Brown676a2322017-08-15 13:16:13 -07007449
Jeff Johnson9d295242017-08-29 14:39:48 -07007450static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007451 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007452{
7453 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7454}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007455#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007456
7457/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007458 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7459 * user space
7460 * @frame_ind: Management frame data to be informed.
7461 *
7462 * This function is used to indicate management frame to
7463 * user space
7464 *
7465 * Return: None
7466 *
7467 */
7468void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7469{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007470 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007471 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007472 int i;
7473
Rajeev Kumard004abc2016-02-17 12:09:56 -08007474 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007475 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007476
7477 if (0 != wlan_hdd_validate_context(hdd_ctx))
7478 return;
7479
7480 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7481 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7482 adapter =
7483 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7484 if (adapter)
7485 break;
7486 }
7487 } else {
7488 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7489 frame_ind->sessionId);
7490 }
7491
7492 if ((NULL != adapter) &&
7493 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7494 __hdd_indicate_mgmt_frame(adapter,
7495 frame_ind->frame_len,
7496 frame_ind->frameBuf,
7497 frame_ind->frameType,
7498 frame_ind->rxChan,
7499 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007500}
7501
Kapil Gupta8878ad92017-02-13 11:56:04 +05307502void hdd_acs_response_timeout_handler(void *context)
7503{
7504 struct hdd_external_acs_timer_context *timer_context =
7505 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007506 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007507 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307508 uint8_t reason;
7509
7510 ENTER();
7511 if (!timer_context) {
7512 hdd_err("invlaid timer context");
7513 return;
7514 }
7515 adapter = timer_context->adapter;
7516 reason = timer_context->reason;
7517
7518
7519 if ((!adapter) ||
7520 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7521 hdd_err("invalid adapter or adapter has invalid magic");
7522 return;
7523 }
7524 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7525 if (wlan_hdd_validate_context(hdd_ctx))
7526 return;
7527
7528 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7529 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7530 else
7531 return;
7532
7533 hdd_err("ACS timeout happened for %s reason %d",
7534 adapter->dev->name, reason);
7535 switch (reason) {
7536 /* SAP init case */
7537 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7538 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7539 false);
7540 wlan_hdd_cfg80211_start_acs(adapter);
7541 break;
7542 /* DFS detected on current channel */
7543 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7544 wlan_sap_update_next_channel(
7545 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7546 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7547 adapter->sessionId);
7548 break;
7549 /* LTE coex event on current channel */
7550 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7551 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7552 break;
7553 default:
7554 hdd_info("invalid reason for timer invoke");
7555
7556 }
7557}
7558
Rajeev Kumard004abc2016-02-17 12:09:56 -08007559/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007560 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7561 * @hdd_ctx: HDD context
7562 *
7563 * Disables all the dual mac features like DBS, Agile DFS etc.
7564 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307565 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007566 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007567static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007568{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007569 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307570 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007571
7572 if (!hdd_ctx) {
7573 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307574 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007575 }
7576
7577 cfg.scan_config = 0;
7578 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007579 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007580
7581 hdd_debug("Disabling all dual mac features...");
7582
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007583 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307584 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007585 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7586 return status;
7587 }
7588
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307589 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007590}
7591
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007592static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007593wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007594{
7595 struct policy_mgr_dual_mac_config cfg = {0};
7596 QDF_STATUS status;
7597
7598 if (!hdd_ctx) {
7599 hdd_err("HDD context is NULL");
7600 return QDF_STATUS_E_FAILURE;
7601 }
7602
7603 cfg.scan_config = 0;
7604 cfg.fw_mode_config = 0;
7605 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7606 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7607 hdd_ctx->hdd_psoc, &cfg.scan_config,
7608 &cfg.fw_mode_config,
7609 hdd_ctx->config->dual_mac_feature_disable);
7610
7611 if (status != QDF_STATUS_SUCCESS) {
7612 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7613 status);
7614 return status;
7615 }
7616
7617 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7618 cfg.scan_config, cfg.fw_mode_config);
7619
7620 status = sme_soc_set_dual_mac_config(cfg);
7621 if (status != QDF_STATUS_SUCCESS) {
7622 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7623 return status;
7624 }
7625
7626 return QDF_STATUS_SUCCESS;
7627}
7628
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007629/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007630 * hdd_override_ini_config - Override INI config
7631 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007632 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007633 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007634 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007635 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007636 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007637static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007638{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007639
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007640 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7641 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007642 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007643 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007644 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007645 if (0 == enable_11d || 1 == enable_11d) {
7646 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007647 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007648 }
Leo Chang11545d62016-10-17 14:53:50 -07007649
7650 if (!hdd_ipa_is_present(hdd_ctx))
7651 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007652}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007653
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007654/**
7655 * hdd_set_trace_level_for_each - Set trace level for each INI config
7656 * @hdd_ctx - HDD context
7657 *
7658 * Set trace level for each module based on INI config.
7659 *
7660 * Return: None
7661 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007662static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007663{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307664 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7665 hdd_ctx->config->qdf_trace_enable_wdi);
7666 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7667 hdd_ctx->config->qdf_trace_enable_hdd);
7668 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7669 hdd_ctx->config->qdf_trace_enable_sme);
7670 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7671 hdd_ctx->config->qdf_trace_enable_pe);
7672 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7673 hdd_ctx->config->qdf_trace_enable_wma);
7674 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7675 hdd_ctx->config->qdf_trace_enable_sys);
7676 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7677 hdd_ctx->config->qdf_trace_enable_qdf);
7678 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7679 hdd_ctx->config->qdf_trace_enable_sap);
7680 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7681 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7682 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7683 hdd_ctx->config->qdf_trace_enable_bmi);
7684 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7685 hdd_ctx->config->qdf_trace_enable_cfg);
7686 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7687 hdd_ctx->config->qdf_trace_enable_epping);
7688 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7689 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7690 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007691 hdd_ctx->config->qdf_trace_enable_txrx);
7692 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7693 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307694 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7695 hdd_ctx->config->qdf_trace_enable_htc);
7696 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7697 hdd_ctx->config->qdf_trace_enable_hif);
7698 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7699 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7700 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7701 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007702 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7703 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007704 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7705 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007706 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7707 hdd_ctx->config->qdf_trace_enable_regulatory);
7708
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007709 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007710}
7711
7712/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007713 * hdd_context_init() - Initialize HDD context
7714 * @hdd_ctx: HDD context.
7715 *
7716 * Initialize HDD context along with all the feature specific contexts.
7717 *
7718 * return: 0 on success and errno on failure.
7719 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007720static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007721{
7722 int ret;
7723
7724 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7725 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7726
7727 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307728 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007729
7730 init_completion(&hdd_ctx->mc_sus_event_var);
7731 init_completion(&hdd_ctx->ready_to_suspend);
7732
7733 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307734 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007735 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307736
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007737 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7738
7739 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7740
7741 ret = hdd_scan_context_init(hdd_ctx);
7742 if (ret)
7743 goto list_destroy;
7744
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007745 hdd_rx_wake_lock_create(hdd_ctx);
7746
7747 ret = hdd_sap_context_init(hdd_ctx);
7748 if (ret)
7749 goto scan_destroy;
7750
7751 ret = hdd_roc_context_init(hdd_ctx);
7752 if (ret)
7753 goto sap_destroy;
7754
7755 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7756
7757 hdd_init_offloaded_packets_ctx(hdd_ctx);
7758
7759 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7760 hdd_ctx->config);
7761 if (ret)
7762 goto roc_destroy;
7763
7764 return 0;
7765
7766roc_destroy:
7767 hdd_roc_context_destroy(hdd_ctx);
7768
7769sap_destroy:
7770 hdd_sap_context_destroy(hdd_ctx);
7771
7772scan_destroy:
7773 hdd_scan_context_destroy(hdd_ctx);
7774 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007775list_destroy:
7776 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007777
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007778 return ret;
7779}
7780
7781/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307782 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7783 * @hdd_ctx: pointer to hdd context
7784 *
7785 * Return: status of initialization
7786 * 0 - success
7787 * negative value - failure
7788 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007789static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307790{
7791 int ret;
7792
7793 if (!hdd_ctx->config->probe_req_ie_whitelist)
7794 return 0;
7795
7796 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7797 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7798 hdd_ctx->config->probe_req_ie_whitelist = false;
7799 return -EINVAL;
7800 }
7801
7802 /* parse ini string probe req oui */
7803 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7804 if (ret) {
7805 hdd_err("parsing error: disable ie whitelisting");
7806 hdd_ctx->config->probe_req_ie_whitelist = false;
7807 }
7808
7809 return ret;
7810}
7811
7812/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007813 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307814 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007815 *
7816 * Allocate and initialize HDD context. HDD context is allocated as part of
7817 * wiphy allocation and then context is initialized.
7818 *
7819 * Return: HDD context on success and ERR_PTR on failure
7820 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007821static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007822{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307823 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007824 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007825 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007826
7827 ENTER();
7828
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007829 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007830 if (hdd_ctx == NULL) {
7831 ret = -ENOMEM;
7832 goto err_out;
7833 }
7834
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007835 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307836 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007837
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307838 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007839 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007840 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007841 ret = -ENOMEM;
7842 goto err_free_hdd_context;
7843 }
7844
7845 /* Read and parse the qcom_cfg.ini file */
7846 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307847 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307848 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007849 WLAN_INI_FILE);
7850 ret = -EINVAL;
7851 goto err_free_config;
7852 }
7853
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307854 ie_whitelist_attrs_init(hdd_ctx);
7855
Dustin Brown7f939932017-05-18 15:02:17 -07007856 hdd_debug("setting timer multiplier: %u",
7857 hdd_ctx->config->timer_multiplier);
7858 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7859
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007860
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307861 if (hdd_ctx->config->fhostNSOffload)
7862 hdd_ctx->ns_offload_enable = true;
7863
Abhishek Singh5ea86532016-04-27 14:10:53 +05307864 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7865
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007866 hdd_override_ini_config(hdd_ctx);
7867
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007868 ret = hdd_context_init(hdd_ctx);
7869
7870 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007871 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007872
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007873 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307874 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007875
Anurag Chouhan6d760662016-02-20 16:05:43 +05307876 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007877 goto skip_multicast_logging;
7878
7879 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7880
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007881 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7882 if (ret)
7883 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307884
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007885 ret = hdd_init_netlink_services(hdd_ctx);
7886 if (ret)
7887 goto err_deinit_txrx_histogram;
7888
Dustin Brown7b3dea22017-07-10 13:02:47 -07007889 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7890 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307891
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007892skip_multicast_logging:
7893 hdd_set_trace_level_for_each(hdd_ctx);
7894
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007895 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7896
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007897 EXIT();
7898
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007899 return hdd_ctx;
7900
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007901err_deinit_txrx_histogram:
7902 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7903
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007904err_deinit_hdd_context:
7905 hdd_context_deinit(hdd_ctx);
7906
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007907err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307908 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007909
7910err_free_hdd_context:
7911 wiphy_free(hdd_ctx->wiphy);
7912
7913err_out:
7914 return ERR_PTR(ret);
7915}
7916
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007917#ifdef WLAN_OPEN_P2P_INTERFACE
7918/**
7919 * hdd_open_p2p_interface - Open P2P interface
7920 * @hdd_ctx: HDD context
7921 * @rtnl_held: True if RTNL lock held
7922 *
7923 * Open P2P interface during probe. This function called to open the P2P
7924 * interface at probe along with STA interface.
7925 *
7926 * Return: 0 on success and errno on failure
7927 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007928static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007929{
Jeff Johnson9d295242017-08-29 14:39:48 -07007930 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007931 uint8_t *p2p_dev_addr;
7932
7933 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7934 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307935 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007936 hdd_ctx->config->intfMacAddr[0].bytes,
7937 sizeof(tSirMacAddr));
7938
7939 /*
7940 * Generate the P2P Device Address. This consists of
7941 * the device's primary MAC address with the locally
7942 * administered bit set.
7943 */
7944 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7945 } else {
7946 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7947 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007948 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007949 return -ENOSPC;
7950 }
7951
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307952 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307953 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007954 }
7955
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007956 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007957 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007958 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007959
7960 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007961 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007962 return -ENOSPC;
7963 }
7964
7965 return 0;
7966}
7967#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007968static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007969 bool rtnl_held)
7970{
7971 return 0;
7972}
7973#endif
7974
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007975static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007976{
Jeff Johnson9d295242017-08-29 14:39:48 -07007977 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007978 int ret = 0;
7979
7980 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7981 wlan_hdd_get_intf_addr(hdd_ctx),
7982 NET_NAME_UNKNOWN, rtnl_held);
7983 if (adapter == NULL) {
7984 hdd_err("Failed to open 802.11p interface");
7985 ret = -ENOSPC;
7986 }
7987
7988 return ret;
7989}
7990
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007991/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307992 * hdd_start_station_adapter()- Start the Station Adapter
7993 * @adapter: HDD adapter
7994 *
7995 * This function initializes the adapter for the station mode.
7996 *
7997 * Return: 0 on success or errno on failure.
7998 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007999int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308000{
8001 QDF_STATUS status;
8002
8003 ENTER_DEV(adapter->dev);
8004
8005 status = hdd_init_station_mode(adapter);
8006
8007 if (QDF_STATUS_SUCCESS != status) {
8008 hdd_err("Error Initializing station mode: %d", status);
8009 return qdf_status_to_os_return(status);
8010 }
8011
Arun Khandavallifae92942016-08-01 13:31:08 +05308012 hdd_register_tx_flow_control(adapter,
8013 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008014 hdd_tx_resume_cb,
8015 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308016
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308017 EXIT();
8018 return 0;
8019}
8020
8021/**
8022 * hdd_start_ap_adapter()- Start AP Adapter
8023 * @adapter: HDD adapter
8024 *
8025 * This function initializes the adapter for the AP mode.
8026 *
8027 * Return: 0 on success errno on failure.
8028 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008029int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308030{
8031 QDF_STATUS status;
8032
8033 ENTER();
8034
Arun Khandavallicc544b32017-01-30 19:52:16 +05308035 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308036
8037 if (QDF_STATUS_SUCCESS != status) {
8038 hdd_err("Error Initializing the AP mode: %d", status);
8039 return qdf_status_to_os_return(status);
8040 }
8041
Arun Khandavallifae92942016-08-01 13:31:08 +05308042 hdd_register_tx_flow_control(adapter,
8043 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008044 hdd_softap_tx_resume_cb,
8045 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308046
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308047 EXIT();
8048 return 0;
8049}
8050
8051/**
8052 * hdd_start_ftm_adapter()- Start FTM adapter
8053 * @adapter: HDD adapter
8054 *
8055 * This function initializes the adapter for the FTM mode.
8056 *
8057 * Return: 0 on success or errno on failure.
8058 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008059int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308060{
8061 QDF_STATUS qdf_status;
8062
8063 ENTER_DEV(adapter->dev);
8064
8065 qdf_status = hdd_init_tx_rx(adapter);
8066
8067 if (QDF_STATUS_SUCCESS != qdf_status) {
8068 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8069 return qdf_status_to_os_return(qdf_status);
8070 }
8071
8072 return 0;
8073 EXIT();
8074}
8075
8076/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008077 * hdd_open_interfaces - Open all required interfaces
8078 * hdd_ctx: HDD context
8079 * rtnl_held: True if RTNL lock is held
8080 *
8081 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8082 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008083 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008084 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008085static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008086{
Jeff Johnson9d295242017-08-29 14:39:48 -07008087 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008088 int ret;
8089
Ravi Joshia307f632017-07-17 23:41:41 -07008090 /* open monitor mode adapter if con_mode is monitor mode */
8091 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8092 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8093 wlan_hdd_get_intf_addr(hdd_ctx),
8094 NET_NAME_UNKNOWN, rtnl_held);
8095 if (!adapter) {
8096 hdd_err("open adapter failed");
8097 return -ENOSPC;
8098 }
8099 return 0;
8100 }
8101
Jeff Johnson957bc272017-02-02 08:54:48 -08008102 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308103 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008104 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008105
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008106 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008107 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008108 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008109
8110 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008111 return -ENOSPC;
8112
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008113 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8114 adapter->fast_roaming_allowed = true;
8115
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008116 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8117 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008118 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008119
8120 /* Open 802.11p Interface */
8121 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008122 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8123 if (ret)
8124 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008125 }
8126
Jeff Johnson957bc272017-02-02 08:54:48 -08008127 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008128
Jeff Johnson957bc272017-02-02 08:54:48 -08008129err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008130 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008131 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008132}
8133
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008134/**
8135 * hdd_update_country_code - Update country code
8136 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008137 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008138 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008139 *
8140 * Return: 0 on success and errno on failure
8141 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008142static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008143{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008144 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008145 return 0;
8146
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008147 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008148}
8149
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308150#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8151/**
8152 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8153 * @cds_cfg: CDS Configuration
8154 * @hdd_ctx: Pointer to hdd context
8155 *
8156 * Return: none
8157 */
8158static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8159 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008160 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308161{
8162 cds_cfg->tx_flow_stop_queue_th =
8163 hdd_ctx->config->TxFlowStopQueueThreshold;
8164 cds_cfg->tx_flow_start_queue_offset =
8165 hdd_ctx->config->TxFlowStartQueueOffset;
8166}
8167#else
8168static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8169 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008170 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308171{
8172}
8173#endif
8174
8175#ifdef FEATURE_WLAN_RA_FILTERING
8176/**
8177 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8178 * @cds_cfg: CDS Configuration
8179 * @hdd_ctx: Pointer to hdd context
8180 *
8181 * Return: none
8182 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308183static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008184 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308185{
8186 cds_cfg->ra_ratelimit_interval =
8187 hdd_ctx->config->RArateLimitInterval;
8188 cds_cfg->is_ra_ratelimit_enabled =
8189 hdd_ctx->config->IsRArateLimitEnabled;
8190}
8191#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308192static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008193 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308194{
8195}
8196#endif
8197
8198/**
8199 * hdd_update_cds_config() - API to update cds configuration parameters
8200 * @hdd_ctx: HDD Context
8201 *
8202 * Return: 0 for Success, errno on failure
8203 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008204static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308205{
8206 struct cds_config_info *cds_cfg;
8207
8208 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8209 if (!cds_cfg) {
8210 hdd_err("failed to allocate cds config");
8211 return -ENOMEM;
8212 }
8213
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008214 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008215 if (!hdd_ctx->config->nMaxPsPoll ||
8216 !hdd_ctx->config->enablePowersaveOffload) {
8217 cds_cfg->powersave_offload_enabled =
8218 hdd_ctx->config->enablePowersaveOffload;
8219 } else {
8220 if ((hdd_ctx->config->enablePowersaveOffload ==
8221 PS_QPOWER_NODEEPSLEEP) ||
8222 (hdd_ctx->config->enablePowersaveOffload ==
8223 PS_LEGACY_NODEEPSLEEP))
8224 cds_cfg->powersave_offload_enabled =
8225 PS_LEGACY_NODEEPSLEEP;
8226 else
8227 cds_cfg->powersave_offload_enabled =
8228 PS_LEGACY_DEEPSLEEP;
8229 hdd_info("Qpower disabled in cds config, %d",
8230 cds_cfg->powersave_offload_enabled);
8231 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308232 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8233 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8234 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8235 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8236 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8237
8238 /* Here ol_ini_info is used to store ini status of arp offload
8239 * ns offload and others. Currently 1st bit is used for arp
8240 * off load and 2nd bit for ns offload currently, rest bits are unused
8241 */
8242 if (hdd_ctx->config->fhostArpOffload)
8243 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8244 if (hdd_ctx->config->fhostNSOffload)
8245 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8246
8247 /*
8248 * Copy the DFS Phyerr Filtering Offload status.
8249 * This parameter reflects the value of the
8250 * dfs_phyerr_filter_offload flag as set in the ini.
8251 */
8252 cds_cfg->dfs_phyerr_filter_offload =
8253 hdd_ctx->config->fDfsPhyerrFilterOffload;
8254 if (hdd_ctx->config->ssdp)
8255 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8256
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308257 cds_cfg->force_target_assert_enabled =
8258 hdd_ctx->config->crash_inject_enabled;
8259
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308260 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8261 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8262
8263 cds_cfg->ap_maxoffload_reorderbuffs =
8264 hdd_ctx->config->apMaxOffloadReorderBuffs;
8265
8266 cds_cfg->ap_disable_intrabss_fwd =
8267 hdd_ctx->config->apDisableIntraBssFwd;
8268
8269 cds_cfg->dfs_pri_multiplier =
8270 hdd_ctx->config->dfsRadarPriMultiplier;
8271 cds_cfg->reorder_offload =
8272 hdd_ctx->config->reorderOffloadSupport;
8273
8274 /* IPA micro controller data path offload resource config item */
8275 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008276 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8277 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008278 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008279 hdd_ctx->config->IpaUcTxBufCount);
8280 hdd_ctx->config->IpaUcTxBufCount =
8281 rounddown_pow_of_two(
8282 hdd_ctx->config->IpaUcTxBufCount);
8283 if (!hdd_ctx->config->IpaUcTxBufCount) {
8284 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308285 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008286 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008287 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008288 hdd_ctx->config->IpaUcTxBufCount);
8289 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308290 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8291 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008292 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8293 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008294 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008295 hdd_ctx->config->IpaUcRxIndRingCount);
8296 hdd_ctx->config->IpaUcRxIndRingCount =
8297 rounddown_pow_of_two(
8298 hdd_ctx->config->IpaUcRxIndRingCount);
8299 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8300 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308301 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008302 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008303 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008304 hdd_ctx->config->IpaUcRxIndRingCount);
8305 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308306 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008307 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308308 cds_cfg->uc_tx_partition_base =
8309 hdd_ctx->config->IpaUcTxPartitionBase;
8310 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8311
8312 cds_cfg->ip_tcp_udp_checksum_offload =
8313 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308314 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308315 cds_cfg->ce_classify_enabled =
8316 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008317 cds_cfg->bpf_packet_filter_enable =
8318 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308319 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8320 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8321 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008322 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008323 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008324 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008325 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308326 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8327 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308328 cds_cfg->auto_power_save_fail_mode =
8329 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308330
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308331 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008332 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308333
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308334 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8335 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8336 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008337 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308338 cds_init_ini_config(cds_cfg);
8339 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308340
8341exit:
8342 qdf_mem_free(cds_cfg);
8343 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308344}
8345
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008346/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008347 * hdd_update_user_config() - API to update user configuration
8348 * parameters to obj mgr which are used by multiple components
8349 * @hdd_ctx: HDD Context
8350 *
8351 * Return: 0 for Success, errno on failure
8352 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008353static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008354{
8355 struct wlan_objmgr_psoc_user_config *user_config;
8356
8357 user_config = qdf_mem_malloc(sizeof(*user_config));
8358 if (user_config == NULL) {
8359 hdd_alert("Failed to alloc memory for user_config!");
8360 return -ENOMEM;
8361 }
8362
8363 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8364 user_config->dual_mac_feature_disable =
8365 hdd_ctx->config->dual_mac_feature_disable;
8366 user_config->indoor_channel_support =
8367 hdd_ctx->config->indoor_channel_support;
8368 user_config->is_11d_support_enabled =
8369 hdd_ctx->config->Is11dSupportEnabled;
8370 user_config->is_11h_support_enabled =
8371 hdd_ctx->config->Is11hSupportEnabled;
8372 user_config->optimize_chan_avoid_event =
8373 hdd_ctx->config->goptimize_chan_avoid_event;
8374 user_config->skip_dfs_chnl_in_p2p_search =
8375 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008376 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008377 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8378
8379 qdf_mem_free(user_config);
8380 return 0;
8381}
8382
8383/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008384 * hdd_init_thermal_info - Initialize thermal level
8385 * @hdd_ctx: HDD context
8386 *
8387 * Initialize thermal level at SME layer and set the thermal level callback
8388 * which would be called when a configured thermal threshold is hit.
8389 *
8390 * Return: 0 on success and errno on failure
8391 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008392static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008393{
8394 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308395 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008396
8397 thermal_param.smeThermalMgmtEnabled =
8398 hdd_ctx->config->thermalMitigationEnable;
8399 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8400
Poddar, Siddarth83905022016-04-16 17:56:08 -07008401 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8402 hdd_ctx->config->throttle_dutycycle_level0;
8403 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8404 hdd_ctx->config->throttle_dutycycle_level1;
8405 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8406 hdd_ctx->config->throttle_dutycycle_level2;
8407 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8408 hdd_ctx->config->throttle_dutycycle_level3;
8409
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008410 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8411 hdd_ctx->config->thermalTempMinLevel0;
8412 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8413 hdd_ctx->config->thermalTempMaxLevel0;
8414 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8415 hdd_ctx->config->thermalTempMinLevel1;
8416 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8417 hdd_ctx->config->thermalTempMaxLevel1;
8418 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8419 hdd_ctx->config->thermalTempMinLevel2;
8420 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8421 hdd_ctx->config->thermalTempMaxLevel2;
8422 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8423 hdd_ctx->config->thermalTempMinLevel3;
8424 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8425 hdd_ctx->config->thermalTempMaxLevel3;
8426
8427 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8428
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308429 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308430 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008431
8432 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8433 hdd_set_thermal_level_cb);
8434
8435 return 0;
8436
8437}
8438
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008439#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8440/**
8441 * hdd_hold_rtnl_lock - Hold RTNL lock
8442 *
8443 * Hold RTNL lock
8444 *
8445 * Return: True if held and false otherwise
8446 */
8447static inline bool hdd_hold_rtnl_lock(void)
8448{
8449 rtnl_lock();
8450 return true;
8451}
8452
8453/**
8454 * hdd_release_rtnl_lock - Release RTNL lock
8455 *
8456 * Release RTNL lock
8457 *
8458 * Return: None
8459 */
8460static inline void hdd_release_rtnl_lock(void)
8461{
8462 rtnl_unlock();
8463}
8464#else
8465static inline bool hdd_hold_rtnl_lock(void) { return false; }
8466static inline void hdd_release_rtnl_lock(void) { }
8467#endif
8468
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008469#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008470
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308471/* MAX iwpriv command support */
8472#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308473#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308474#define MAX_PKTLOG_SIZE 16
8475
8476/**
8477 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8478 * @hdd_ctx: hdd context
8479 * @set_value2: pktlog buffer size value
8480 *
8481 *
8482 * Return: 0 for success or error.
8483 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008484static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308485{
8486 struct sir_wifi_start_log start_log = { 0 };
8487 QDF_STATUS status;
8488
8489 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8490 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8491 start_log.ini_triggered = cds_is_packet_log_enabled();
8492 start_log.user_triggered = 1;
8493 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308494 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308495
8496 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8497 if (!QDF_IS_STATUS_SUCCESS(status)) {
8498 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8499 EXIT();
8500 return -EINVAL;
8501 }
8502
8503 return 0;
8504}
8505
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008506/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308507 * hdd_pktlog_clear_buff() - clear pktlog buffer
8508 * @hdd_ctx: hdd context
8509 *
8510 * Return: 0 for success or error.
8511 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008512static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308513{
8514 struct sir_wifi_start_log start_log;
8515 QDF_STATUS status;
8516
8517 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8518 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8519 start_log.ini_triggered = cds_is_packet_log_enabled();
8520 start_log.user_triggered = 1;
8521 start_log.size = 0;
8522 start_log.is_pktlog_buff_clear = true;
8523
8524 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8525 if (!QDF_IS_STATUS_SUCCESS(status)) {
8526 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8527 EXIT();
8528 return -EINVAL;
8529 }
8530
8531 return 0;
8532}
8533
8534
8535/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008536 * hdd_process_pktlog_command() - process pktlog command
8537 * @hdd_ctx: hdd context
8538 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308539 * @set_value2: pktlog buffer size value
8540 *
8541 * This function process pktlog command.
8542 * set_value2 only matters when set_value is 3 (set buff size)
8543 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008544 *
8545 * Return: 0 for success or error.
8546 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008547int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308548 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008549{
8550 int ret;
8551 bool enable;
8552 uint8_t user_triggered = 0;
8553
8554 ret = wlan_hdd_validate_context(hdd_ctx);
8555 if (0 != ret)
8556 return ret;
8557
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008558 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008559
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308560 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008561 hdd_err("invalid pktlog value %d", set_value);
8562 return -EINVAL;
8563 }
8564
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308565 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8566 if (set_value2 <= 0) {
8567 hdd_err("invalid pktlog size %d", set_value2);
8568 return -EINVAL;
8569 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8570 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8571 return -EINVAL;
8572 }
8573 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308574 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8575 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308576 }
8577
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008578 /*
8579 * set_value = 0 then disable packetlog
8580 * set_value = 1 enable packetlog forcefully
8581 * set_vlaue = 2 then disable packetlog if disabled through ini or
8582 * enable packetlog with AUTO type.
8583 */
8584 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8585 true : false;
8586
8587 if (1 == set_value) {
8588 enable = true;
8589 user_triggered = 1;
8590 }
8591
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308592 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008593}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008594/**
8595 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8596 * @hdd_ctx: HDD context
8597 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308598 * @user_triggered: triggered through iwpriv
8599 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008600 *
8601 * Return: 0 on success; error number otherwise
8602 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008603int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308604 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008605{
8606 struct sir_wifi_start_log start_log;
8607 QDF_STATUS status;
8608
8609 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8610 start_log.verbose_level =
8611 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008612 start_log.ini_triggered = cds_is_packet_log_enabled();
8613 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308614 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308615 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308616 /*
8617 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8618 * commands. Host uses this flag to decide whether to send pktlog
8619 * disable command to fw without sending pktlog enable command
8620 * previously. For eg, If vendor sends pktlog disable command without
8621 * sending pktlog enable command, then host discards the packet
8622 * but for iwpriv command, host will send it to fw.
8623 */
8624 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008625 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8626 if (!QDF_IS_STATUS_SUCCESS(status)) {
8627 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8628 EXIT();
8629 return -EINVAL;
8630 }
8631
8632 return 0;
8633}
8634#endif /* REMOVE_PKT_LOG */
8635
Komal Seelam92fff912016-03-24 11:51:41 +05308636/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008637 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8638 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308639 * @dev: Device Pointer
8640 * @num: Number of Valid Mac address
8641 *
8642 * Return: Pointer to MAC address buffer
8643 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008644static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8645 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308646{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008647 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308648}
Komal Seelam92fff912016-03-24 11:51:41 +05308649
8650/**
8651 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8652 * @hdd_ctx: HDD Context
8653 * @num: Number of random mac addresses needed
8654 *
8655 * Generate random addresses using bit manipulation on the base mac address
8656 *
8657 * Return: None
8658 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008659void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308660{
8661 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8662 uint32_t iter;
8663 struct hdd_config *ini = hdd_ctx->config;
8664 uint8_t *buf = NULL;
8665 uint8_t macaddr_b3, tmp_br3;
8666 uint8_t *src = ini->intfMacAddr[0].bytes;
8667
8668 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8669 buf = ini->intfMacAddr[iter].bytes;
8670 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8671 macaddr_b3 = buf[3];
8672 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8673 INTF_MACADDR_MASK;
8674 macaddr_b3 += tmp_br3;
8675 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8676 buf[0] |= 0x02;
8677 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008678 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308679 }
8680}
8681
8682/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008683 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308684 * @hdd_ctx: HDD Context
8685 *
8686 * API to get mac addresses from platform driver and update the driver
8687 * structures and configure FW with the base mac address.
8688 * Return: int
8689 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008690static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308691{
8692 uint32_t no_of_mac_addr, iter;
8693 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8694 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8695 uint8_t *addr, *buf;
8696 struct device *dev = hdd_ctx->parent_dev;
8697 struct hdd_config *ini = hdd_ctx->config;
8698 tSirMacAddr mac_addr;
8699 QDF_STATUS status;
8700
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008701 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308702
8703 if (no_of_mac_addr == 0 || !addr) {
8704 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8705 return -EINVAL;
8706 }
8707
8708 if (no_of_mac_addr > max_mac_addr)
8709 no_of_mac_addr = max_mac_addr;
8710
8711 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8712
8713 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8714 buf = ini->intfMacAddr[iter].bytes;
8715 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008716 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308717 }
8718
8719 status = sme_set_custom_mac_addr(mac_addr);
8720
8721 if (!QDF_IS_STATUS_SUCCESS(status))
8722 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008723
Komal Seelam92fff912016-03-24 11:51:41 +05308724 if (no_of_mac_addr < max_mac_addr)
8725 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8726 no_of_mac_addr);
8727 return 0;
8728}
8729
8730/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008731 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8732 * @hdd_ctx: HDD Context
8733 *
8734 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8735 * will generate its own MAC and update it to FW.
8736 *
8737 * Return: 0 for success
8738 * Non-zero error code for failure
8739 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008740static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008741{
8742 tSirMacAddr customMacAddr;
8743 QDF_STATUS status;
8744
8745 qdf_mem_copy(&customMacAddr,
8746 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8747 sizeof(tSirMacAddr));
8748 status = sme_set_custom_mac_addr(customMacAddr);
8749 if (!QDF_IS_STATUS_SUCCESS(status))
8750 return -EAGAIN;
8751 return 0;
8752}
8753
8754/**
Komal Seelam92fff912016-03-24 11:51:41 +05308755 * hdd_initialize_mac_address() - API to get wlan mac addresses
8756 * @hdd_ctx: HDD Context
8757 *
8758 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8759 * is provisioned with mac addresses, driver uses it, else it will use
8760 * wlan_mac.bin to update HW MAC addresses.
8761 *
8762 * Return: None
8763 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008764static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308765{
8766 QDF_STATUS status;
8767 int ret;
8768
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008769 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308770 if (ret == 0)
8771 return;
8772
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008773 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8774 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308775
8776 status = hdd_update_mac_config(hdd_ctx);
8777
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008778 if (QDF_IS_STATUS_SUCCESS(status))
8779 return;
8780
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008781 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8782 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008783
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008784 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008785 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008786 if (ret != 0) {
8787 hdd_err("MAC address out-of-sync, ret:%d", ret);
8788 QDF_ASSERT(ret);
8789 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008790 }
Komal Seelam92fff912016-03-24 11:51:41 +05308791}
8792
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008793static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008794{
8795 int vdev_id = 0;
8796 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8797 int value = hdd_ctx->config->smart_chainmask_enabled;
8798 int vpdev = PDEV_CMD;
8799 int ret;
8800
Naveen Rawat247a8682017-06-05 15:00:31 -07008801 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008802 if (ret)
8803 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8804
8805 return ret;
8806}
8807
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008808static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008809{
8810 int vdev_id = 0;
8811 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8812 int value = hdd_ctx->config->alternative_chainmask_enabled;
8813 int vpdev = PDEV_CMD;
8814 int ret;
8815
Naveen Rawat247a8682017-06-05 15:00:31 -07008816 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008817 if (ret)
8818 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8819 ret);
8820
8821 return ret;
8822}
8823
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008824static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008825{
8826 int vdev_id = 0;
8827 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8828 int value = hdd_ctx->config->ani_enabled;
8829 int vpdev = PDEV_CMD;
8830 int ret;
8831
Naveen Rawat247a8682017-06-05 15:00:31 -07008832 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008833 if (ret)
8834 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8835
8836 return ret;
8837}
8838
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008839/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008840 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8841 * @hdd_ctx: HDD context
8842 *
8843 * Pre configurations to be done at lower layer before calling cds enable.
8844 *
8845 * Return: 0 on success and errno on failure.
8846 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008847static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008848{
8849 int ret;
8850 QDF_STATUS status;
8851 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008852 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008853
Leo Changfdb45c32016-10-28 11:09:23 -07008854 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008855 /*
8856 * Set 802.11p config
8857 * TODO-OCB: This has been temporarily added here to ensure this
8858 * parameter is set in CSR when we init the channel list. This should
8859 * be removed once the 5.9 GHz channels are added to the regulatory
8860 * domain.
8861 */
8862 hdd_set_dot11p_config(hdd_ctx);
8863
8864 /*
8865 * Note that the cds_pre_enable() sequence triggers the cfg download.
8866 * The cfg download must occur before we update the SME config
8867 * since the SME config operation must access the cfg database
8868 */
8869 status = hdd_set_sme_config(hdd_ctx);
8870
8871 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008872 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008873 ret = qdf_status_to_os_return(status);
8874 goto out;
8875 }
8876
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008877 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8878 if (QDF_STATUS_SUCCESS != status) {
8879 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8880 ret = qdf_status_to_os_return(status);
8881 goto out;
8882 }
8883
Naveen Rawat247a8682017-06-05 15:00:31 -07008884 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008885 hdd_ctx->config->tx_chain_mask_1ss,
8886 PDEV_CMD);
8887 if (0 != ret) {
8888 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8889 goto out;
8890 }
8891
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008892 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8893 if (ret)
8894 goto out;
8895
8896 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8897 if (ret)
8898 goto out;
8899
Jeff Johnson12a744b2017-04-04 08:19:37 -07008900 ret = hdd_set_ani_enabled(hdd_ctx);
8901 if (ret)
8902 goto out;
8903
Naveen Rawat247a8682017-06-05 15:00:31 -07008904 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008905 hdd_ctx->config->arp_ac_category,
8906 PDEV_CMD);
8907 if (0 != ret) {
8908 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8909 hdd_ctx->config->arp_ac_category, ret);
8910 goto out;
8911 }
8912
8913
Prashanth Bhatta07998752016-04-28 12:35:33 -07008914 status = hdd_set_sme_chan_list(hdd_ctx);
8915 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008916 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008917 ret = qdf_status_to_os_return(status);
8918 goto out;
8919 }
8920
8921 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008922 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008923 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008924 ret = -EINVAL;
8925 goto out;
8926 }
8927
Prashanth Bhatta07998752016-04-28 12:35:33 -07008928 /*
8929 * Set the MAC Address Currently this is used by HAL to add self sta.
8930 * Remove this once self sta is added as part of session open.
8931 */
8932 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8933 hdd_ctx->config->intfMacAddr[0].bytes,
8934 sizeof(hdd_ctx->config->intfMacAddr[0]));
8935
8936 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8937 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8938 hal_status, hal_status);
8939 ret = -EINVAL;
8940 goto out;
8941 }
8942
8943 hdd_init_channel_avoidance(hdd_ctx);
8944
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308945 /* update enable sap mandatory chan list */
8946 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8947 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008948out:
8949 return ret;
8950}
8951
8952/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008953 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8954 * @context_ptr - hdd context pointer
8955 * @event_ptr - event structure pointer
8956 *
8957 * This is the p2p listen offload stop event handler, it sends vendor
8958 * event back to supplicant to notify the stop reason.
8959 *
8960 * Return: None
8961 */
8962static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8963 void *event_ptr)
8964{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008965 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008966 struct sir_p2p_lo_event *evt = event_ptr;
8967 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008968 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008969
8970 ENTER();
8971
8972 if (hdd_ctx == NULL) {
8973 hdd_err("Invalid HDD context pointer");
8974 return;
8975 }
8976
Peng Xu5c682812017-08-06 07:39:13 -07008977 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8978 if (!adapter) {
8979 hdd_err("Cannot find adapter by vdev_id = %d",
8980 evt->vdev_id);
8981 return;
8982 }
8983
Peng Xu8fdaa492016-06-22 10:20:47 -07008984 vendor_event =
8985 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008986 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008987 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8988 GFP_KERNEL);
8989
8990 if (!vendor_event) {
8991 hdd_err("cfg80211_vendor_event_alloc failed");
8992 return;
8993 }
8994
8995 if (nla_put_u32(vendor_event,
8996 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8997 evt->reason_code)) {
8998 hdd_err("nla put failed");
8999 kfree_skb(vendor_event);
9000 return;
9001 }
9002
9003 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009004 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9005 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009006}
9007
9008/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309009 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9010 * @hdd_ctx: HDD context
9011 *
9012 * This function sends the adaptive dwell time config configuration to the
9013 * firmware via WMA
9014 *
9015 * Return: 0 - success, < 0 - failure
9016 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009017static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309018{
9019 QDF_STATUS status;
9020 struct adaptive_dwelltime_params dwelltime_params;
9021
9022 dwelltime_params.is_enabled =
9023 hdd_ctx->config->adaptive_dwell_mode_enabled;
9024 dwelltime_params.dwelltime_mode =
9025 hdd_ctx->config->global_adapt_dwelltime_mode;
9026 dwelltime_params.lpf_weight =
9027 hdd_ctx->config->adapt_dwell_lpf_weight;
9028 dwelltime_params.passive_mon_intval =
9029 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9030 dwelltime_params.wifi_act_threshold =
9031 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9032
9033 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9034 &dwelltime_params);
9035
9036 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9037 if (!QDF_IS_STATUS_SUCCESS(status)) {
9038 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9039 return -EAGAIN;
9040 }
9041 return 0;
9042}
9043
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009044int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309045{
9046 QDF_STATUS status;
9047 struct wmi_dbs_scan_sel_params dbs_scan_params;
9048 uint32_t i = 0;
9049 uint8_t count = 0, numentries = 0;
9050 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9051 * CDS_DBS_SCAN_CLIENTS_MAX];
9052
9053 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009054 if (hdd_ctx->config->dual_mac_feature_disable ==
9055 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309056 return -EINVAL;
9057
9058 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9059 dbs_scan_config, &numentries,
9060 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9061 * CDS_DBS_SCAN_CLIENTS_MAX));
9062
9063 hdd_info("numentries %hu", numentries);
9064 if (!numentries) {
9065 hdd_info("Donot send scan_selection_config");
9066 return 0;
9067 }
9068
9069 /* hdd_set_fw_log_params */
9070 dbs_scan_params.num_clients = 0;
9071 while (count < (numentries - 2)) {
9072 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9073 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9074 dbs_scan_params.num_non_dbs_scans[i] =
9075 dbs_scan_config[count + 2];
9076 dbs_scan_params.num_clients++;
9077 hdd_debug("module:%d NDS:%d NNDS:%d",
9078 dbs_scan_params.module_id[i],
9079 dbs_scan_params.num_dbs_scans[i],
9080 dbs_scan_params.num_non_dbs_scans[i]);
9081 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9082 i++;
9083 }
9084
9085 dbs_scan_params.pdev_id = 0;
9086
9087 hdd_debug("clients:%d pdev:%d",
9088 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9089
9090 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9091 &dbs_scan_params);
9092 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9093 if (!QDF_IS_STATUS_SUCCESS(status)) {
9094 hdd_err("Failed to send DBS Scan selection configuration!");
9095 return -EAGAIN;
9096 }
9097 return 0;
9098}
9099
Arun Khandavallid4349a92016-07-25 11:10:43 +05309100#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9101/**
9102 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9103 * @hdd_ctx: HDD context
9104 *
9105 * Set auto shutdown callback to get indications from firmware to indicate
9106 * userspace to shutdown WLAN after a configured amount of inactivity.
9107 *
9108 * Return: 0 on success and errno on failure.
9109 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009110static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309111{
9112 QDF_STATUS status;
9113
9114 if (!hdd_ctx->config->WlanAutoShutdown)
9115 return 0;
9116
9117 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9118 wlan_hdd_auto_shutdown_cb);
9119 if (status != QDF_STATUS_SUCCESS)
9120 hdd_err("Auto shutdown feature could not be enabled: %d",
9121 status);
9122
9123 return qdf_status_to_os_return(status);
9124}
9125#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009126static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309127{
9128 return 0;
9129}
9130#endif
9131
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009132static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009133{
9134 QDF_STATUS status = QDF_STATUS_SUCCESS;
9135
9136 switch (hdd_ctx->config->dual_mac_feature_disable) {
9137 case DISABLE_DBS_CXN_AND_SCAN:
9138 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9139 if (status != QDF_STATUS_SUCCESS)
9140 hdd_err("Failed to disable dual mac features");
9141 break;
9142 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9143 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9144 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9145 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9146 if (status != QDF_STATUS_SUCCESS)
9147 hdd_err("Failed to set dbs scan and fw mode config");
9148 break;
9149 default:
9150 break;
9151 }
9152
9153 return status;
9154}
9155
Arun Khandavallid4349a92016-07-25 11:10:43 +05309156/**
9157 * hdd_features_init() - Init features
9158 * @hdd_ctx: HDD context
9159 * @adapter: Primary adapter context
9160 *
9161 * Initialize features and their feature context after WLAN firmware is up.
9162 *
9163 * Return: 0 on success and errno on failure.
9164 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009165static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309166{
9167 tSirTxPowerLimit hddtxlimit;
9168 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309169 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309170 int ret;
9171
9172 ENTER();
9173
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009174 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309175 if (ret) {
9176 hdd_err("Failed to update country code: %d", ret);
9177 goto out;
9178 }
9179
9180 /* FW capabilities received, Set the Dot11 mode */
9181 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009182 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9183 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309184
Arun Khandavallid4349a92016-07-25 11:10:43 +05309185
9186 if (hdd_ctx->config->fIsImpsEnabled)
9187 hdd_set_idle_ps_config(hdd_ctx, true);
9188 else
9189 hdd_set_idle_ps_config(hdd_ctx, false);
9190
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309191 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009192 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309193
Arun Khandavallid4349a92016-07-25 11:10:43 +05309194 if (hdd_lro_init(hdd_ctx))
9195 hdd_err("Unable to initialize LRO in fw");
9196
9197 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9198 hdd_err("Unable to send adaptive dwelltime setting to FW");
9199
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309200 if (hdd_dbs_scan_selection_init(hdd_ctx))
9201 hdd_err("Unable to send DBS scan selection setting to FW");
9202
Arun Khandavallid4349a92016-07-25 11:10:43 +05309203 ret = hdd_init_thermal_info(hdd_ctx);
9204 if (ret) {
9205 hdd_err("Error while initializing thermal information");
9206 goto deregister_frames;
9207 }
9208
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309209 if (cds_is_packet_log_enabled())
9210 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9211
Arun Khandavallid4349a92016-07-25 11:10:43 +05309212 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9213 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9214 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9215 if (!QDF_IS_STATUS_SUCCESS(status))
9216 hdd_err("Error setting txlimit in sme: %d", status);
9217
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009218 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309219
Arun Khandavallid4349a92016-07-25 11:10:43 +05309220 ret = hdd_register_cb(hdd_ctx);
9221 if (ret) {
9222 hdd_err("Failed to register HDD callbacks!");
9223 goto deregister_frames;
9224 }
9225
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009226 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9227 if (!QDF_IS_STATUS_SUCCESS(status)) {
9228 hdd_err("Failed to set dbs scan and fw mode cfg");
9229 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309230 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009231
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309232 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9233 status = sme_enable_disable_chanavoidind_event(
9234 hdd_ctx->hHal, 0);
9235 if (!QDF_IS_STATUS_SUCCESS(status)) {
9236 hdd_err("Failed to disable Chan Avoidance Indication");
9237 goto deregister_cb;
9238 }
9239 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309240
Manjeet Singha9cae432017-02-28 11:58:22 +05309241 if (hdd_ctx->config->enable_5g_band_pref) {
9242 band_pref_params.rssi_boost_threshold_5g =
9243 hdd_ctx->config->rssi_boost_threshold_5g;
9244 band_pref_params.rssi_boost_factor_5g =
9245 hdd_ctx->config->rssi_boost_factor_5g;
9246 band_pref_params.max_rssi_boost_5g =
9247 hdd_ctx->config->max_rssi_boost_5g;
9248 band_pref_params.rssi_penalize_threshold_5g =
9249 hdd_ctx->config->rssi_penalize_threshold_5g;
9250 band_pref_params.rssi_penalize_factor_5g =
9251 hdd_ctx->config->rssi_penalize_factor_5g;
9252 band_pref_params.max_rssi_penalize_5g =
9253 hdd_ctx->config->max_rssi_penalize_5g;
9254 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9255 }
9256
Arun Khandavallid4349a92016-07-25 11:10:43 +05309257 /* register P2P Listen Offload event callback */
9258 if (wma_is_p2p_lo_capable())
9259 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9260 wlan_hdd_p2p_lo_event_callback);
9261
9262 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9263
9264 if (ret)
9265 goto deregister_cb;
9266
9267 EXIT();
9268 return 0;
9269
9270deregister_cb:
9271 hdd_deregister_cb(hdd_ctx);
9272deregister_frames:
9273 wlan_hdd_cfg80211_deregister_frames(adapter);
9274out:
9275 return -EINVAL;
9276
9277}
9278
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009279/**
9280 * hdd_features_deinit() - Deinit features
9281 * @hdd_ctx: HDD context
9282 *
9283 * De-Initialize features and their feature context.
9284 *
9285 * Return: none.
9286 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009287static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009288{
9289 wlan_hdd_tsf_deinit(hdd_ctx);
9290}
9291
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309292/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009293 * hdd_register_bcn_cb() - register scan beacon callback
9294 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309295 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009296 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309297 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009298static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309299{
9300 QDF_STATUS status;
9301
9302 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9303 wlan_cfg80211_inform_bss_frame,
9304 SCAN_CB_TYPE_INFORM_BCN);
9305 if (!QDF_IS_STATUS_SUCCESS(status)) {
9306 hdd_err("failed with status code %08d [x%08x]",
9307 status, status);
9308 return status;
9309 }
9310
9311 return QDF_STATUS_SUCCESS;
9312}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309313
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309314/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309315 * hdd_configure_cds() - Configure cds modules
9316 * @hdd_ctx: HDD context
9317 * @adapter: Primary adapter context
9318 *
9319 * Enable Cds modules after WLAN firmware is up.
9320 *
9321 * Return: 0 on success and errno on failure.
9322 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009323int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309324{
9325 int ret;
9326 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309327 int set_value;
9328 uint32_t num_abg_tx_chains = 0;
9329 uint32_t num_11b_tx_chains = 0;
9330 uint32_t num_11ag_tx_chains = 0;
9331
9332 if (hdd_ctx->config->sifs_burst_duration) {
9333 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9334 hdd_ctx->config->sifs_burst_duration;
9335
9336 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9337 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9338 set_value, PDEV_CMD);
9339 }
9340
9341 if (hdd_ctx->config->is_force_1x1)
9342 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9343 1, PDEV_CMD);
9344 /* set chip power save failure detected callback */
9345 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9346 hdd_chip_pwr_save_fail_detected_cb);
9347
9348 if (hdd_ctx->config->max_mpdus_inampdu) {
9349 set_value = hdd_ctx->config->max_mpdus_inampdu;
9350 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9351 set_value, PDEV_CMD);
9352 }
9353
9354 if (hdd_ctx->config->enable_rts_sifsbursting) {
9355 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9356 sme_cli_set_command(0,
9357 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9358 set_value, PDEV_CMD);
9359 }
9360
9361 if (hdd_ctx->config->sap_get_peer_info) {
9362 set_value = hdd_ctx->config->sap_get_peer_info;
9363 sme_cli_set_command(0,
9364 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9365 set_value, PDEV_CMD);
9366 }
9367
9368 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9369 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9370 if (!hdd_ctx->config->enable2x2) {
9371 if (num_11b_tx_chains > 1)
9372 num_11b_tx_chains = 1;
9373 if (num_11ag_tx_chains > 1)
9374 num_11ag_tx_chains = 1;
9375 }
9376 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9377 num_11b_tx_chains);
9378 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9379 num_11ag_tx_chains);
9380 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9381 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309382
9383 ret = hdd_pre_enable_configure(hdd_ctx);
9384 if (ret) {
9385 hdd_err("Failed to pre-configure cds");
9386 goto out;
9387 }
9388
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009389 /* Always get latest IPA resources allocated from cds_open and configure
9390 * IPA module before configuring them to FW. Sequence required as crash
9391 * observed otherwise.
9392 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009393 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9394 hdd_err("Failed to setup pipes");
9395 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009396 }
9397
Arun Khandavallifae92942016-08-01 13:31:08 +05309398 /*
9399 * Start CDS which starts up the SME/MAC/HAL modules and everything
9400 * else
9401 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009402 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309403
9404 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009405 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309406 goto out;
9407 }
9408
9409 status = hdd_post_cds_enable_config(hdd_ctx);
9410 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009411 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009412 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309413 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309414 status = hdd_register_bcn_cb(hdd_ctx);
9415 if (!QDF_IS_STATUS_SUCCESS(status)) {
9416 hdd_alert("hdd_post_cds_enable_config failed");
9417 goto cds_disable;
9418 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309419
9420 ret = hdd_features_init(hdd_ctx, adapter);
9421 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009422 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309423
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309424 if (hdd_enable_egap(hdd_ctx))
9425 hdd_debug("enhance green ap is not enabled");
9426
Nachiket Kukadedd302662017-07-13 17:31:44 +05309427 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9428 hdd_debug("Failed to set wow pulse");
9429
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309430 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9431 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9432
Arun Khandavallifae92942016-08-01 13:31:08 +05309433 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009434
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009435cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009436 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009437
Arun Khandavallifae92942016-08-01 13:31:08 +05309438out:
9439 return -EINVAL;
9440}
9441
9442/**
9443 * hdd_deconfigure_cds() -De-Configure cds
9444 * @hdd_ctx: HDD context
9445 *
9446 * Deconfigure Cds modules before WLAN firmware is down.
9447 *
9448 * Return: 0 on success and errno on failure.
9449 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009450static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309451{
9452 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009453 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309454
9455 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009456
9457 /* De-init features */
9458 hdd_features_deinit(hdd_ctx);
9459
Arun Khandavallifae92942016-08-01 13:31:08 +05309460 /* De-register the SME callbacks */
9461 hdd_deregister_cb(hdd_ctx);
9462
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009463 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309464 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9465 hdd_err("Failed to Disable the CDS Modules! :%d",
9466 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009467 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309468 }
9469
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309470 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9471 hdd_err("Failed to disconnect pipes");
9472 ret = -EINVAL;
9473 }
9474
Arun Khandavallifae92942016-08-01 13:31:08 +05309475 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009476 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309477}
9478
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009479#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9480static void hdd_deregister_policy_manager_callback(
9481 struct wlan_objmgr_psoc *psoc)
9482{
9483 if (QDF_STATUS_SUCCESS !=
9484 policy_mgr_deregister_hdd_cb(psoc)) {
9485 hdd_err("HDD callback deregister with policy manager failed");
9486 }
9487}
9488#else
9489static void hdd_deregister_policy_manager_callback(
9490 struct wlan_objmgr_psoc *psoc)
9491{
9492}
9493#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309494
9495/**
9496 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9497 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009498 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309499 *
9500 * This function maintains the driver state machine it will be invoked from
9501 * exit, shutdown and con_mode change handler. Depending on the driver state
9502 * shall perform the stopping/closing of the modules.
9503 *
9504 * Return: 0 for success; non-zero for failure
9505 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009506int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309507{
9508 void *hif_ctx;
9509 qdf_device_t qdf_ctx;
9510 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309511 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009512 bool is_idle_stop = !cds_is_driver_unloading() &&
9513 !cds_is_driver_recovering();
9514 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309515
9516 ENTER();
9517
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009518 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9519
Arun Khandavallifae92942016-08-01 13:31:08 +05309520 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9521 if (!qdf_ctx) {
9522 hdd_err("QDF device context NULL");
9523 return -EINVAL;
9524 }
9525
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309526 mutex_lock(&hdd_ctx->iface_change_lock);
9527 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309528
Dustin Brown70111822017-03-30 15:31:40 -07009529 active_threads = cds_return_external_threads_count();
9530 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009531 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009532 active_threads, hdd_ctx->isWiphySuspended);
9533
9534 cds_print_external_threads();
9535
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009536 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009537 mutex_unlock(&hdd_ctx->iface_change_lock);
9538 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009539 hdd_ctx->config->iface_change_wait_time);
9540 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009541 return 0;
9542 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009543 }
9544
Arun Khandavallifae92942016-08-01 13:31:08 +05309545 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9546
9547 switch (hdd_ctx->driver_status) {
9548 case DRIVER_MODULES_UNINITIALIZED:
9549 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309550 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309551 case DRIVER_MODULES_CLOSED:
9552 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309553 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309554 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309555 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309556 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009557 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309558 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309559 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309560 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009561 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309562 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9563 break;
9564 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009565 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309566 break;
9567 default:
9568 hdd_err("Trying to stop wlan in a wrong state: %d",
9569 hdd_ctx->driver_status);
9570 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309571 ret = -EINVAL;
9572 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309573 }
9574
Rajeev Kumarbe021242017-02-16 16:12:23 -08009575 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309576 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9577 hdd_err("Failed to process post CDS disable Modules! :%d",
9578 qdf_status);
9579 ret = -EINVAL;
9580 QDF_ASSERT(0);
9581 }
Jeff Johnsone4b14592017-09-13 14:23:33 -07009582 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309583 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009584 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309585 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309586 QDF_ASSERT(0);
9587 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009588
Arun Khandavallifae92942016-08-01 13:31:08 +05309589 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9590 if (!hif_ctx) {
9591 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309592 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309593 }
9594
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309595 hdd_runtime_suspend_context_deinit(hdd_ctx);
9596
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309597 if (hdd_ctx->target_hw_name) {
9598 qdf_mem_free(hdd_ctx->target_hw_name);
9599 hdd_ctx->target_hw_name = NULL;
9600 }
9601
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309602 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309603
9604 ol_cds_free();
9605
Dustin Brown70111822017-03-30 15:31:40 -07009606 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309607 ret = pld_power_off(qdf_ctx->dev);
9608 if (ret)
9609 hdd_err("CNSS power down failed put device into Low power mode:%d",
9610 ret);
9611 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309612
9613 /* Once the firmware sequence is completed reset this flag */
9614 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309615 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009616 /*
9617 * Reset total mac phy during module stop such that during
9618 * next module start same psoc is used to populate new service
9619 * ready data
9620 */
9621 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309622
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309623done:
9624 hdd_ctx->stop_modules_in_progress = false;
9625 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309626 EXIT();
9627
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309628 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309629
9630}
9631
9632/**
9633 * hdd_iface_change_callback() - Function invoked when stop modules expires
9634 * @priv: pointer to hdd context
9635 *
9636 * This function is invoked when the timer waiting for the interface change
9637 * expires, it shall cut-down the power to wlan and stop all the modules.
9638 *
9639 * Return: void
9640 */
9641static void hdd_iface_change_callback(void *priv)
9642{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009643 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309644 int ret;
9645 int status = wlan_hdd_validate_context(hdd_ctx);
9646
9647 if (status)
9648 return;
9649
9650 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009651 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009652 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309653 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009654 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309655 EXIT();
9656}
9657
9658/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309659 * hdd_state_info_dump() - prints state information of hdd layer
9660 * @buf: buffer pointer
9661 * @size: size of buffer to be filled
9662 *
9663 * This function is used to dump state information of hdd layer
9664 *
9665 * Return: None
9666 */
9667static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9668{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009669 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309670 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9671 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009672 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009673 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309674 uint16_t len = 0;
9675 char *buf = *buf_ptr;
9676
9677 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9678 if (!hdd_ctx) {
9679 hdd_err("Failed to get hdd context ");
9680 return;
9681 }
9682
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009683 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309684
9685 len += scnprintf(buf + len, *size - len,
9686 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9687 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009688 "\n is_scheduler_suspended %d",
9689 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309690
9691 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9692
9693 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009694 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309695 if (adapter->dev)
9696 len += scnprintf(buf + len, *size - len,
9697 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009698 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309699 "\n device_mode: %d", adapter->device_mode);
9700 switch (adapter->device_mode) {
9701 case QDF_STA_MODE:
9702 case QDF_P2P_CLIENT_MODE:
9703 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9704 len += scnprintf(buf + len, *size - len,
9705 "\n connState: %d",
9706 hdd_sta_ctx->conn_info.connState);
9707 break;
9708
9709 default:
9710 break;
9711 }
9712 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9713 adapter_node = next;
9714 }
9715
9716 *size -= len;
9717 *buf_ptr += len;
9718}
9719
9720/**
9721 * hdd_register_debug_callback() - registration function for hdd layer
9722 * to print hdd state information
9723 *
9724 * Return: None
9725 */
9726static void hdd_register_debug_callback(void)
9727{
9728 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9729}
9730
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309731/*
9732 * wlan_init_bug_report_lock() - Initialize bug report lock
9733 *
9734 * This function is used to create bug report lock
9735 *
9736 * Return: None
9737 */
9738static void wlan_init_bug_report_lock(void)
9739{
9740 p_cds_contextType p_cds_context;
9741
9742 p_cds_context = cds_get_global_context();
9743 if (!p_cds_context) {
9744 hdd_err("cds context is NULL");
9745 return;
9746 }
9747
9748 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9749}
9750
Mohit Khannaf8f96822017-05-17 17:11:59 -07009751void hdd_dp_trace_init(struct hdd_config *config)
9752{
9753
9754 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9755 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9756 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9757 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9758 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9759 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9760 uint8_t num_entries = 0;
9761
9762 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9763 &num_entries, sizeof(config_params));
9764
9765 /* calculating, num bw timer intervals in a second (1000ms) */
9766 if (config->busBandwidthComputeInterval)
9767 thresh_time_limit =
9768 (1000 / config->busBandwidthComputeInterval);
9769 else
9770 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9771
9772 switch (num_entries) {
9773 case 4:
9774 proto_bitmap = config_params[3];
9775 case 3:
9776 verbosity = config_params[2];
9777 case 2:
9778 thresh = config_params[1];
9779 case 1:
9780 live_mode = config_params[0];
9781 default:
9782 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9783 live_mode, thresh, thresh_time_limit,
9784 verbosity, proto_bitmap);
9785 };
9786
9787 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9788 verbosity, proto_bitmap);
9789
9790}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309791/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009792 * hdd_wlan_startup() - HDD init function
9793 * @dev: Pointer to the underlying device
9794 *
9795 * This is the driver startup code executed once a WLAN device has been detected
9796 *
9797 * Return: 0 for success, < 0 for failure
9798 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309799int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009800{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309801 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009802 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009803 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009804 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009805
9806 ENTER();
9807
Arun Khandavallifae92942016-08-01 13:31:08 +05309808 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009809
9810 if (IS_ERR(hdd_ctx))
9811 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009812
Abhishek Singhe9068f12017-03-31 14:14:52 +05309813 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9814 DEFAULT_PSOC_ID);
9815 if (ret) {
9816 hdd_err("Psoc creation fails!");
9817 QDF_BUG(0);
9818 goto err_hdd_free_context;
9819 }
9820
Arun Khandavallifae92942016-08-01 13:31:08 +05309821 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9822 hdd_iface_change_callback, (void *)hdd_ctx);
9823
9824 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309825#ifdef FEATURE_WLAN_CH_AVOID
9826 mutex_init(&hdd_ctx->avoid_freq_lock);
9827#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309828
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009829 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009830 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309831
Jeff Johnson957bc272017-02-02 08:54:48 -08009832 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309833 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009834 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009835 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009836 }
9837
Yingying Tang80e15f32016-09-27 18:23:01 +08009838 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009839
Anurag Chouhan6d760662016-02-20 16:05:43 +05309840 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009841
9842 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009843 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309844 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009845 }
9846
Prashanth Bhatta07998752016-04-28 12:35:33 -07009847 ret = hdd_wiphy_init(hdd_ctx);
9848 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009849 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309850 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009851 }
9852
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309853 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009854 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309855
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309856 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009857 goto err_wiphy_unregister;
9858
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309859 wlan_hdd_init_chan_info(hdd_ctx);
9860
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009861 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009862
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309863 ret = hdd_register_notifiers(hdd_ctx);
9864 if (ret)
9865 goto err_ipa_cleanup;
9866
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009867 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009868
Jeff Johnson957bc272017-02-02 08:54:48 -08009869 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9870 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009871 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009872 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009873 }
9874
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009875 hdd_release_rtnl_lock();
9876 rtnl_held = false;
9877
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009878 wlan_hdd_update_11n_mode(hdd_ctx->config);
9879
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009880#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309881 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309882 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009883 hdd_skip_acs_scan_timer_handler,
9884 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309885 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009886 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009887 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009888#endif
9889
Prashanth Bhattaab004382016-10-11 16:08:11 -07009890 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009891
Jeff Johnson9afc5012016-09-23 13:56:27 -07009892 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009893
Nirav Shahbd36b062016-07-18 11:12:59 +05309894 if (hdd_ctx->rps)
9895 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009896
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309897 status = wlansap_global_init();
9898 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009899 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009900
Komal Seelam8634b772016-09-29 12:12:24 +05309901 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009902 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309903 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009904
Arun Khandavallifae92942016-08-01 13:31:08 +05309905 if (hdd_ctx->config->fIsImpsEnabled)
9906 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309907
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309908 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9909 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309910 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309911
Sachin Ahujadddd2632017-03-07 19:07:24 +05309912 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009913 goto success;
9914
Jeff Johnson957bc272017-02-02 08:54:48 -08009915err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009916 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009917
Jeff Johnson46bde382017-02-01 15:31:16 -08009918err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309919 if (rtnl_held)
9920 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009921
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309922 unregister_netdevice_notifier(&hdd_netdev_notifier);
9923
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309924err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309925 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009926
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009927err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009928 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009929
Arun Khandavallifae92942016-08-01 13:31:08 +05309930err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009931 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309932
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009933err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309934 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009935 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309936 if (!QDF_IS_STATUS_SUCCESS(status)) {
9937 hdd_err("Failed to close CDS Scheduler");
9938 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9939 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009940 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009941
Houston Hoffman47a4a052016-11-14 23:22:44 -08009942 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009943 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009944 hdd_exit_netlink_services(hdd_ctx);
9945
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309946 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009947
Dustin Brown20912462017-06-07 13:48:25 -07009948 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9949
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009950err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309951 if (cds_is_fw_down())
9952 hdd_err("Not setting the complete event as fw is down");
9953 else
9954 hdd_start_complete(ret);
9955
Arun Khandavallifae92942016-08-01 13:31:08 +05309956 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9957 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009958 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009959 return -EIO;
9960
9961success:
9962 EXIT();
9963 return 0;
9964}
9965
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009966/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309967 * hdd_wlan_update_target_info() - update target type info
9968 * @hdd_ctx: HDD context
9969 * @context: hif context
9970 *
9971 * Update target info received from firmware in hdd context
9972 * Return:None
9973 */
9974
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009975void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309976{
9977 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9978
9979 if (!tgt_info) {
9980 hdd_err("Target info is Null");
9981 return;
9982 }
9983
9984 hdd_ctx->target_type = tgt_info->target_type;
9985}
9986
9987/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05309988 * hdd_get_nud_stats_cb() - callback api to update the stats
9989 * received from the firmware
9990 * @data: pointer to adapter.
9991 * @rsp: pointer to data received from FW.
9992 *
9993 * This is called when wlan driver received response event for
9994 * get arp stats to firmware.
9995 *
9996 * Return: None
9997 */
9998static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
9999{
10000 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10001 struct hdd_nud_stats_context *context;
10002 int status;
10003 struct hdd_adapter *adapter = NULL;
10004
10005 ENTER();
10006
10007 if (!rsp) {
10008 hdd_err("data is null");
10009 return;
10010 }
10011
10012 status = wlan_hdd_validate_context(hdd_ctx);
10013 if (0 != status)
10014 return;
10015
10016 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10017 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10018 hdd_err("Invalid adapter or adapter has invalid magic");
10019 return;
10020 }
10021
10022 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10023 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10024 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10025 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10026 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10027 rsp->out_of_order_arp_rsp_drop_cnt);
10028 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10029 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10030 hdd_notice("rsp->ba_session_establishment_status :%x",
10031 rsp->ba_session_establishment_status);
10032
10033 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10034 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10035 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10036 adapter->dad |= rsp->dad_detected;
10037 adapter->con_status = rsp->connect_status;
10038
10039 spin_lock(&hdd_context_lock);
10040 context = &hdd_ctx->nud_stats_context;
10041 complete(&context->response_event);
10042 spin_unlock(&hdd_context_lock);
10043
10044 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010045}
10046
10047/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010048 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010049 * @hdd_ctx: HDD context
10050 *
10051 * Register the HDD callbacks to CDS/SME.
10052 *
10053 * Return: 0 for success or Error code for failure
10054 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010055int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010056{
10057 QDF_STATUS status;
10058 int ret = 0;
10059
10060 ENTER();
10061
10062 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10063
10064 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10065 hdd_send_oem_data_rsp_msg);
10066
10067 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10068 wlan_hdd_cfg80211_fw_mem_dump_cb);
10069 if (!QDF_IS_STATUS_SUCCESS(status)) {
10070 hdd_err("Failed to register memdump callback");
10071 ret = -EINVAL;
10072 return ret;
10073 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010074 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10075 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010076 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10077 sme_nan_register_callback(hdd_ctx->hHal,
10078 wlan_hdd_cfg80211_nan_callback);
10079 sme_stats_ext_register_callback(hdd_ctx->hHal,
10080 wlan_hdd_cfg80211_stats_ext_callback);
10081
10082 sme_ext_scan_register_callback(hdd_ctx->hHal,
10083 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010084 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10085 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010086
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010087 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10088 hdd_rssi_threshold_breached);
10089
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010090 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10091
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010092 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10093 wlan_hdd_cfg80211_link_layer_stats_callback);
10094
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010095 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10096
Zhang Qianca38fb12016-12-23 11:10:48 +080010097 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10098 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10099
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010100 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10101 hdd_lost_link_info_cb);
10102 /* print error and not block the startup process */
10103 if (!QDF_IS_STATUS_SUCCESS(status))
10104 hdd_err("set lost link info callback failed");
10105
Poddar, Siddarth34872782017-08-10 14:08:51 +053010106 ret = hdd_register_data_stall_detect_cb();
10107 if (ret) {
10108 hdd_err("Register data stall detect detect callback failed.");
10109 return ret;
10110 }
10111
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010112 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10113
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010114 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010115 hdd_set_connection_in_progress,
10116 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010117
10118 status = sme_congestion_register_callback(hdd_ctx->hHal,
10119 hdd_update_cca_info_cb);
10120 if (!QDF_IS_STATUS_SUCCESS(status))
10121 hdd_err("set congestion callback failed");
10122
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010123 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10124 hdd_bt_activity_cb);
10125 if (!QDF_IS_STATUS_SUCCESS(status))
10126 hdd_err("set bt activity info callback failed");
10127
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010128 EXIT();
10129
10130 return ret;
10131}
10132
10133/**
10134 * hdd_deregister_cb() - De-Register HDD callbacks.
10135 * @hdd_ctx: HDD context
10136 *
10137 * De-Register the HDD callbacks to CDS/SME.
10138 *
10139 * Return: void
10140 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010141void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010142{
10143 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010144 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010145
10146 ENTER();
10147
10148 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10149 if (!QDF_IS_STATUS_SUCCESS(status))
10150 hdd_err("De-register of dcc stats callback failed: %d",
10151 status);
10152
10153 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010154 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10155
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010156 sme_stats_ext_register_callback(hdd_ctx->hHal,
10157 wlan_hdd_cfg80211_stats_ext_callback);
10158
10159 sme_nan_deregister_callback(hdd_ctx->hHal);
10160 status = sme_reset_tsfcb(hdd_ctx->hHal);
10161 if (!QDF_IS_STATUS_SUCCESS(status))
10162 hdd_err("Failed to de-register tsfcb the callback:%d",
10163 status);
10164 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10165 if (!QDF_IS_STATUS_SUCCESS(status))
10166 hdd_err("Failed to de-register the fw mem dump callback: %d",
10167 status);
10168
Poddar, Siddarth34872782017-08-10 14:08:51 +053010169 ret = hdd_deregister_data_stall_detect_cb();
10170 if (ret)
10171 hdd_err("Failed to de-register data stall detect event callback");
10172
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010173 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10174 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10175
10176 EXIT();
10177}
10178
10179/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010180 * hdd_softap_sta_deauth() - handle deauth req from HDD
10181 * @adapter: Pointer to the HDD
10182 * @enable: bool value
10183 *
10184 * This to take counter measure to handle deauth req from HDD
10185 *
10186 * Return: None
10187 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010188QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010189 struct tagCsrDelStaParams *pDelStaParams)
10190{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010191 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010192
10193 ENTER();
10194
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010195 /* Ignore request to deauth bcmc station */
10196 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010197 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010198
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010199 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010200 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10201 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010202
10203 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010204 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010205}
10206
10207/**
10208 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10209 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010210 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010211 *
10212 * This to take counter measure to handle deauth req from HDD
10213 *
10214 * Return: None
10215 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010216void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010217 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010218{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010219 ENTER();
10220
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010221 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010222 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010223 return;
10224
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010225 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010226 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010227}
10228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010229/**
10230 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10231 * @hdd_ctx: HDD Context
10232 *
10233 * API to find if there is any STA or P2P-Client is connected
10234 *
10235 * Return: true if connected; false otherwise
10236 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010237QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010238{
10239 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10240}
10241
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010242/**
10243 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10244 * @adapter: HDD adapter pointer
10245 *
10246 * This function loop through each adapter and disable roaming on each STA
10247 * device mode except the input adapter.
10248 *
10249 * Note: On the input adapter roaming is not enabled yet hence no need to
10250 * disable.
10251 *
10252 * Return: None
10253 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010254void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010255{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010256 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010257 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010258 hdd_adapter_list_node_t *adapterNode = NULL;
10259 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010260 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010261
10262 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010263 hdd_ctx->config->isRoamOffloadScanEnabled &&
10264 QDF_STA_MODE == adapter->device_mode &&
10265 policy_mgr_is_sta_active_connection_exists(
10266 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010267 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010268 adapter->sessionId);
10269 /*
10270 * Loop through adapter and disable roaming for each STA device
10271 * mode except the input adapter.
10272 */
10273 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10274
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010275 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010276 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010277
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010278 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010279 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010280 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010281 adapterIdx->sessionId);
10282 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10283 (adapterIdx),
10284 adapterIdx->sessionId, 0);
10285 }
10286
10287 status = hdd_get_next_adapter(hdd_ctx,
10288 adapterNode,
10289 &pNext);
10290 adapterNode = pNext;
10291 }
10292 }
10293}
10294
10295/**
10296 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10297 * @adapter: HDD adapter pointer
10298 *
10299 * This function loop through each adapter and enable roaming on each STA
10300 * device mode except the input adapter.
10301 * Note: On the input adapter no need to enable roaming because link got
10302 * disconnected on this.
10303 *
10304 * Return: None
10305 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010306void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010307{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010308 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010309 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010310 hdd_adapter_list_node_t *adapterNode = NULL;
10311 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010312 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010313
10314 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010315 hdd_ctx->config->isRoamOffloadScanEnabled &&
10316 QDF_STA_MODE == adapter->device_mode &&
10317 policy_mgr_is_sta_active_connection_exists(
10318 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010319 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010320 adapter->sessionId);
10321 /*
10322 * Loop through adapter and enable roaming for each STA device
10323 * mode except the input adapter.
10324 */
10325 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10326
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010327 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010328 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010329
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010330 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010331 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010332 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010333 adapterIdx->sessionId);
10334 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10335 (adapterIdx),
10336 adapterIdx->sessionId,
10337 REASON_CONNECT);
10338 }
10339
10340 status = hdd_get_next_adapter(hdd_ctx,
10341 adapterNode,
10342 &pNext);
10343 adapterNode = pNext;
10344 }
10345 }
10346}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010347
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010348/**
10349 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10350 * @skb: sk buffer pointer
10351 *
10352 * Sends the bcast message to SVC multicast group with generic nl socket
10353 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10354 *
10355 * Return: None
10356 */
10357static void nl_srv_bcast_svc(struct sk_buff *skb)
10358{
10359#ifdef CNSS_GENL
10360 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10361#else
10362 nl_srv_bcast(skb);
10363#endif
10364}
10365
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010366void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010367{
10368 struct sk_buff *skb;
10369 struct nlmsghdr *nlh;
10370 tAniMsgHdr *ani_hdr;
10371 void *nl_data = NULL;
10372 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010373 struct radio_index_tlv *radio_info;
10374 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010375
10376 if (in_interrupt() || irqs_disabled() || in_atomic())
10377 flags = GFP_ATOMIC;
10378
10379 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10380
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010381 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010382 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010383
10384 nlh = (struct nlmsghdr *)skb->data;
10385 nlh->nlmsg_pid = 0; /* from kernel */
10386 nlh->nlmsg_flags = 0;
10387 nlh->nlmsg_seq = 0;
10388 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10389
10390 ani_hdr = NLMSG_DATA(nlh);
10391 ani_hdr->type = type;
10392
10393 switch (type) {
10394 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010395 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010396 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010397 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010398 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010399 ani_hdr->length = 0;
10400 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010401 break;
10402 case WLAN_SVC_WLAN_STATUS_IND:
10403 case WLAN_SVC_WLAN_VERSION_IND:
10404 case WLAN_SVC_DFS_CAC_START_IND:
10405 case WLAN_SVC_DFS_CAC_END_IND:
10406 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10407 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10408 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010409 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010410 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010411 ani_hdr->length = len;
10412 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10413 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10414 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010415 break;
10416
10417 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010418 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010419 type);
10420 kfree_skb(skb);
10421 return;
10422 }
10423
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010424 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010425 * Add radio index at the end of the svc event in TLV format
10426 * to maintain the backward compatibility with userspace
10427 * applications.
10428 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010429
10430 tlv_len = 0;
10431
10432 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10433 < WLAN_NL_MAX_PAYLOAD) {
10434 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10435 sizeof(*ani_hdr) + len);
10436 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10437 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10438 radio_info->radio = radio;
10439 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010440 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010441 "Added radio index tlv - radio index %d",
10442 radio_info->radio);
10443 }
10444
10445 nlh->nlmsg_len += tlv_len;
10446 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10447
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010448 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010449}
10450
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010451#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10452void wlan_hdd_auto_shutdown_cb(void)
10453{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010454 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010455
10456 if (!hdd_ctx)
10457 return;
10458
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010459 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010460 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10461 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010462}
10463
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010464void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010465{
10466 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010467 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010468 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010469 bool ap_connected = false, sta_connected = false;
10470 tHalHandle hal_handle;
10471
10472 hal_handle = hdd_ctx->hHal;
10473 if (hal_handle == NULL)
10474 return;
10475
10476 if (hdd_ctx->config->WlanAutoShutdown == 0)
10477 return;
10478
10479 if (enable == false) {
10480 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010481 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010482 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010483 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010484 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010485 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010486 return;
10487 }
10488
10489 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010490 if (policy_mgr_concurrent_open_sessions_running(
10491 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010492 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10493
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010494 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010495 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010496 if (adapter
10497 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010498 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010499 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10500 conn_info.connState ==
10501 eConnectionState_Associated) {
10502 sta_connected = true;
10503 break;
10504 }
10505 }
10506 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010507 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010508 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10509 bApActive == true) {
10510 ap_connected = true;
10511 break;
10512 }
10513 }
10514 status = hdd_get_next_adapter(hdd_ctx,
10515 adapterNode,
10516 &pNext);
10517 adapterNode = pNext;
10518 }
10519 }
10520
10521 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010522 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010523 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010524 }
Jeff Johnson68755312017-02-10 11:46:55 -080010525
10526 if (sme_set_auto_shutdown_timer(hal_handle,
10527 hdd_ctx->config->WlanAutoShutdown)
10528 != QDF_STATUS_SUCCESS)
10529 hdd_err("Failed to start wlan auto shutdown timer");
10530 else
10531 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10532 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010533}
10534#endif
10535
Jeff Johnson9d295242017-08-29 14:39:48 -070010536struct hdd_adapter *hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010537 bool check_start_bss)
10538{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010539 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010540 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010541 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010542 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10543
10544 con_sap_adapter = NULL;
10545
10546 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010547 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010548 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010549 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10550 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010551 adapter != this_sap_adapter) {
10552 if (check_start_bss) {
10553 if (test_bit(SOFTAP_BSS_STARTED,
10554 &adapter->event_flags)) {
10555 con_sap_adapter = adapter;
10556 break;
10557 }
10558 } else {
10559 con_sap_adapter = adapter;
10560 break;
10561 }
10562 }
10563 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10564 adapterNode = pNext;
10565 }
10566
10567 return con_sap_adapter;
10568}
10569
10570#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010571static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010572{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010573 return adapter->device_mode == QDF_STA_MODE ||
10574 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010575}
10576
Jeff Johnson9d295242017-08-29 14:39:48 -070010577static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010578{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010579 return adapter->device_mode == QDF_SAP_MODE ||
10580 adapter->device_mode == QDF_P2P_GO_MODE;
10581}
10582
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010583static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010584{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010585 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010586 hdd_adapter_list_node_t *node;
10587
10588 status = hdd_get_front_adapter(hdd_ctx, &node);
10589 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010590 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010591
10592 if (adapter &&
10593 hdd_adapter_is_sta(adapter) &&
10594 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10595 conn_info.connState == eConnectionState_Associated) {
10596 return true;
10597 }
10598
10599 if (adapter &&
10600 hdd_adapter_is_ap(adapter) &&
10601 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10602 return true;
10603 }
10604
10605 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10606 }
10607
10608 return false;
10609}
10610
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010611static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010612{
10613 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010614
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010615 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010616 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010617 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010618
Dustin Brown5ec6b552017-03-31 12:11:40 -070010619 return is_running;
10620}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010621
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010622static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010623{
10624 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10625 hdd_ctx->bus_bw_timer_running = true;
10626 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10627 hdd_ctx->config->busBandwidthComputeInterval);
10628 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10629}
10630
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010631void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010632{
10633 ENTER();
10634
10635 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10636 hdd_debug("Bandwidth compute timer already started");
10637 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010638 }
10639
Dustin Brown5ec6b552017-03-31 12:11:40 -070010640 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10641
10642 EXIT();
10643}
10644
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010645void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010646{
10647 ENTER();
10648
10649 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10650 hdd_debug("Bandwidth compute timer already started");
10651 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010652 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010653
10654 if (hdd_any_adapter_is_assoc(hdd_ctx))
10655 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10656
10657 EXIT();
10658}
10659
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010660static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010661{
10662 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10663
10664 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10665 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10666 hdd_ctx->bus_bw_timer_running = false;
10667 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10668
10669 hdd_reset_tcp_delack(hdd_ctx);
10670}
10671
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010672void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010673{
10674 ENTER();
10675
10676 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10677 hdd_debug("Bandwidth compute timer already stopped");
10678 return;
10679 }
10680
10681 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10682
10683 EXIT();
10684}
10685
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010686void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010687{
10688 ENTER();
10689
10690 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10691 hdd_debug("Bandwidth compute timer already stopped");
10692 return;
10693 }
10694
10695 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10696 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10697
10698 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010699}
10700#endif
10701
10702/**
10703 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10704 * and sta's operating channel.
10705 * @sta_adapter: Describe the first argument to foobar.
10706 * @ap_adapter: Describe the second argument to foobar.
10707 * @roam_profile: Roam profile of AP to which STA wants to connect.
10708 * @concurrent_chnl_same: If both SAP and STA channels are same then
10709 * set this flag to true else false.
10710 *
10711 * This function checks the sap's operating channel and sta's operating channel.
10712 * if both are same then it will return false else it will restart the sap in
10713 * sta's channel and return true.
10714 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010715 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010716 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010717QDF_STATUS wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10718 struct hdd_adapter *ap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010719 tCsrRoamProfile *roam_profile,
10720 tScanResultHandle *scan_cache,
10721 bool *concurrent_chnl_same)
10722{
Jeff Johnson87251032017-08-29 13:31:11 -070010723 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010724 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010725 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010726 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010727 *concurrent_chnl_same = true;
10728
10729 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10730 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010731 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010732 scan_cache,
10733 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010734 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010735 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010736 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10737 if (hdd_ap_ctx->operatingChannel != channel_id) {
10738 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010739 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010740 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010741 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010742 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10743 if (hdd_ap_ctx->operatingChannel != channel_id) {
10744 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010745 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010746 }
10747 }
10748 } else {
10749 /*
10750 * Lets handle worst case scenario here, Scan cache lookup is
10751 * failed so we have to stop the SAP to avoid any channel
10752 * discrepancy between SAP's channel and STA's channel.
10753 * Return the status as failure so caller function could know
10754 * that scan look up is failed.
10755 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010756 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010757 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010758 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010759 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010760}
10761
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010762/**
10763 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10764 * @ap_adapter: SAP adapter
10765 *
10766 * This function will process the stopping of sap adapter.
10767 *
10768 * Return: None
10769 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010770void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010771{
Jeff Johnson87251032017-08-29 13:31:11 -070010772 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010773 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010774 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010775 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010776
10777 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010778 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010779 return;
10780 }
10781
10782 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10783 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010784 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010785 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010786
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010787 mutex_lock(&hdd_ctx->sap_lock);
10788 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010789 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010790 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10791 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010792 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010793 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010794 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010795 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010796 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010797 qdf_stop_bss_event,
10798 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010799 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010800 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010801 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010802 return;
10803 }
10804 }
10805 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010806 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10807 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010808 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010809 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010810 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010811 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010812 }
10813 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010814}
10815
10816/**
10817 * wlan_hdd_start_sap() - this function starts bss of SAP.
10818 * @ap_adapter: SAP adapter
10819 *
10820 * This function will process the starting of sap adapter.
10821 *
10822 * Return: None
10823 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010824void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010825{
Jeff Johnson87251032017-08-29 13:31:11 -070010826 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010827 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010828 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010829 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010830 tsap_Config_t *sap_config;
10831
10832 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010833 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010834 return;
10835 }
10836
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010837 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010838 hdd_err("SoftAp role has not been enabled");
10839 return;
10840 }
10841
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010842 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10843 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10844 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10845 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10846
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010847 mutex_lock(&hdd_ctx->sap_lock);
10848 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10849 goto end;
10850
10851 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010852 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010853 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10854 goto end;
10855 }
10856
Wei Song2f76f642016-11-18 16:32:53 +080010857 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010858 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10859 &hdd_ap_ctx->sapConfig,
10860 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010861 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010862 goto end;
10863
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010864 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010865 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010866 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010867 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010868 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010869 goto end;
10870 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010871 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010872 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010873 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010874 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10875 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010876 ap_adapter->sessionId);
10877 hostapd_state->bCommit = true;
10878
10879end:
10880 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010881 /* SAP context and beacon cleanup will happen during driver unload
10882 * in hdd_stop_adapter
10883 */
10884 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10885
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010886}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010887
10888/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010889 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10890 * mac scan config
10891 * @status: Status of set antenna mode
10892 *
10893 * Callback on setting the dual mac configuration
10894 *
10895 * Return: None
10896 */
10897void wlan_hdd_soc_set_antenna_mode_cb(
10898 enum set_antenna_mode_status status)
10899{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010900 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010901
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010902 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010903
10904 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10905 if (0 != wlan_hdd_validate_context(hdd_ctx))
10906 return;
10907
10908 /* Signal the completion of set dual mac config */
10909 complete(&hdd_ctx->set_antenna_mode_cmpl);
10910}
10911
10912/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010913 * hdd_get_fw_version() - Get FW version
10914 * @hdd_ctx: pointer to HDD context.
10915 * @major_spid: FW version - major spid.
10916 * @minor_spid: FW version - minor spid
10917 * @ssid: FW version - ssid
10918 * @crmid: FW version - crmid
10919 *
10920 * This function is called to get the firmware build version stored
10921 * as part of the HDD context
10922 *
10923 * Return: None
10924 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010925void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010926 uint32_t *major_spid, uint32_t *minor_spid,
10927 uint32_t *siid, uint32_t *crmid)
10928{
10929 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10930 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10931 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10932 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10933}
10934
10935#ifdef QCA_CONFIG_SMP
10936/**
10937 * wlan_hdd_get_cpu() - get cpu_index
10938 *
10939 * Return: cpu_index
10940 */
10941int wlan_hdd_get_cpu(void)
10942{
10943 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010945 put_cpu();
10946 return cpu_index;
10947}
10948#endif
10949
10950/**
10951 * hdd_get_fwpath() - get framework path
10952 *
10953 * This function is used to get the string written by
10954 * userspace to start the wlan driver
10955 *
10956 * Return: string
10957 */
10958const char *hdd_get_fwpath(void)
10959{
10960 return fwpath.string;
10961}
10962
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010963static int hdd_qdf_print_init(void)
10964{
10965 int qdf_print_idx;
10966 QDF_STATUS status;
10967
10968 status = qdf_print_setup();
10969 if (status != QDF_STATUS_SUCCESS) {
10970 pr_err("qdf_print_setup failed\n");
10971 return -EINVAL;
10972 }
10973
10974 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10975
10976 if (qdf_print_idx < 0) {
10977 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10978 qdf_print_idx);
10979 return -EINVAL;
10980 }
10981
10982 qdf_set_pidx(qdf_print_idx);
10983
10984 return 0;
10985}
10986
10987static void hdd_qdf_print_deinit(void)
10988{
10989 int qdf_print_idx;
10990
10991 qdf_print_idx = qdf_get_pidx();
10992 qdf_print_ctrl_cleanup(qdf_print_idx);
10993}
10994
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010995/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010996 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010997 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010998 * This function initilizes CDS global context with the help of cds_init. This
10999 * has to be the first function called after probe to get a valid global
11000 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011001 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011002 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011003 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011004int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011005{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011006 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011007 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011008
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011009 status = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011010
11011 wlan_init_bug_report_lock();
11012
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011013#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11014 wlan_logging_sock_init_svc();
11015#endif
11016
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011017 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011018 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011019 ret = -ENOMEM;
11020 goto err_out;
11021 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011022
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011023 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11024 (void *)hdd_drv_ops_inactivity_handler, NULL,
11025 QDF_TIMER_TYPE_SW);
11026
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011027 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011028 hdd_qdf_print_init();
11029
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011030 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011031
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011032err_out:
11033 return ret;
11034}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011035
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011036/**
11037 * hdd_deinit() - Deinitialize Driver
11038 *
11039 * This function frees CDS global context with the help of cds_deinit. This
11040 * has to be the last function call in remove callback to free the global
11041 * context.
11042 */
11043void hdd_deinit(void)
11044{
Dustin Brownedce4a52017-05-10 11:59:15 -070011045 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011046 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011047
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011048 hdd_qdf_print_deinit();
11049
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011050#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11051 wlan_logging_sock_deinit_svc();
11052#endif
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011053
11054 wlan_destroy_bug_report_lock();
11055 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011056}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011057
Yue Ma6e7b1a02017-04-03 14:17:46 -070011058#ifdef QCA_WIFI_NAPIER_EMULATION
11059#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11060#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011061#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011062#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011063
Sachin Ahujadddd2632017-03-07 19:07:24 +053011064static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11065 struct file *file)
11066{
11067 return 0;
11068}
11069
11070static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11071 const char __user *user_buf,
11072 size_t count,
11073 loff_t *f_pos)
11074{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011075 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011076 static const char wlan_off_str[] = "OFF";
11077 static const char wlan_on_str[] = "ON";
11078 int ret;
11079 unsigned long rc;
11080
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011081 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011082 pr_err("Failed to read buffer\n");
11083 return -EINVAL;
11084 }
11085
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011086 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011087 pr_debug("Wifi turning off from UI\n");
11088 goto exit;
11089 }
11090
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011091 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011092 pr_err("Invalid value received from framework");
11093 goto exit;
11094 }
11095
11096 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011097 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011098 rc = wait_for_completion_timeout(&wlan_start_comp,
11099 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11100 if (!rc) {
11101 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11102 ret = -EINVAL;
11103 hdd_start_complete(ret);
11104 return ret;
11105 }
11106
11107 hdd_start_complete(0);
11108 }
11109
11110exit:
11111 return count;
11112}
11113
11114
11115const struct file_operations wlan_hdd_state_fops = {
11116 .owner = THIS_MODULE,
11117 .open = wlan_hdd_state_ctrl_param_open,
11118 .write = wlan_hdd_state_ctrl_param_write,
11119};
11120
11121static int wlan_hdd_state_ctrl_param_create(void)
11122{
11123 unsigned int wlan_hdd_state_major = 0;
11124 int ret;
11125 struct device *dev;
11126
11127 device = MKDEV(wlan_hdd_state_major, 0);
11128
11129 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11130 if (ret) {
11131 pr_err("Failed to register qcwlanstate");
11132 goto dev_alloc_err;
11133 }
11134 wlan_hdd_state_major = MAJOR(device);
11135
11136 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11137 if (IS_ERR(class)) {
11138 pr_err("wlan_hdd_state class_create error");
11139 goto class_err;
11140 }
11141
11142 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11143 if (IS_ERR(dev)) {
11144 pr_err("wlan_hdd_statedevice_create error");
11145 goto err_class_destroy;
11146 }
11147
11148 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11149 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11150 if (ret) {
11151 pr_err("Failed to add cdev error");
11152 goto cdev_add_err;
11153 }
11154
11155 pr_info("wlan_hdd_state %s major(%d) initialized",
11156 WLAN_MODULE_NAME, wlan_hdd_state_major);
11157
11158 return 0;
11159
11160cdev_add_err:
11161 device_destroy(class, device);
11162err_class_destroy:
11163 class_destroy(class);
11164class_err:
11165 unregister_chrdev_region(device, dev_num);
11166dev_alloc_err:
11167 return -ENODEV;
11168}
11169
11170static void wlan_hdd_state_ctrl_param_destroy(void)
11171{
11172 cdev_del(&wlan_hdd_state_cdev);
11173 device_destroy(class, device);
11174 class_destroy(class);
11175 unregister_chrdev_region(device, dev_num);
11176
11177 pr_info("Device node unregistered");
11178}
11179
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011180/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011181 * component_init - API to init cld component's
11182 *
11183 * Return: None
11184 */
11185static void component_init(void)
11186{
11187 pmo_init();
11188}
11189
11190/**
11191 * component_deinit - API to deinit cld component's
11192 *
11193 * Return: None
11194 */
11195static void component_deinit(void)
11196{
11197 pmo_deinit();
11198}
11199
11200/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011201 * __hdd_module_init - Module init helper
11202 *
11203 * Module init helper function used by both module and static driver.
11204 *
11205 * Return: 0 for success, errno on failure
11206 */
11207static int __hdd_module_init(void)
11208{
11209 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011210
Dustin Brownab482ac2017-06-09 17:00:44 -070011211 pr_err("%s: Loading driver v%s (%s)%s\n",
11212 WLAN_MODULE_NAME,
11213 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011214 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011215 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011216
Sachin Ahujadddd2632017-03-07 19:07:24 +053011217 ret = wlan_hdd_state_ctrl_param_create();
11218 if (ret) {
11219 pr_err("wlan_hdd_state_create:%x\n", ret);
11220 goto err_dev_state;
11221 }
11222
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011223 pld_init();
11224
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011225 ret = hdd_init();
11226 if (ret) {
11227 pr_err("hdd_init failed %x\n", ret);
11228 goto err_hdd_init;
11229 }
11230
Rajeev Kumar97767a02016-11-30 11:20:40 -080011231 dispatcher_init();
11232
Mukul Sharmad75a6672017-06-22 15:40:53 +053011233 /* Ensure to call post objmgr init */
11234 component_init();
11235
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011236 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011237
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011238 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011239
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011240 ret = wlan_hdd_register_driver();
11241 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011242 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11243 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011244 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011245 }
11246
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011247 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011248
11249 return 0;
11250out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011251 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011252 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011253 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011254
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011255err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011256 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011257 wlan_hdd_state_ctrl_param_destroy();
11258err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011259 return ret;
11260}
11261
11262/**
11263 * __hdd_module_exit - Module exit helper
11264 *
11265 * Module exit helper function used by both module and static driver.
11266 */
11267static void __hdd_module_exit(void)
11268{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011269
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011270 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11271 QWLAN_VERSIONSTR);
11272
bings6028ee82017-03-29 07:51:40 +080011273 cds_set_unload_in_progress(true);
11274
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011275 hdd_wait_for_recovery_completion();
11276
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011277 wlan_hdd_unregister_driver();
11278
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011279 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011280
Mukul Sharmad75a6672017-06-22 15:40:53 +053011281 /* Ensure to call prior to objmgr deinit */
11282 component_deinit();
11283
Rajeev Kumar97767a02016-11-30 11:20:40 -080011284 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011285 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011286 pld_deinit();
11287
Sachin Ahujadddd2632017-03-07 19:07:24 +053011288 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011289}
11290
Arun Khandavallifae92942016-08-01 13:31:08 +053011291#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011292/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011293 * wlan_boot_cb() - Wlan boot callback
11294 * @kobj: object whose directory we're creating the link in.
11295 * @attr: attribute the user is interacting with
11296 * @buff: the buffer containing the user data
11297 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011298 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011299 * This callback is invoked when the fs is ready to start the
11300 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011301 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011302 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011303 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011304static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011305 struct kobj_attribute *attr,
11306 const char *buf,
11307 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011308{
Arun Khandavallifae92942016-08-01 13:31:08 +053011309
Arun Khandavallifae92942016-08-01 13:31:08 +053011310 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011311 pr_err("%s: wlan driver already initialized\n", __func__);
11312 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011313 }
11314
Arun Khandavallifae92942016-08-01 13:31:08 +053011315 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011316 pr_err("%s: wlan driver initialization failed\n", __func__);
11317 return -EIO;
11318 }
11319
11320 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011321
11322 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011323}
Arun Khandavallifae92942016-08-01 13:31:08 +053011324
11325/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011326 * hdd_sysfs_cleanup() - cleanup sysfs
11327 *
11328 * Return: None
11329 *
11330 */
11331static void hdd_sysfs_cleanup(void)
11332{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011333 /* remove from group */
11334 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11335 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11336 wlan_loader->attr_group);
11337
11338 /* unlink the object from parent */
11339 kobject_del(wlan_loader->boot_wlan_obj);
11340
11341 /* free the object */
11342 kobject_put(wlan_loader->boot_wlan_obj);
11343
11344 kfree(wlan_loader->attr_group);
11345 kfree(wlan_loader);
11346
11347 wlan_loader = NULL;
11348}
11349
11350/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011351 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11352 * ready
11353 *
11354 * This is creates the syfs entry boot_wlan. Which shall be invoked
11355 * when the filesystem is ready.
11356 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011357 * QDF API cannot be used here since this function is called even before
11358 * initializing WLAN driver.
11359 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011360 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011361 */
11362static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011363{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011364 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011365
11366 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011367 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011368 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011369
11370 wlan_loader->boot_wlan_obj = NULL;
11371 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11372 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011373 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011374 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011375
11376 wlan_loader->loaded_state = 0;
11377 wlan_loader->attr_group->attrs = attrs;
11378
11379 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11380 kernel_kobj);
11381 if (!wlan_loader->boot_wlan_obj) {
11382 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011383 goto error_return;
11384 }
11385
11386 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11387 wlan_loader->attr_group);
11388 if (ret) {
11389 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11390 goto error_return;
11391 }
11392
11393 return 0;
11394
11395error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011396 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011397
11398 return ret;
11399}
11400
11401/**
11402 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11403 *
11404 * Return: 0 on success or errno on failure
11405 */
11406static int wlan_deinit_sysfs(void)
11407{
Arun Khandavallifae92942016-08-01 13:31:08 +053011408 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011409 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011410 return -EINVAL;
11411 }
11412
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011413 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011414 return 0;
11415}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011416
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011417#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011418
11419#ifdef MODULE
11420/**
11421 * __hdd_module_init - Module init helper
11422 *
11423 * Module init helper function used by both module and static driver.
11424 *
11425 * Return: 0 for success, errno on failure
11426 */
11427static int hdd_module_init(void)
11428{
Arun Khandavallifae92942016-08-01 13:31:08 +053011429 if (__hdd_module_init()) {
11430 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011431 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011432 }
11433
Dustin Brownab482ac2017-06-09 17:00:44 -070011434 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011435}
11436#else
11437static int __init hdd_module_init(void)
11438{
11439 int ret = -EINVAL;
11440
11441 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011442 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011443 pr_err("Failed to create sysfs entry for loading wlan");
11444
11445 return ret;
11446}
11447#endif
11448
11449
11450#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011451/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011452 * hdd_module_exit() - Exit function
11453 *
11454 * This is the driver exit point (invoked when module is unloaded using rmmod)
11455 *
11456 * Return: None
11457 */
11458static void __exit hdd_module_exit(void)
11459{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011460 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011461}
Arun Khandavallifae92942016-08-01 13:31:08 +053011462#else
11463static void __exit hdd_module_exit(void)
11464{
11465 __hdd_module_exit();
11466 wlan_deinit_sysfs();
11467}
11468#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011469
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011470static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11471{
11472 return param_set_copystring(kmessage, kp);
11473}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011474
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011475/**
11476 * is_con_mode_valid() check con mode is valid or not
11477 * @mode: global con mode
11478 *
11479 * Return: TRUE on success FALSE on failure
11480 */
11481static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11482{
11483 switch (mode) {
11484 case QDF_GLOBAL_MONITOR_MODE:
11485 case QDF_GLOBAL_FTM_MODE:
11486 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011487 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011488 return true;
11489 default:
11490 return false;
11491 }
11492}
11493
11494/**
11495 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11496 * @mode: global con mode
11497 *
11498 * Return: adapter mode
11499 */
11500static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11501 enum tQDF_GLOBAL_CON_MODE mode)
11502{
11503
11504 switch (mode) {
11505 case QDF_GLOBAL_MISSION_MODE:
11506 return QDF_STA_MODE;
11507 case QDF_GLOBAL_MONITOR_MODE:
11508 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011509 case QDF_GLOBAL_EPPING_MODE:
11510 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011511 case QDF_GLOBAL_FTM_MODE:
11512 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011513 case QDF_GLOBAL_QVIT_MODE:
11514 return QDF_QVIT_MODE;
11515 default:
11516 return QDF_MAX_NO_OF_MODE;
11517 }
11518}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011519
Dustin Brown27cd9942017-09-27 16:11:44 -070011520static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11521 enum tQDF_GLOBAL_CON_MODE curr_mode)
11522{
11523 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11524 return;
11525
11526 switch (curr_mode) {
11527 case QDF_GLOBAL_MISSION_MODE:
11528 case QDF_GLOBAL_MONITOR_MODE:
11529 case QDF_GLOBAL_FTM_MODE:
11530 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11531 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11532
11533 /* re-use the existing session */
11534 hdd_stop_all_adapters(hdd_ctx, false);
11535 break;
11536 default:
11537 break;
11538 }
11539}
11540
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011541static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011542 enum tQDF_GLOBAL_CON_MODE curr_mode)
11543{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011544 int driver_status;
11545
11546 driver_status = hdd_ctx->driver_status;
11547
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011548 switch (curr_mode) {
11549 case QDF_GLOBAL_MISSION_MODE:
11550 case QDF_GLOBAL_MONITOR_MODE:
11551 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011552 hdd_deinit_all_adapters(hdd_ctx, false);
11553 hdd_close_all_adapters(hdd_ctx, false);
11554 break;
11555 case QDF_GLOBAL_EPPING_MODE:
11556 epping_disable();
11557 epping_close();
11558 break;
11559 default:
11560 return;
11561 }
11562}
11563
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011564static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011565 enum tQDF_GLOBAL_CON_MODE mode)
11566{
Jeff Johnson9d295242017-08-29 14:39:48 -070011567 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011568 int ret = 0;
11569 bool rtnl_held;
11570 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11571 QDF_STATUS status;
11572
11573 if (!qdf_dev) {
11574 hdd_err("qdf device context is Null return!");
11575 return -EINVAL;
11576 }
11577
11578 rtnl_held = hdd_hold_rtnl_lock();
11579 switch (mode) {
11580 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011581 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11582 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011583 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011584 break;
11585 case QDF_GLOBAL_FTM_MODE:
11586 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11587 wlan_hdd_get_intf_addr(hdd_ctx),
11588 NET_NAME_UNKNOWN, rtnl_held);
11589 if (adapter == NULL)
11590 ret = -EINVAL;
11591 break;
11592 case QDF_GLOBAL_MONITOR_MODE:
11593 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11594 wlan_hdd_get_intf_addr(hdd_ctx),
11595 NET_NAME_UNKNOWN, rtnl_held);
11596 if (adapter == NULL)
11597 ret = -EINVAL;
11598 break;
11599 case QDF_GLOBAL_EPPING_MODE:
11600 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011601 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011602 hdd_err("Failed to open in eeping mode: %d", status);
11603 ret = -EINVAL;
11604 break;
11605 }
11606 ret = epping_enable(qdf_dev->dev);
11607 if (ret) {
11608 hdd_err("Failed to enable in epping mode : %d", ret);
11609 epping_close();
11610 }
11611 break;
11612 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011613 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011614 ret = -ENOTSUPP;
11615 break;
11616 }
11617 hdd_release_rtnl_lock();
11618 rtnl_held = false;
11619 return ret;
11620}
11621
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011622/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011623 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011624 * @kmessage: con mode name on which driver to be bring up
11625 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011626 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011627 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011628 * This function is invoked when user updates con mode using sys entry,
11629 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011630 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011631 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011632 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011633static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011634 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011635{
11636 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011637 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011638 enum tQDF_GLOBAL_CON_MODE curr_mode;
11639 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011640
Dustin Brownab6029b2017-05-24 13:04:19 -070011641 hdd_info("con_mode handler: %s", kmessage);
11642
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011643 ret = wlan_hdd_validate_context(hdd_ctx);
11644 if (ret)
11645 return ret;
11646
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011647 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011648
11649 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011650
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011651 if (!(is_con_mode_valid(con_mode))) {
11652 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011653 ret = -EINVAL;
11654 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011655 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011656
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011657 curr_mode = hdd_get_conparam();
11658 if (curr_mode == con_mode) {
11659 hdd_err("curr mode: %d is same as user triggered mode %d",
11660 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011661 ret = 0;
11662 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011663 }
11664
Dustin Brown27cd9942017-09-27 16:11:44 -070011665 /* ensure adapters are stopped */
11666 hdd_stop_present_mode(hdd_ctx, curr_mode);
11667
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011668 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011669 if (ret) {
11670 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011671 goto reset_flags;
11672 }
11673
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011674 /* Cleanup present mode before switching to new mode */
11675 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11676
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011677 hdd_set_conparam(con_mode);
11678
11679 /* Register for new con_mode & then kick_start modules again */
11680 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11681 if (ret) {
11682 hdd_err("Failed to register for new mode");
11683 goto reset_flags;
11684 }
11685
11686 adapter_mode = hdd_get_adpter_mode(con_mode);
11687 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11688 hdd_err("invalid adapter");
11689 ret = -EINVAL;
11690 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011691 }
11692
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011693 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011694 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011695 hdd_err("Failed to get adapter:%d", adapter_mode);
11696 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011697 }
11698
11699 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11700 if (ret) {
11701 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011702 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011703 }
11704
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011705 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011706 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011707 if (hdd_start_adapter(adapter)) {
11708 hdd_err("Failed to start %s adapter", kmessage);
11709 ret = -EINVAL;
11710 goto reset_flags;
11711 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011712 }
11713
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011714 hdd_info("Mode successfully changed to %s", kmessage);
11715 ret = 0;
11716
11717reset_flags:
11718 cds_set_load_in_progress(false);
11719 return ret;
11720}
11721
11722
11723static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11724{
11725 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011726 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011727
11728 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11729 ret = wlan_hdd_validate_context(hdd_ctx);
11730 if (ret)
11731 return ret;
11732
11733 cds_ssr_protect(__func__);
11734 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11735 cds_ssr_unprotect(__func__);
11736
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011737 return ret;
11738}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011739
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011740static int con_mode_handler_ftm(const char *kmessage,
11741 struct kernel_param *kp)
11742{
11743 int ret;
11744
11745 ret = param_set_int(kmessage, kp);
11746
11747 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11748 pr_err("Only FTM mode supported!");
11749 return -ENOTSUPP;
11750 }
11751
11752 hdd_set_conparam(con_mode_ftm);
11753 con_mode = con_mode_ftm;
11754
11755 return ret;
11756}
11757
Ravi Joshia307f632017-07-17 23:41:41 -070011758static int con_mode_handler_monitor(const char *kmessage,
11759 struct kernel_param *kp)
11760{
11761 int ret;
11762
11763 ret = param_set_int(kmessage, kp);
11764
11765 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11766 pr_err("Only Monitor mode supported!");
11767 return -ENOTSUPP;
11768 }
11769
11770 hdd_set_conparam(con_mode_monitor);
11771 con_mode = con_mode_monitor;
11772
11773 return ret;
11774}
11775
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011776/**
11777 * hdd_get_conparam() - driver exit point
11778 *
11779 * This is the driver exit point (invoked when module is unloaded using rmmod)
11780 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011781 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011782 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011783enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011784{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011785 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011786}
11787
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011788void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011789{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011790 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011791}
11792
Komal Seelamc11bb222016-01-27 18:57:10 +053011793/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011794 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11795 * @hdd_ctx: HDD context
11796 *
11797 * Cleans up the pre cac interface, if it exists
11798 *
11799 * Return: None
11800 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011801void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011802{
11803 uint8_t session_id;
11804 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011805 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011806
11807 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11808 if (QDF_IS_STATUS_ERROR(status)) {
11809 hdd_err("failed to get pre cac vdev id");
11810 return;
11811 }
11812
11813 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11814 if (!precac_adapter) {
11815 hdd_err("invalid pre cac adapater");
11816 return;
11817 }
11818
11819 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11820 wlan_hdd_sap_pre_cac_failure,
11821 (void *)precac_adapter);
11822 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11823
11824}
11825
11826/**
Komal Seelamec702b02016-02-24 18:42:16 +053011827 * hdd_update_ol_config - API to update ol configuration parameters
11828 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011829 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011830 * Return: void
11831 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011832static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011833{
Komal Seelamec702b02016-02-24 18:42:16 +053011834 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011835 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011836
Komal Seelamec702b02016-02-24 18:42:16 +053011837 if (!ol_ctx)
11838 return;
11839
11840 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11841 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11842 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11843 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011844 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011845
11846 ol_init_ini_config(ol_ctx, &cfg);
11847}
11848
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011849#ifdef FEATURE_RUNTIME_PM
11850/**
11851 * hdd_populate_runtime_cfg() - populate runtime configuration
11852 * @hdd_ctx: hdd context
11853 * @cfg: pointer to the configuration memory being populated
11854 *
11855 * Return: void
11856 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011857static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011858 struct hif_config_info *cfg)
11859{
11860 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11861 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11862}
11863#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011864static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011865 struct hif_config_info *cfg)
11866{
11867}
11868#endif
11869
Komal Seelamec702b02016-02-24 18:42:16 +053011870/**
11871 * hdd_update_hif_config - API to update HIF configuration parameters
11872 * @hdd_ctx: HDD Context
11873 *
11874 * Return: void
11875 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011876static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011877{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011878 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011879 struct hif_config_info cfg;
11880
11881 if (!scn)
11882 return;
11883
11884 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011885 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011886 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011887
11888 if (hdd_ctx->config->prevent_link_down)
11889 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011890}
11891
11892/**
11893 * hdd_update_config() - Initialize driver per module ini parameters
11894 * @hdd_ctx: HDD Context
11895 *
11896 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011897 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011898 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011899int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011900{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011901 int ret;
11902
Komal Seelamec702b02016-02-24 18:42:16 +053011903 hdd_update_ol_config(hdd_ctx);
11904 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011905 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11906 ret = hdd_update_cds_config_ftm(hdd_ctx);
11907 else
11908 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011909 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011910
11911 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011912}
11913
Mukul Sharma9d797a02017-01-05 20:26:03 +053011914#ifdef FEATURE_WLAN_RA_FILTERING
11915/**
11916 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11917 * @psoc_cfg: pmo psoc Configuration
11918 * @hdd_ctx: Pointer to hdd context
11919 *
11920 * Return: none
11921 */
11922static inline void hdd_ra_populate_pmo_config(
11923 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011924 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011925{
11926 psoc_cfg->ra_ratelimit_interval =
11927 hdd_ctx->config->RArateLimitInterval;
11928 psoc_cfg->ra_ratelimit_enable =
11929 hdd_ctx->config->IsRArateLimitEnabled;
11930}
11931#else
11932static inline void hdd_ra_populate_pmo_config(
11933 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011934 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011935{
11936}
11937#endif
11938/**
11939 * hdd_update_pmo_config - API to update pmo configuration parameters
11940 * @hdd_ctx: HDD context
11941 *
11942 * Return: void
11943 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011944static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011945{
11946 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11947 struct pmo_psoc_cfg psoc_cfg;
11948 QDF_STATUS status;
11949
11950 /*
11951 * Value of hdd_ctx->wowEnable can be,
11952 * 0 - Disable both magic pattern match and pattern byte match.
11953 * 1 - Enable magic pattern match on all interfaces.
11954 * 2 - Enable pattern byte match on all interfaces.
11955 * 3 - Enable both magic patter and pattern byte match on
11956 * all interfaces.
11957 */
11958 psoc_cfg.magic_ptrn_enable =
11959 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11960 psoc_cfg.ptrn_match_enable_all_vdev =
11961 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080011962 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
11963 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011964 psoc_cfg.bpf_enable =
11965 hdd_ctx->config->bpf_packet_filter_enable;
11966 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011967 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011968 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11969 if (hdd_ctx->config->fhostNSOffload)
11970 psoc_cfg.ns_offload_enable_dynamic = true;
11971 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11972 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11973 psoc_cfg.active_mode_offload =
11974 hdd_ctx->config->active_mode_offload;
11975 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11976 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011977 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11978 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11979 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11980 psoc_cfg.power_save_mode =
11981 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011982 psoc_cfg.auto_power_save_fail_mode =
11983 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011984
11985 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011986 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11987 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011988 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11989 if (status != QDF_STATUS_SUCCESS) {
11990 hdd_err("failed pmo psoc configuration");
11991 return -EINVAL;
11992 }
11993
11994 return 0;
11995}
11996
Abhishek Singhb20db962017-03-03 21:28:46 +053011997#ifdef FEATURE_WLAN_SCAN_PNO
11998static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11999 struct hdd_config *cfg)
12000{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012001 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12002
Abhishek Singhb20db962017-03-03 21:28:46 +053012003 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12004 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12005 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12006 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12007 pno_cfg->channel_prediction_full_scan =
12008 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012009 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12010 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12011 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12012 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012013}
12014#else
12015static inline void
12016hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012017 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012018{
Abhishek Singhb20db962017-03-03 21:28:46 +053012019}
12020#endif
12021
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012022void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12023 struct hdd_config *cfg)
12024{
12025 uint8_t i = 0;
12026
12027 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12028 if (!ie_whitelist->white_list)
12029 return;
12030
12031 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12032 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12033 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12034 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12035 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12036 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12037 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12038 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12039
12040 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12041 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12042 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12043}
12044
Abhishek Singh257a9482017-03-06 16:52:39 +053012045/**
12046 * hdd_update_scan_config - API to update scan configuration parameters
12047 * @hdd_ctx: HDD context
12048 *
12049 * Return: 0 if success else err
12050 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012051static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012052{
12053 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12054 struct scan_user_cfg scan_cfg;
12055 struct hdd_config *cfg = hdd_ctx->config;
12056 QDF_STATUS status;
12057
12058 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12059 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12060 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12061 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12062 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12063 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12064 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012065 /* convert to ms */
12066 scan_cfg.scan_cache_aging_time =
12067 cfg->scanAgingTimeout * 1000;
12068 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12069 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12070 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12071 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012072 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012073 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012074 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Abhishek Singh257a9482017-03-06 16:52:39 +053012075
Abhishek Singhb20db962017-03-03 21:28:46 +053012076 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012077 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012078
Abhishek Singh257a9482017-03-06 16:52:39 +053012079 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12080 if (status != QDF_STATUS_SUCCESS) {
12081 hdd_err("failed pmo psoc configuration");
12082 return -EINVAL;
12083 }
12084
12085 return 0;
12086}
Abhishek Singh257a9482017-03-06 16:52:39 +053012087
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012088static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012089{
12090 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12091 struct tdls_start_params tdls_cfg;
12092 struct tdls_user_config *config = &tdls_cfg.config;
12093 struct hdd_config *cfg = hdd_ctx->config;
12094 QDF_STATUS status;
12095
12096 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12097 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12098 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12099 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12100 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12101 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12102 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12103 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12104 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12105 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12106 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12107 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12108 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12109 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12110 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12111 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12112 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12113 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12114 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12115 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12116 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12117 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12118 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12119 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12120 (cfg->fEnableTDLSImplicitTrigger ?
12121 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12122 (cfg->fTDLSExternalControl ?
12123 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12124
12125 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12126 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12127 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12128 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012129 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012130 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012131 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12132 tdls_cfg.tdls_evt_cb_data = psoc;
12133 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12134 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12135 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012136 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12137 tdls_cfg.tdls_wmm_cb_data = psoc;
12138 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12139 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012140 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012141
12142 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12143 if (status != QDF_STATUS_SUCCESS) {
12144 hdd_err("failed pmo psoc configuration");
12145 return -EINVAL;
12146 }
12147
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012148 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012149 /* enable napier specific tdls data path */
12150 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012151
Frank Liud4b2fa02017-03-29 11:46:48 +080012152 return 0;
12153}
Frank Liud4b2fa02017-03-29 11:46:48 +080012154
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012155int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012156{
12157 int ret;
12158
12159 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012160 if (ret)
12161 return ret;
12162 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012163 if (ret)
12164 return ret;
12165 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012166
12167 return ret;
12168}
12169
Agrawal Ashish65634612016-08-18 13:24:32 +053012170/**
12171 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12172 * @mode : cfg80211 DFS mode
12173 *
12174 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12175 */
12176enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12177{
12178 switch (mode) {
12179 case DFS_MODE_ENABLE:
12180 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012181 case DFS_MODE_DISABLE:
12182 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012183 case DFS_MODE_DEPRIORITIZE:
12184 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012185 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012186 hdd_debug("ACS dfs mode is NONE");
12187 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012188 }
12189}
12190
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012191/**
12192 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12193 * @hddctx: pointer to hdd context
12194 * @set_value: enable/disable
12195 *
12196 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12197 * Host(even though it is duplicate). When Host send vendor command
12198 * disable,FW doesn't perform any action. Whenever any change in
12199 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12200 *
12201 * return - 0 on success, appropriate error values on failure.
12202 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012203int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012204{
12205 QDF_STATUS status;
12206
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012207 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012208 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012209
12210 if (!hddctx->config->goptimize_chan_avoid_event) {
12211 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12212 return -EINVAL;
12213 }
12214
12215 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12216 if (!QDF_IS_STATUS_SUCCESS(status)) {
12217 hdd_err("Failed to send chan avoid command to SME");
12218 return -EINVAL;
12219 }
12220 return 0;
12221}
Agrawal Ashish65634612016-08-18 13:24:32 +053012222
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012223/**
12224 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12225 * @value: value to set
12226 *
12227 * This function will set the passed value to roaming in progress flag.
12228 *
12229 * Return: None
12230 */
12231void hdd_set_roaming_in_progress(bool value)
12232{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012233 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012234
12235 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12236 if (!hdd_ctx) {
12237 hdd_err("HDD context is NULL");
12238 return;
12239 }
12240
12241 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012242 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012243}
12244
12245/**
12246 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012247 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012248 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012249 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012250 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012251bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012252{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012253 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012254 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012255
12256 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12257 if (!hdd_ctx) {
12258 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012259 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012260 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012261 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12262 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012263 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12264 hdd_ctx->roaming_in_progress);
12265
12266 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012267}
12268
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012269/**
12270 * hdd_is_connection_in_progress() - check if connection is in
12271 * progress
12272 * @session_id: session id
12273 * @reason: scan reject reason
12274 *
12275 * Go through each adapter and check if Connection is in progress
12276 *
12277 * Return: true if connection is in progress else false
12278 */
12279bool hdd_is_connection_in_progress(uint8_t *session_id,
12280 enum scan_reject_states *reason)
12281{
12282 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012283 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012284 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012285 QDF_STATUS status = 0;
12286 uint8_t sta_id = 0;
12287 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012288 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012289
12290 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12291 if (!hdd_ctx) {
12292 hdd_err("HDD context is NULL");
12293 return false;
12294 }
12295
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012296 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12297 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012298 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012299 if (!adapter)
12300 goto end;
12301
12302 hdd_info("Adapter with device mode %s(%d) exists",
12303 hdd_device_mode_to_string(adapter->device_mode),
12304 adapter->device_mode);
12305 if (((QDF_STA_MODE == adapter->device_mode)
12306 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12307 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12308 && (eConnectionState_Connecting ==
12309 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12310 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012311 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012312 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12313 adapter->sessionId);
12314 if (session_id && reason) {
12315 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012316 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012317 }
12318 return true;
12319 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012320 /*
12321 * sme_neighbor_middle_of_roaming is for LFR2
12322 * hdd_is_roaming_in_progress is for LFR3
12323 */
12324 if (((QDF_STA_MODE == adapter->device_mode) &&
12325 sme_neighbor_middle_of_roaming(
12326 WLAN_HDD_GET_HAL_CTX(adapter),
12327 adapter->sessionId)) ||
12328 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012329 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012330 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12331 adapter->sessionId);
12332 if (session_id && reason) {
12333 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012334 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012335 }
12336 return true;
12337 }
12338 if ((QDF_STA_MODE == adapter->device_mode) ||
12339 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12340 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12341 hdd_sta_ctx =
12342 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12343 if ((eConnectionState_Associated ==
12344 hdd_sta_ctx->conn_info.connState)
12345 && (false ==
12346 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12347 sta_mac = (uint8_t *)
12348 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012349 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012350 " is in middle of WPS/EAPOL exchange.",
12351 MAC_ADDR_ARRAY(sta_mac));
12352 if (session_id && reason) {
12353 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012354 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012355 }
12356 return true;
12357 }
12358 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12359 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12360 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12361 sta_id++) {
12362 if (!((adapter->aStaInfo[sta_id].isUsed)
12363 && (OL_TXRX_PEER_STATE_CONN ==
12364 adapter->aStaInfo[sta_id].tlSTAState)))
12365 continue;
12366
12367 sta_mac = (uint8_t *)
12368 &(adapter->aStaInfo[sta_id].
12369 macAddrSTA.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012370 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012371 " of SAP/GO is in middle of WPS/EAPOL exchange",
12372 MAC_ADDR_ARRAY(sta_mac));
12373 if (session_id && reason) {
12374 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012375 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012376 }
12377 return true;
12378 }
12379 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012380 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012381 return true;
12382 }
12383 }
12384end:
12385 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12386 adapter_node = next;
12387 }
12388 return false;
12389}
12390
12391/**
12392 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012393 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012394 *
12395 * Return: None
12396 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012397void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012398{
Jeff Johnson87251032017-08-29 13:31:11 -070012399 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012400 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012401 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012402 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012403 tsap_Config_t *sap_config;
12404 void *sap_ctx;
12405
12406 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12407 sap_config = &hdd_ap_ctx->sapConfig;
12408 sap_ctx = hdd_ap_ctx->sapContext;
12409
12410 mutex_lock(&hdd_ctx->sap_lock);
12411 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12412 wlan_hdd_del_station(ap_adapter);
12413 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12414 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12415 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12416 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12417 qdf_status =
12418 qdf_wait_single_event(&hostapd_state->
12419 qdf_stop_bss_event,
12420 SME_CMD_TIMEOUT_VALUE);
12421
12422 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012423 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012424 goto end;
12425 }
12426 }
12427 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012428 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012429 ap_adapter->device_mode, ap_adapter->sessionId);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012430 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012431
12432 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012433 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012434 wlansap_reset_sap_config_add_ie(sap_config,
12435 eUPDATE_IE_ALL);
12436 goto end;
12437 }
12438
12439 qdf_event_reset(&hostapd_state->qdf_event);
12440 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12441 sap_config,
12442 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012443 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012444 wlansap_reset_sap_config_add_ie(sap_config,
12445 eUPDATE_IE_ALL);
12446 goto end;
12447 }
12448
Jeff Johnson6867ec32017-09-29 20:30:20 -070012449 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012450 qdf_status =
12451 qdf_wait_single_event(&hostapd_state->qdf_event,
12452 SME_CMD_TIMEOUT_VALUE);
12453 wlansap_reset_sap_config_add_ie(sap_config,
12454 eUPDATE_IE_ALL);
12455 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012456 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012457 goto end;
12458 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012459 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012460 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12461 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012462 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12463 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012464 ap_adapter->sessionId);
12465 hostapd_state->bCommit = true;
12466 }
12467end:
12468 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012469}
12470
12471/**
12472 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12473 * with non dfs acs
12474 *
12475 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12476 *
12477 * Return: None
12478 */
12479void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12480{
Jeff Johnson9d295242017-08-29 14:39:48 -070012481 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012482 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012483 cds_context_type *cds_ctx;
12484
12485 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12486 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012487 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012488 return;
12489 }
12490
12491 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12492 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012493 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012494 return;
12495 }
12496
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012497 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12498 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012499 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012500 return;
12501 }
12502
12503 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012504 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12505 &ap_adapter->event_flags) &&
12506 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12507 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012508
Jeff Johnson6867ec32017-09-29 20:30:20 -070012509 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012510 ap_adapter->sessionCtx.ap.sapConfig.channel =
12511 AUTO_CHANNEL_SELECT;
12512 ap_adapter->sessionCtx.ap.sapConfig.
12513 acs_cfg.acs_mode = true;
12514
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012515 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012516 }
12517}
12518
12519/**
12520 * hdd_set_connection_in_progress() - to set the connection in
12521 * progress flag
12522 * @value: value to set
12523 *
12524 * This function will set the passed value to connection in progress flag.
12525 * If value is previously being set to true then no need to set it again.
12526 *
12527 * Return: true if value is being set correctly and false otherwise.
12528 */
12529bool hdd_set_connection_in_progress(bool value)
12530{
12531 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012532 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012533
12534 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12535 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012536 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012537 return false;
12538 }
12539
12540 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12541 /*
12542 * if the value is set to true previously and if someone is
12543 * trying to make it true again then it could be some race
12544 * condition being triggered. Avoid this situation by returning
12545 * false
12546 */
12547 if (hdd_ctx->connection_in_progress && value)
12548 status = false;
12549 else
12550 hdd_ctx->connection_in_progress = value;
12551 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12552 return status;
12553}
12554
Jeff Johnson9d295242017-08-29 14:39:48 -070012555int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012556{
12557 if (!adapter) {
12558 hdd_err("Invalid adapter");
12559 return -EINVAL;
12560 }
12561 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012562 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012563 WMA_VDEV_MCC_SET_TIME_QUOTA,
12564 set_value, VDEV_CMD);
12565 return 0;
12566
12567}
12568
Jeff Johnson9d295242017-08-29 14:39:48 -070012569int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012570{
12571 if (!adapter) {
12572 hdd_err("Invalid adapter");
12573 return -EINVAL;
12574 }
12575
12576 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012577 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012578 WMA_VDEV_MCC_SET_TIME_LATENCY,
12579 set_value, VDEV_CMD);
12580 return 0;
12581}
12582
Jeff Johnson9d295242017-08-29 14:39:48 -070012583struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012584 *psoc, uint8_t vdev_id)
12585{
Jeff Johnson9d295242017-08-29 14:39:48 -070012586 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012587 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012588
12589 /*
12590 * Currently PSOC is not being used. But this logic will
12591 * change once we have the converged implementation of
12592 * HDD context per PSOC in place. This would break if
12593 * multiple vdev objects reuse the vdev id.
12594 */
12595 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12596 if (!adapter)
12597 hdd_err("Get adapter by vdev id failed");
12598
12599 return adapter;
12600}
12601
Jeff Johnson9d295242017-08-29 14:39:48 -070012602int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012603 int8_t *rssi, int8_t *snr)
12604{
12605 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012606 struct hdd_wext_state *wext_state =
12607 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012608 tCsrRoamProfile *profile = &wext_state->roamProfile;
12609
12610 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12611 profile, bssid, rssi, snr);
12612 if (QDF_STATUS_SUCCESS != status) {
12613 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12614 return -EINVAL;
12615 }
12616
12617 return 0;
12618}
12619
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012620/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012621 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12622 * @adapter - HDD adapter
12623 * @tos - type of service
12624 * @status - status of the traffic
12625 *
12626 * Return: 0 on success and non zero value on failure
12627 */
12628
12629int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12630 bool is_tos_active)
12631{
12632 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012633 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012634 uint32_t max_off_chan_time = 0;
12635 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012636 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012637 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012638
12639 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12640 ret = wlan_hdd_validate_context(hdd_ctx);
12641
12642 if (ret < 0) {
12643 hdd_err("failed to set limit off chan params");
12644 return ret;
12645 }
12646
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012647 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12648
12649 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012650 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012651 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012652 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012653
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012654 if (adapter->active_ac) {
12655 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012656 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012657 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12658 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12659 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012660 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012661 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012662 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12663 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12664 PM_LATENCY);
12665 } else {
12666 /*ignore this command if only BE/BK is active */
12667 is_tos_active = false;
12668 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12669 hdd_ctx->config->conc_system_pref);
12670 }
12671 } else {
12672 /* No active tos */
12673 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12674 hdd_ctx->config->conc_system_pref);
12675 }
12676
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012677 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12678 is_tos_active, max_off_chan_time,
12679 hdd_ctx->config->nRestTimeConc, true);
12680 if (!QDF_IS_STATUS_SUCCESS(status)) {
12681 hdd_err("failed to set limit off chan params");
12682 ret = -EINVAL;
12683 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012684
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012685 return ret;
12686}
12687
12688/**
12689 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
12690 * @adapter - HDD adapter
12691 *
12692 * Return: 0 on success and non zero value on failure
12693 */
12694int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
12695{
12696 struct hdd_context *hdd_ctx;
12697 int ret;
12698 QDF_STATUS status;
12699 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
12700
12701 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12702 ret = wlan_hdd_validate_context(hdd_ctx);
12703 if (ret < 0)
12704 return ret;
12705
12706 /* set the system preferece to default */
12707 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12708 hdd_ctx->config->conc_system_pref);
12709
12710 /* clear the bitmap */
12711 adapter->active_ac = 0;
12712
12713 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
12714 adapter->sessionId, adapter->active_ac);
12715
12716 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12717 false, 0, 0, false);
12718 if (!QDF_IS_STATUS_SUCCESS(status)) {
12719 hdd_err("failed to reset limit off chan params");
12720 ret = -EINVAL;
12721 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012722
12723 return ret;
12724}
12725
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012726/**
12727 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12728 * @drv_op: Enum indicating driver op
12729 *
12730 * Return: none
12731 */
12732void hdd_start_driver_ops_timer(int drv_op)
12733{
12734 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12735 switch (drv_op) {
12736 case eHDD_DRV_OP_PROBE:
12737 memcpy(drv_ops_string, "probe", sizeof("probe"));
12738 break;
12739 case eHDD_DRV_OP_REMOVE:
12740 memcpy(drv_ops_string, "remove", sizeof("remove"));
12741 break;
12742 case eHDD_DRV_OP_SHUTDOWN:
12743 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12744 break;
12745 case eHDD_DRV_OP_REINIT:
12746 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12747 break;
12748 }
12749
12750 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12751 HDD_OPS_INACTIVITY_TIMEOUT);
12752}
12753
12754/**
12755 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12756 *
12757 * Return: none
12758 */
12759void hdd_stop_driver_ops_timer(void)
12760{
12761 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12762}
12763
12764/**
12765 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12766 * inactivity timer
12767 *
12768 * Return: None
12769 */
12770void hdd_drv_ops_inactivity_handler(void)
12771{
12772 hdd_err("%s: %d Sec timer expired while in .%s",
12773 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12774
12775 /* Driver shutdown is stuck, no recovery possible at this point */
12776 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12777 sizeof("shutdown")))
12778 QDF_BUG(0);
12779
12780 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012781 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012782 else
12783 QDF_BUG(0);
12784}
12785
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012786void hdd_pld_ipa_uc_shutdown_pipes(void)
12787{
12788 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12789
12790 if (!hdd_ctx)
12791 return;
12792
12793 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12794}
12795
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012796/* Register the module init/exit functions */
12797module_init(hdd_module_init);
12798module_exit(hdd_module_exit);
12799
12800MODULE_LICENSE("Dual BSD/GPL");
12801MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12802MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12803
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012804module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12805 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012806
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012807module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12808 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12809
Ravi Joshia307f632017-07-17 23:41:41 -070012810module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12811 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012813module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12814 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12815
12816module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12817
12818module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12819
12820module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);