blob: 7119583f108fd9f461ccd072cf4239b462981442 [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"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700127#include <cdp_txrx_cmn_struct.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800128
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530129#ifdef CNSS_GENL
130#include <net/cnss_nl.h>
131#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800132#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800134#ifdef MODULE
135#define WLAN_MODULE_NAME module_name(THIS_MODULE)
136#else
137#define WLAN_MODULE_NAME "wlan"
138#endif
139
140#ifdef TIMER_MANAGER
141#define TIMER_MANAGER_STR " +TIMER_MANAGER"
142#else
143#define TIMER_MANAGER_STR ""
144#endif
145
146#ifdef MEMORY_DEBUG
147#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
148#else
149#define MEMORY_DEBUG_STR ""
150#endif
151
Sachin Ahujadddd2632017-03-07 19:07:24 +0530152int wlan_start_ret_val;
153static DECLARE_COMPLETION(wlan_start_comp);
154static unsigned int dev_num = 1;
155static struct cdev wlan_hdd_state_cdev;
156static struct class *class;
157static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530158#ifndef MODULE
159static struct gwlan_loader *wlan_loader;
160static ssize_t wlan_boot_cb(struct kobject *kobj,
161 struct kobj_attribute *attr,
162 const char *buf, size_t count);
163struct gwlan_loader {
164 bool loaded_state;
165 struct kobject *boot_wlan_obj;
166 struct attribute_group *attr_group;
167};
168
169static struct kobj_attribute wlan_boot_attribute =
170 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
171
172static struct attribute *attrs[] = {
173 &wlan_boot_attribute.attr,
174 NULL,
175};
176
177#define MODULE_INITIALIZED 1
178#endif
179
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530180#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
181#define MAX_OPS_NAME_STRING_SIZE 20
182
183static qdf_timer_t hdd_drv_ops_inactivity_timer;
184static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
185
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800186/* the Android framework expects this param even though we don't use it */
187#define BUF_LEN 20
188static char fwpath_buffer[BUF_LEN];
189static struct kparam_string fwpath = {
190 .string = fwpath_buffer,
191 .maxlen = BUF_LEN,
192};
193
194static char *country_code;
195static int enable_11d = -1;
196static int enable_dfs_chan_scan = -1;
197
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800198/*
199 * spinlock for synchronizing asynchronous request/response
200 * (full description of use in wlan_hdd_main.h)
201 */
202DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530203DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800204
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800205#define WLAN_NLINK_CESIUM 30
206
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530207static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800208
209#define WOW_MAX_FILTER_LISTS 1
210#define WOW_MAX_FILTERS_PER_LIST 4
211#define WOW_MIN_PATTERN_SIZE 6
212#define WOW_MAX_PATTERN_SIZE 64
213
214#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
215static const struct wiphy_wowlan_support wowlan_support_reg_init = {
216 .flags = WIPHY_WOWLAN_ANY |
217 WIPHY_WOWLAN_MAGIC_PKT |
218 WIPHY_WOWLAN_DISCONNECT |
219 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
220 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
221 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
222 WIPHY_WOWLAN_4WAY_HANDSHAKE |
223 WIPHY_WOWLAN_RFKILL_RELEASE,
224 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
225 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
226 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
227};
228#endif
229
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700230static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
231 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
232 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
233 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
234 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
235 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
236 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
237 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
243 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
244 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
245 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
246 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
247 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700265 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700266 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700267 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700268};
269
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530270int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
271 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
272 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
273 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
274 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
275};
276
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800277/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530278struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800279
280struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800281#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700282static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800283#endif
284
Sachin Ahujadddd2632017-03-07 19:07:24 +0530285void hdd_start_complete(int ret)
286{
287 wlan_start_ret_val = ret;
288
289 complete(&wlan_start_comp);
290}
291
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800292/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530293 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700294 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530295 *
296 * Return: none
297 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700298static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530299{
Jeff Johnson9d295242017-08-29 14:39:48 -0700300 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530301 hdd_adapter_list_node_t *adapter_node, *next;
302 QDF_STATUS status = QDF_STATUS_SUCCESS;
303
304 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
305 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -0700306 adapter = adapter_node->adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530307 if (NULL != adapter)
308 hdd_send_rps_ind(adapter);
309 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
310 adapter_node = next;
311 }
312}
313
314/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800315 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
316 * @vdev_id: vdev_id
317 * @action: action type
318 * @reason: reason type
319 *
320 * Return: none
321 */
322void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
323 enum netif_action_type action, enum netif_reason_type reason)
324{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700325 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700326 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800327
328 if (!hdd_ctx) {
329 hdd_err("hdd ctx is NULL");
330 return;
331 }
332 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
333
334 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800335}
336
337/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700338 * Store WLAN driver version and timestamp info in global variables such that
339 * crash debugger can extract them from driver debug symbol and crashdump for
340 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800341 */
342uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700343
344#ifndef BUILD_TIMESTAMP
345#define BUILD_TIMESTAMP ""
346#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700347uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800348
349/**
350 * hdd_device_mode_to_string() - return string conversion of device mode
351 * @device_mode: device mode
352 *
353 * This utility function helps log string conversion of device mode.
354 *
355 * Return: string conversion of device mode, if match found;
356 * "Unknown" otherwise.
357 */
358const char *hdd_device_mode_to_string(uint8_t device_mode)
359{
360 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800361 CASE_RETURN_STRING(QDF_STA_MODE);
362 CASE_RETURN_STRING(QDF_SAP_MODE);
363 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
364 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
365 CASE_RETURN_STRING(QDF_FTM_MODE);
366 CASE_RETURN_STRING(QDF_IBSS_MODE);
367 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
368 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700369 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800370 default:
371 return "Unknown";
372 }
373}
374
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530375/**
376 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
377 * @adapter: HDD adapter
378 * @chan_number: Channel number
379 * @chan_bw: Bandwidth
380 *
381 * Checks if the given bandwidth is valid for the given channel number.
382 *
383 * Return: 0 for success, non-zero for failure
384 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700385int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530386 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800387 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530388{
389 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
390 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
391 bool found = false;
392 tHalHandle hal;
393
394 hal = WLAN_HDD_GET_HAL_CTX(adapter);
395 if (!hal) {
396 hdd_err("Invalid HAL context");
397 return -EINVAL;
398 }
399
400 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
401 hdd_err("No valid channel list");
402 return -EOPNOTSUPP;
403 }
404
405 for (i = 0; i < len; i++) {
406 if (chan[i] == chan_number) {
407 found = true;
408 break;
409 }
410 }
411
412 if (found == false) {
413 hdd_err("Channel not in driver's valid channel list");
414 return -EOPNOTSUPP;
415 }
416
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700417 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
418 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530419 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
420 return -EINVAL;
421 }
422
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700423 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530424 if (chan_bw == CH_WIDTH_80MHZ) {
425 hdd_err("BW80 not possible in 2.4GHz band");
426 return -EINVAL;
427 }
428 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
429 (chan_bw != CH_WIDTH_MAX)) {
430 hdd_err("Only BW20 possible on channel 14");
431 return -EINVAL;
432 }
433 }
434
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700435 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530436 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
437 (chan_bw != CH_WIDTH_MAX)) {
438 hdd_err("Only BW20 possible on channel 165");
439 return -EINVAL;
440 }
441 }
442
443 return 0;
444}
445
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530446/**
447 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
448 *
449 * Block the unloading of the driver (or) interface up until the
450 * cds recovery is completed
451 *
452 * Return: true for recovery completion else false
453 */
454static bool hdd_wait_for_recovery_completion(void)
455{
456 int retry = 0;
457
458 /* Wait for recovery to complete */
459 while (cds_is_driver_recovering()) {
460 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
461 hdd_err("Recovery in progress; wait here!!!");
462 msleep(1000);
463 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
464 hdd_err("SSR never completed, error");
465 /*
466 * Trigger the bug_on in the internal builds, in the
467 * customer builds self-recovery will be enabled
468 * in those cases just return error.
469 */
470 if (cds_is_self_recovery_enabled())
471 return false;
472 QDF_BUG(0);
473 }
474 }
475
476 hdd_info("Recovery completed successfully!");
477 return true;
478}
479
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800480static int __hdd_netdev_notifier_call(struct notifier_block *nb,
481 unsigned long state, void *data)
482{
483#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
484 struct netdev_notifier_info *dev_notif_info = data;
485 struct net_device *dev = dev_notif_info->dev;
486#else
487 struct net_device *dev = data;
488#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700489 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700490 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800492 ENTER_DEV(dev);
493
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800494 /* Make sure that this callback corresponds to our device. */
495 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
496 return NOTIFY_DONE;
497
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530498 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800499 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700500 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800501 return NOTIFY_DONE;
502 }
503
504 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700505 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800506 return NOTIFY_DONE;
507 }
508
509 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
510 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800511 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530512 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800513 return NOTIFY_DONE;
514 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800515
516 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
517 hdd_err("%s: Driver module is closed", __func__);
518 return NOTIFY_DONE;
519 }
520
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530521 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800522 return NOTIFY_DONE;
523
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800524 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800525 dev->name, state);
526
527 switch (state) {
528 case NETDEV_REGISTER:
529 break;
530
531 case NETDEV_UNREGISTER:
532 break;
533
534 case NETDEV_UP:
535 sme_ch_avoid_update_req(hdd_ctx->hHal);
536 break;
537
538 case NETDEV_DOWN:
539 break;
540
541 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700542 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800543 complete(&adapter->linkup_event_var);
544 break;
545
546 case NETDEV_GOING_DOWN:
547 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530548 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
549 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800550 } else {
hqueaa33ee2017-05-04 17:56:35 +0800551 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800552 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800553 }
554 break;
555
556 default:
557 break;
558 }
559
560 return NOTIFY_DONE;
561}
562
563/**
564 * hdd_netdev_notifier_call() - netdev notifier callback function
565 * @nb: pointer to notifier block
566 * @state: state
567 * @ndev: ndev pointer
568 *
569 * Return: 0 on success, error number otherwise.
570 */
571static int hdd_netdev_notifier_call(struct notifier_block *nb,
572 unsigned long state,
573 void *ndev)
574{
575 int ret;
576
577 cds_ssr_protect(__func__);
578 ret = __hdd_netdev_notifier_call(nb, state, ndev);
579 cds_ssr_unprotect(__func__);
580
581 return ret;
582}
583
584struct notifier_block hdd_netdev_notifier = {
585 .notifier_call = hdd_netdev_notifier_call,
586};
587
588/* variable to hold the insmod parameters */
589static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800590
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530591static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700592int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530593
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800594/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800595static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800596
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530597/**
598 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
599 * @ch_width: NL channel width
600 *
601 * Converts the NL channel width to the driver's internal representation
602 *
603 * Return: Converted channel width. In case of non matching NL channel width,
604 * CH_WIDTH_MAX will be returned.
605 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800606enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530607{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800608 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700609
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800610 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530611 switch (ch_width) {
612 case NL80211_CHAN_WIDTH_20_NOHT:
613 case NL80211_CHAN_WIDTH_20:
614 return CH_WIDTH_20MHZ;
615 case NL80211_CHAN_WIDTH_40:
616 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530617 case NL80211_CHAN_WIDTH_80:
618 return CH_WIDTH_80MHZ;
619 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800620 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
621 return CH_WIDTH_80P80MHZ;
622 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
623 return CH_WIDTH_160MHZ;
624 else
625 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530626 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800627 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
628 return CH_WIDTH_160MHZ;
629 else
630 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530631 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800632 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530633 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800634 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530635 default:
636 hdd_err("Invalid channel width %d, setting to default",
637 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800638 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530639 }
640}
641
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530642/* wlan_hdd_find_opclass() - Find operating class for a channel
643 * @hal: handler to HAL
644 * @channel: channel id
645 * @bw_offset: bandwidth offset
646 *
647 * Function invokes sme api to find the operating class
648 *
649 * Return: operating class
650 */
651uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
652 uint8_t bw_offset)
653{
654 uint8_t opclass = 0;
655
656 sme_get_opclass(hal, channel, bw_offset, &opclass);
657 return opclass;
658}
659
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800660/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530661 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530662 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800663 * @bitmask: Bitmask of log levels to be enabled
664 *
665 * Called immediately after the cfg.ini is read in order to configure
666 * the desired trace levels.
667 *
668 * Return: None
669 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530670int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800671{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530672 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530673 int qdf_print_idx = -1;
674 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800675 /*
676 * if the bitmask is the default value, then a bitmask was not
677 * specified in cfg.ini, so leave the logging level alone (it
678 * will remain at the "compiled in" default value)
679 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700680 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530681 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800682
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530683 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800684
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530685 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530686 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530687 QDF_TRACE_LEVEL_NONE, 0);
688
689 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530690 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530692 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693 while (0 != bitmask) {
694 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530695 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530696 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530697 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530698 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800699 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700700
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800701 level++;
702 bitmask >>= 1;
703 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530704 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800705}
706
707/**
Chris Guo1751acf2017-07-03 14:09:01 +0800708 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
709 * @hdd_ctx: HDD context pointer
710 *
711 * Return: 0 if the context is valid. Error code otherwise
712 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700713int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800714{
715 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
716 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
717 return -ENODEV;
718 }
719
720 if (cds_is_driver_recovering()) {
721 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
722 (void *)_RET_IP_, cds_get_driver_state());
723 return -EAGAIN;
724 }
725
726 if (hdd_ctx->start_modules_in_progress ||
727 hdd_ctx->stop_modules_in_progress) {
728 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
729 (void *)_RET_IP_);
730 return -EAGAIN;
731 }
732
733 return 0;
734}
735
736
737/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 * wlan_hdd_validate_context() - check the HDD context
739 * @hdd_ctx: HDD context pointer
740 *
741 * Return: 0 if the context is valid. Error code otherwise
742 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700743int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800744{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530746 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747 return -ENODEV;
748 }
749
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800750 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800751 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530752 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800753 return -EAGAIN;
754 }
755
Yue Ma9f275d92017-09-14 16:58:41 -0700756 if (cds_is_load_or_unload_in_progress()) {
757 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
758 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700760 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530761
762 if (hdd_ctx->start_modules_in_progress ||
763 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800764 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530765 (void *)_RET_IP_);
766 return -EAGAIN;
767 }
768
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530769 if (cds_is_driver_in_bad_state()) {
770 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
771 (void *)_RET_IP_, cds_get_driver_state());
772 return -ENODEV;
773 }
774
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 return 0;
776}
777
Jeff Johnson9d295242017-08-29 14:39:48 -0700778int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700779{
780 if (!adapter) {
781 hdd_err("adapter is null");
782 return -EINVAL;
783 }
784
785 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
786 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
787 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
788 return -EINVAL;
789 }
790
791 if (!adapter->dev) {
792 hdd_err("adapter net_device is null");
793 return -EINVAL;
794 }
795
796 if (!(adapter->dev->flags & IFF_UP)) {
797 hdd_info("adapter net_device is not up");
798 return -EAGAIN;
799 }
800
Krunal Soni4a020c72017-10-30 20:58:40 -0700801 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700802 hdd_info("adapter session is not open");
803 return -EAGAIN;
804 }
805
806 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
807 hdd_err("bad adapter session Id: %u", adapter->sessionId);
808 return -EINVAL;
809 }
810
811 return 0;
812}
813
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530815 * wlan_hdd_validate_modules_state() - Check modules status
816 * @hdd_ctx: HDD context pointer
817 *
818 * Check's the driver module's state and returns true if the
819 * modules are enabled returns false if modules are closed.
820 *
821 * Return: True if modules are enabled or false.
822 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700823bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530824{
825 mutex_lock(&hdd_ctx->iface_change_lock);
826 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
827 mutex_unlock(&hdd_ctx->iface_change_lock);
828 hdd_notice("Modules not enabled, Present status: %d",
829 hdd_ctx->driver_status);
830 return false;
831 }
832 mutex_unlock(&hdd_ctx->iface_change_lock);
833 return true;
834}
835
836/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700838 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800839 *
840 * This function sets the IBSS power save config parameters to WMA
841 * which will send it to firmware if FW supports IBSS power save
842 * before vdev start.
843 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530844 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 * on failure.
846 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700847QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800848{
849 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700850 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851
852 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700853 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530854 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800855 }
856
Naveen Rawat247a8682017-06-05 15:00:31 -0700857 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800858 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
859 hdd_ctx->config->ibssATIMWinSize,
860 VDEV_CMD);
861 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700862 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530863 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864 }
865
Naveen Rawat247a8682017-06-05 15:00:31 -0700866 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
868 hdd_ctx->config->isIbssPowerSaveAllowed,
869 VDEV_CMD);
870 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700871 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
872 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530873 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874 }
875
Naveen Rawat247a8682017-06-05 15:00:31 -0700876 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
878 hdd_ctx->config->
879 isIbssPowerCollapseAllowed, VDEV_CMD);
880 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700881 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
882 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530883 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800884 }
885
Naveen Rawat247a8682017-06-05 15:00:31 -0700886 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800887 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
888 hdd_ctx->config->isIbssAwakeOnTxRx,
889 VDEV_CMD);
890 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700891 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530892 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893 }
894
Naveen Rawat247a8682017-06-05 15:00:31 -0700895 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
897 hdd_ctx->config->ibssInactivityCount,
898 VDEV_CMD);
899 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700900 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530901 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800902 }
903
Naveen Rawat247a8682017-06-05 15:00:31 -0700904 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800905 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
906 hdd_ctx->config->ibssTxSpEndInactivityTime,
907 VDEV_CMD);
908 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700909 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
910 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530911 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 }
913
Naveen Rawat247a8682017-06-05 15:00:31 -0700914 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
916 hdd_ctx->config->ibssPsWarmupTime,
917 VDEV_CMD);
918 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700919 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
920 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530921 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800922 }
923
Naveen Rawat247a8682017-06-05 15:00:31 -0700924 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
926 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
927 VDEV_CMD);
928 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700929 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
930 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530931 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800932 }
933
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530934 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800935}
936
Yue Macd359b72017-10-03 15:21:00 -0700937#ifdef FEATURE_RUNTIME_PM
938/**
939 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
940 * @hdd_ctx: HDD context
941 *
942 * Return: None
943 */
944static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
945{
946 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
947
Yue Macd359b72017-10-03 15:21:00 -0700948 qdf_runtime_lock_init(&ctx->dfs);
949
950 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
951}
952
953/**
954 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
955 * @hdd_ctx: HDD Context
956 *
957 * Return: None
958 */
959static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
960{
961 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
962
Yue Macd359b72017-10-03 15:21:00 -0700963 qdf_runtime_lock_deinit(&ctx->dfs);
964
965 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
966}
967
968static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
969{
970 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
971
972 qdf_runtime_lock_init(&ctx->connect);
973}
974
975static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
976{
977 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
978
979 qdf_runtime_lock_deinit(&ctx->connect);
980}
981#else /* FEATURE_RUNTIME_PM */
982static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
983static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
984static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
985static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
986#endif /* FEATURE_RUNTIME_PM */
987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988#define INTF_MACADDR_MASK 0x7
989
990/**
991 * hdd_update_macaddr() - update mac address
992 * @config: hdd configuration
993 * @hw_macaddr: mac address
994 *
995 * Mac address for multiple virtual interface is found as following
996 * i) The mac address of the first interface is just the actual hw mac address.
997 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
998 * define the mac address for the remaining interfaces and locally
999 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1000 * supported virtual interfaces, right now this is 0x07 (meaning 8
1001 * interface).
1002 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1003 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1004 *
1005 * Return: None
1006 */
1007void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301008 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009{
1010 int8_t i;
1011 uint8_t macaddr_b3, tmp_br3;
1012
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301013 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301014 QDF_MAC_ADDR_SIZE);
1015 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301016 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301017 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1019 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1020 INTF_MACADDR_MASK;
1021 macaddr_b3 += tmp_br3;
1022
1023 /* XOR-ing bit-24 of the mac address. This will give enough
1024 * mac address range before collision
1025 */
1026 macaddr_b3 ^= (1 << 7);
1027
1028 /* Set locally administered bit */
1029 config->intfMacAddr[i].bytes[0] |= 0x02;
1030 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001031 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001032 MAC_ADDRESS_STR, i,
1033 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1034 }
1035}
1036
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001037static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 struct wma_tgt_services *cfg)
1039{
1040 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001041
1042 /* Set up UAPSD */
1043 config->apUapsdEnabled &= cfg->uapsd;
1044
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001045 /* 11AX mode support */
1046 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1047 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1048 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1049
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050 /* 11AC mode support */
1051 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1052 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1053 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054
1055 /* ARP offload: override user setting if invalid */
1056 config->fhostArpOffload &= cfg->arp_offload;
1057
1058#ifdef FEATURE_WLAN_SCAN_PNO
1059 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001060 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061 if (cfg->pno_offload)
1062 config->PnoOffload = true;
1063#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064#ifdef FEATURE_WLAN_TDLS
1065 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301066 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1067 cfg->en_tdls_offchan;
1068 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1069 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001070 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001071 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001072 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001075#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1076 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1077#endif
Will Huang496b36c2017-07-11 16:38:50 +08001078 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001079 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001080 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001081
1082}
1083
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001084/**
1085 * hdd_update_vdev_nss() - sets the vdev nss
1086 * @hdd_ctx: HDD context
1087 *
1088 * Sets the Nss per vdev type based on INI
1089 *
1090 * Return: None
1091 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001092static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001093{
1094 struct hdd_config *cfg_ini = hdd_ctx->config;
1095 uint8_t max_supp_nss = 1;
1096
Naveen Rawat10b1c152017-01-18 11:16:06 -08001097 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001098 max_supp_nss = 2;
1099
1100 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1101 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1102
1103 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1104 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1105}
1106
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301107/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301108 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1109 * @hdd_ctx: HDD context
1110 *
1111 * Updates wiphy vhtcap fields
1112 *
1113 * Return: None
1114 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001115static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301116{
1117 struct ieee80211_supported_band *band_5g =
1118 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1119 uint32_t val;
1120
1121 if (!band_5g) {
1122 hdd_debug("5GHz band disabled, skipping capability population");
1123 return;
1124 }
1125
1126 val = hdd_ctx->config->txBFCsnValue;
1127 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1128
1129 val = NUM_OF_SOUNDING_DIMENSIONS;
1130 band_5g->vht_cap.cap |=
1131 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1132
1133 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1134 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1135}
1136
1137/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301138 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1139 * @hdd_ctx: HDD context
1140 *
1141 * Sets the DBS capability as per INI and firmware capability
1142 *
1143 * Return: None
1144 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001145static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301146{
1147 struct hdd_config *cfg_ini = hdd_ctx->config;
1148 uint8_t hw_dbs_capable = 0;
1149
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001150 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1151 ((cfg_ini->dual_mac_feature_disable ==
1152 ENABLE_DBS_CXN_AND_SCAN) ||
1153 (cfg_ini->dual_mac_feature_disable ==
1154 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301155 hw_dbs_capable = 1;
1156
1157 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1158}
1159
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001160static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161 struct wma_tgt_ht_cap *cfg)
1162{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301163 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001164 uint32_t value, val32;
1165 uint16_t val16;
1166 struct hdd_config *pconfig = hdd_ctx->config;
1167 tSirMacHTCapabilityInfo *phtCapInfo;
1168 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1169 uint8_t enable_tx_stbc;
1170
1171 /* check and update RX STBC */
1172 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1173 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1174
1175 /* get the MPDU density */
1176 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1177
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301178 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001179 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001180 value = 0;
1181 }
1182
1183 /*
1184 * MPDU density:
1185 * override user's setting if value is larger
1186 * than the one supported by target
1187 */
1188 if (value > cfg->mpdu_density) {
1189 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1190 cfg->mpdu_density);
1191
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301192 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001193 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001194 }
1195
1196 /* get the HT capability info */
1197 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301198 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001199 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001200 return;
1201 }
1202 val16 = (uint16_t) val32;
1203 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1204
1205 /* Set the LDPC capability */
1206 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1207
1208 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1209 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1210
1211 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1212 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1213
1214 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1215 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1216
1217 enable_tx_stbc = pconfig->enableTxSTBC;
1218
1219 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1220 pconfig->enable2x2 = 1;
1221 } else {
1222 pconfig->enable2x2 = 0;
1223 enable_tx_stbc = 0;
1224
1225 /* 1x1 */
1226 /* Update Rx Highest Long GI data Rate */
1227 if (sme_cfg_set_int(hdd_ctx->hHal,
1228 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001229 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301230 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001231 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001232 }
1233
1234 /* Update Tx Highest Long GI data Rate */
1235 if (sme_cfg_set_int
1236 (hdd_ctx->hHal,
1237 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001238 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301239 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001240 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241 }
1242 }
1243 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1244 enable_tx_stbc = 0;
1245 phtCapInfo->txSTBC = enable_tx_stbc;
1246
1247 val32 = val16;
1248 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301249 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001250 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1252 value = SIZE_OF_SUPPORTED_MCS_SET;
1253 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301254 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001255 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001256
1257 if (pconfig->enable2x2) {
1258 for (value = 0; value < cfg->num_rf_chains; value++)
1259 mcs_set[value] =
1260 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1261
1262 status =
1263 sme_cfg_set_str(hdd_ctx->hHal,
1264 WNI_CFG_SUPPORTED_MCS_SET,
1265 mcs_set,
1266 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301267 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001268 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269 }
1270 }
1271#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1272}
1273
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001274static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001275 struct wma_tgt_vht_cap *cfg)
1276{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301277 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001278 uint32_t value = 0;
1279 struct hdd_config *pconfig = hdd_ctx->config;
1280 struct wiphy *wiphy = hdd_ctx->wiphy;
1281 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001282 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001283 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001284 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001285 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001286
Dustin Brown5e06bd32016-10-04 12:49:10 -07001287 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001288 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001289 return;
1290 }
1291
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001292 /* Get the current MPDU length */
1293 status =
1294 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1295 &value);
1296
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301297 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001298 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299 value = 0;
1300 }
1301
1302 /*
1303 * VHT max MPDU length:
1304 * override if user configured value is too high
1305 * that the target cannot support
1306 */
1307 if (value > cfg->vht_max_mpdu) {
1308 status = sme_cfg_set_int(hdd_ctx->hHal,
1309 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1310 cfg->vht_max_mpdu);
1311
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001312 if (status == QDF_STATUS_E_FAILURE)
1313 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001314 }
1315
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001316 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1317 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1318
1319 if (pconfig->enable2x2)
1320 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1321
1322 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1323 QDF_STATUS_E_FAILURE) {
1324 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1325 }
1326
1327 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1328 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1329 if (pconfig->enable2x2)
1330 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1331
1332 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1333 QDF_STATUS_E_FAILURE) {
1334 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1335 }
1336
1337 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1338 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1339 if (pconfig->enable2x2)
1340 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1341
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001342 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001343 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1344
1345 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1346 QDF_STATUS_E_FAILURE) {
1347 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1348 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001349 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001350 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 &value);
1352
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301353 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001354 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001355 value = 0;
1356 }
1357
jiad4a7a33c2017-08-08 15:32:24 +08001358 /* Set HW RX LDPC capability */
1359 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1360 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 status = sme_cfg_set_int(hdd_ctx->hHal,
1362 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001363 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001365 if (status == QDF_STATUS_E_FAILURE)
1366 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001367 }
1368
1369 /* Get current GI 80 value */
1370 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1371 &value);
1372
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301373 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001374 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001375 value = 0;
1376 }
1377
1378 /* set the Guard interval 80MHz */
1379 if (value && !cfg->vht_short_gi_80) {
1380 status = sme_cfg_set_int(hdd_ctx->hHal,
1381 WNI_CFG_VHT_SHORT_GI_80MHZ,
1382 cfg->vht_short_gi_80);
1383
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001384 if (status == QDF_STATUS_E_FAILURE)
1385 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386 }
1387
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001388 /* Get VHT TX STBC cap */
1389 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1390
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301391 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001392 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001393 value = 0;
1394 }
1395
1396 /* VHT TX STBC cap */
1397 if (value && !cfg->vht_tx_stbc) {
1398 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1399 cfg->vht_tx_stbc);
1400
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001401 if (status == QDF_STATUS_E_FAILURE)
1402 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 }
1404
1405 /* Get VHT RX STBC cap */
1406 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1407
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301408 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001409 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001410 value = 0;
1411 }
1412
1413 /* VHT RX STBC cap */
1414 if (value && !cfg->vht_rx_stbc) {
1415 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1416 cfg->vht_rx_stbc);
1417
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001418 if (status == QDF_STATUS_E_FAILURE)
1419 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420 }
1421
1422 /* Get VHT SU Beamformer cap */
1423 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1424 &value);
1425
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301426 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001427 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 value = 0;
1429 }
1430
1431 /* set VHT SU Beamformer cap */
1432 if (value && !cfg->vht_su_bformer) {
1433 status = sme_cfg_set_int(hdd_ctx->hHal,
1434 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1435 cfg->vht_su_bformer);
1436
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001437 if (status == QDF_STATUS_E_FAILURE)
1438 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001439 }
1440
1441 /* check and update SU BEAMFORMEE capabality */
1442 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1443 pconfig->enableTxBF = cfg->vht_su_bformee;
1444
1445 status = sme_cfg_set_int(hdd_ctx->hHal,
1446 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1447 pconfig->enableTxBF);
1448
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001449 if (status == QDF_STATUS_E_FAILURE)
1450 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451
1452 /* Get VHT MU Beamformer cap */
1453 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1454 &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 MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 value = 0;
1459 }
1460
1461 /* set VHT MU Beamformer cap */
1462 if (value && !cfg->vht_mu_bformer) {
1463 status = sme_cfg_set_int(hdd_ctx->hHal,
1464 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1465 cfg->vht_mu_bformer);
1466
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001467 if (status == QDF_STATUS_E_FAILURE)
1468 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001469 }
1470
1471 /* Get VHT MU Beamformee cap */
1472 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1473 &value);
1474
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301475 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001476 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001477 value = 0;
1478 }
1479
1480 /* set VHT MU Beamformee cap */
1481 if (value && !cfg->vht_mu_bformee) {
1482 status = sme_cfg_set_int(hdd_ctx->hHal,
1483 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1484 cfg->vht_mu_bformee);
1485
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001486 if (status == QDF_STATUS_E_FAILURE)
1487 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001488 }
1489
1490 /* Get VHT MAX AMPDU Len exp */
1491 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1492 &value);
1493
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301494 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001495 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496 value = 0;
1497 }
1498
1499 /*
1500 * VHT max AMPDU len exp:
1501 * override if user configured value is too high
1502 * that the target cannot support.
1503 * Even though Rome publish ampdu_len=7, it can
1504 * only support 4 because of some h/w bug.
1505 */
1506
1507 if (value > cfg->vht_max_ampdu_len_exp) {
1508 status = sme_cfg_set_int(hdd_ctx->hHal,
1509 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1510 cfg->vht_max_ampdu_len_exp);
1511
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001512 if (status == QDF_STATUS_E_FAILURE)
1513 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514 }
1515
1516 /* Get VHT TXOP PS CAP */
1517 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1518
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301519 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001520 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001521 value = 0;
1522 }
1523
1524 /* set VHT TXOP PS cap */
1525 if (value && !cfg->vht_txop_ps) {
1526 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1527 cfg->vht_txop_ps);
1528
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001529 if (status == QDF_STATUS_E_FAILURE)
1530 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001531 }
1532
1533 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1534 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1535 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1536 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1537 else
1538 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1539
1540
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001541 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1542 status = sme_cfg_set_int(hdd_ctx->hHal,
1543 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1544 VHT_CAP_160_AND_80P80_SUPP);
1545 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001546 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001547 band_5g->vht_cap.cap |=
1548 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001549 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1550 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1551 status = sme_cfg_set_int(hdd_ctx->hHal,
1552 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1553 VHT_CAP_160_SUPP);
1554 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001555 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001556 band_5g->vht_cap.cap |=
1557 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001558 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1559 }
1560 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1561 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301562 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001563 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301564 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001565 &value);
1566 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301567 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001568 value = 0;
1569 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301570 /* set the Guard interval 160MHz */
1571 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001572 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301573 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1574 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001575
1576 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301577 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001578 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579
1580 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1581 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1582
1583 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1584 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1585 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1586 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1587
1588 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1589 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1590
1591 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1592 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1593 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1594 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1595 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1596 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1597
1598 band_5g->vht_cap.cap |=
1599 (cfg->vht_max_ampdu_len_exp <<
1600 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1601
1602 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1603 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1604 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1605 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1606 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1607 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1608 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1609 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1610
1611 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1612 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1613
1614}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001616/**
1617 * hdd_generate_macaddr_auto() - Auto-generate mac address
1618 * @hdd_ctx: Pointer to the HDD context
1619 *
1620 * Auto-generate mac address using device serial number.
1621 * Keep the first 3 bytes of OUI as before and replace
1622 * the last 3 bytes with the lower 3 bytes of serial number.
1623 *
1624 * Return: 0 for success
1625 * Non zero failure code for errors
1626 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001627static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001628{
1629 unsigned int serialno = 0;
1630 struct qdf_mac_addr mac_addr = {
1631 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1632 };
1633
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001634 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001635 if (serialno == 0)
1636 return -EINVAL;
1637
1638 serialno &= 0x00ffffff;
1639
1640 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1641 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1642 mac_addr.bytes[5] = serialno & 0xff;
1643
1644 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1645 return 0;
1646}
1647
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301648/**
1649 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1650 * configuration to cfg_ini in HDD
1651 * @hdd_ctx: Pointer to hdd_ctx
1652 * @cfg: target configuration
1653 *
1654 * Return: None
1655 */
1656#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001657static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301658 struct wma_tgt_cfg *cfg)
1659{
1660 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1661}
1662#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001663static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301664 struct wma_tgt_cfg *cfg)
1665{
1666}
1667#endif
1668
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001669void hdd_update_tgt_cfg(void *context, void *param)
1670{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001671 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001672 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001673 struct wma_tgt_cfg *cfg = param;
1674 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001675 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301676 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301677
Yue Mae3e86ab2017-05-08 10:48:24 -07001678 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301679 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1680 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1681 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1682 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1683 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001684 /* Restore pdev to MAC/WMA contexts */
1685 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001686 } else {
1687 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1688 if (ret) {
1689 hdd_err("pdev creation fails!");
1690 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301691 } else
1692 hdd_debug("New pdev has been created with pdev_id = %u",
1693 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301694 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001695
Naveen Rawat64e477e2016-05-20 10:34:56 -07001696 if (cds_cfg) {
1697 if (hdd_ctx->config->enable_sub_20_channel_width !=
1698 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1699 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1700 cds_cfg->sub_20_channel_width =
1701 WLAN_SUB_20_CH_WIDTH_NONE;
1702 } else {
1703 cds_cfg->sub_20_channel_width =
1704 hdd_ctx->config->enable_sub_20_channel_width;
1705 }
1706 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001707
1708 /* first store the INI band capability */
1709 temp_band_cap = hdd_ctx->config->nBandCapability;
1710
1711 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301712 hdd_ctx->is_fils_roaming_supported =
1713 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001715 /*
1716 * now overwrite the target band capability with INI
1717 * setting if INI setting is a subset
1718 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001719
1720 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1721 (temp_band_cap != eCSR_BAND_ALL))
1722 hdd_ctx->config->nBandCapability = temp_band_cap;
1723 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1724 (temp_band_cap != eCSR_BAND_ALL) &&
1725 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001726 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001727 }
1728
Amar Singhal58b45ef2017-08-01 13:43:54 -07001729 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1730
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301731 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1733 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1734 }
1735
1736 /* This can be extended to other configurations like ht, vht cap... */
1737
Anurag Chouhanc5548422016-02-24 18:33:27 +05301738 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001739 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001740 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001741 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001742 static struct qdf_mac_addr default_mac_addr = {
1743 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1744 };
1745 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1746 &default_mac_addr)) {
1747 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1748 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1749 MAC_ADDRESS_STR,
1750 MAC_ADDR_ARRAY(hdd_ctx->config->
1751 intfMacAddr[0].bytes));
1752 } else {
1753 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1754 MAC_ADDRESS_STR,
1755 MAC_ADDR_ARRAY(hdd_ctx->config->
1756 intfMacAddr[0].bytes));
1757 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001758 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001759 }
1760
1761 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001762 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001763
1764 hdd_ctx->max_intf_count = cfg->max_intf_count;
1765
Jeff Johnsonc875e242016-09-23 18:12:34 -07001766 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001767 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001768
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001769 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1770 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1771
1772 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1773
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001774 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001775 if (cfg->services.en_11ax) {
1776 hdd_info("11AX: 11ax is enabled - update HDD config");
1777 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1778 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001779
1780 hdd_update_vdev_nss(hdd_ctx);
1781
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301782 hdd_update_hw_dbs_capable(hdd_ctx);
1783
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001784 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001785 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001786 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001787 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001788
Nitesh Shahe50711f2017-04-26 16:30:45 +05301789 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1790 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1791 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001792 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001793 hdd_ctx->current_antenna_mode);
1794
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001795 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1796 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301797 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301798 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301799
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301800 if ((hdd_ctx->config->txBFCsnValue >
1801 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1802 !cfg->tx_bfee_8ss_enabled)
1803 hdd_ctx->config->txBFCsnValue =
1804 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1805
1806 if (sme_cfg_set_int(hdd_ctx->hHal,
1807 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1808 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1809 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1810
1811
1812 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1813 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1814 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301815
1816 /*
1817 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1818 */
1819 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301820
1821 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1822
Arun Khandavallid454d422016-08-17 12:47:05 +05301823 /*
1824 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1825 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1826 * configure the STA mode wow pattern.
1827 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301828 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301829 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301830
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301831 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1832
Yue Macd359b72017-10-03 15:21:00 -07001833 /*
1834 * This needs to be done after HDD pdev is created and stored since
1835 * it will access the HDD pdev object lock.
1836 */
1837 hdd_runtime_suspend_context_init(hdd_ctx);
1838
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001839 /* Configure NAN datapath features */
1840 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001841 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001842}
1843
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001844bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001845{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001846 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001847 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301848 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001849 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001850
Arif Hussaincd151632017-02-11 16:57:19 -08001851 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001852 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001853 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301854 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001855 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856
Arif Hussaincd151632017-02-11 16:57:19 -08001857 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1858 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001859 adapter = adapterNode->adapter;
Arif Hussaincd151632017-02-11 16:57:19 -08001860 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1861
1862 if ((QDF_SAP_MODE == adapter->device_mode ||
1863 QDF_P2P_GO_MODE == adapter->device_mode) &&
1864 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07001865 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08001866 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1867 true;
1868 hdd_info("tx blocked for session: %d",
1869 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301870 }
Arif Hussaincd151632017-02-11 16:57:19 -08001871 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1872 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001873 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301874
1875 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001876}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877
1878/**
1879 * hdd_is_valid_mac_address() - validate MAC address
1880 * @pMacAddr: Pointer to the input MAC address
1881 *
1882 * This function validates whether the given MAC address is valid or not
1883 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1884 * where X is the hexa decimal digit character and separated by ':'
1885 * This algorithm works even if MAC address is not separated by ':'
1886 *
1887 * This code checks given input string mac contains exactly 12 hexadecimal
1888 * digits and a separator colon : appears in the input string only after
1889 * an even number of hex digits.
1890 *
1891 * Return: 1 for valid and 0 for invalid
1892 */
1893bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1894{
1895 int xdigit = 0;
1896 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001897
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001898 while (*pMacAddr) {
1899 if (isxdigit(*pMacAddr)) {
1900 xdigit++;
1901 } else if (':' == *pMacAddr) {
1902 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1903 break;
1904
1905 ++separator;
1906 } else {
1907 /* Invalid MAC found */
1908 return 0;
1909 }
1910 ++pMacAddr;
1911 }
1912 return xdigit == 12 && (separator == 5 || separator == 0);
1913}
1914
1915/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301916 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1917 * @dev: Handle to struct net_device to be updated.
1918 *
1919 * Return: None
1920 */
1921static void hdd_mon_mode_ether_setup(struct net_device *dev)
1922{
1923 dev->header_ops = NULL;
1924 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1925 dev->hard_header_len = ETH_HLEN;
1926 dev->mtu = ETH_DATA_LEN;
1927 dev->addr_len = ETH_ALEN;
1928 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1929 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1930 dev->priv_flags |= IFF_TX_SKB_SHARING;
1931
1932 memset(dev->broadcast, 0xFF, ETH_ALEN);
1933}
1934
1935/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001936 * __hdd__mon_open() - HDD Open function
1937 * @dev: Pointer to net_device structure
1938 *
1939 * This is called in response to ifconfig up
1940 *
1941 * Return: 0 for success; non-zero for failure
1942 */
1943static int __hdd_mon_open(struct net_device *dev)
1944{
1945 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001946 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1947 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001948
1949 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001950
1951 ret = wlan_hdd_validate_context(hdd_ctx);
1952 if (ret)
1953 return ret;
1954
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301955 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001956
1957 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1958 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1959 if (ret) {
1960 hdd_err("Failed to start WLAN modules return");
1961 return ret;
1962 }
1963 hdd_err("hdd_wlan_start_modules() successful !");
1964
1965 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1966 ret = hdd_start_adapter(adapter);
1967 if (ret) {
1968 hdd_err("Failed to start adapter :%d",
1969 adapter->device_mode);
1970 return ret;
1971 }
1972 hdd_err("hdd_start_adapters() successful !");
1973 }
1974 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1975 }
1976
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001977 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001978
1979 if (!ret)
1980 ret = hdd_enable_monitor_mode(dev);
1981
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001982 return ret;
1983}
1984
1985/**
1986 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1987 * @dev: Pointer to net_device structure
1988 *
1989 * This is called in response to ifconfig up
1990 *
1991 * Return: 0 for success; non-zero for failure
1992 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001993static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001994{
1995 int ret;
1996
1997 cds_ssr_protect(__func__);
1998 ret = __hdd_mon_open(dev);
1999 cds_ssr_unprotect(__func__);
2000
2001 return ret;
2002}
2003
2004/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302005 * hdd_start_adapter() - Wrapper function for device specific adapter
2006 * @adapter: pointer to HDD adapter
2007 *
2008 * This function is called to start the device specific adapter for
2009 * the mode passed in the adapter's device_mode.
2010 *
2011 * Return: 0 for success; non-zero for failure
2012 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002013int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302014{
2015
2016 int ret;
2017 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
2018
2019 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002020 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302021
2022 switch (device_mode) {
2023 case QDF_P2P_CLIENT_MODE:
2024 case QDF_P2P_DEVICE_MODE:
2025 case QDF_OCB_MODE:
2026 case QDF_STA_MODE:
2027 case QDF_MONITOR_MODE:
2028 ret = hdd_start_station_adapter(adapter);
2029 if (ret)
2030 goto err_start_adapter;
2031 break;
2032 case QDF_P2P_GO_MODE:
2033 case QDF_SAP_MODE:
2034 ret = hdd_start_ap_adapter(adapter);
2035 if (ret)
2036 goto err_start_adapter;
2037 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302038 case QDF_IBSS_MODE:
2039 /*
2040 * For IBSS interface is initialized as part of
2041 * hdd_init_station_mode()
2042 */
2043 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302044 case QDF_FTM_MODE:
2045 ret = hdd_start_ftm_adapter(adapter);
2046 if (ret)
2047 goto err_start_adapter;
2048 break;
2049 default:
2050 hdd_err("Invalid session type %d", device_mode);
2051 QDF_ASSERT(0);
2052 goto err_start_adapter;
2053 }
2054 if (hdd_set_fw_params(adapter))
2055 hdd_err("Failed to set the FW params for the adapter!");
2056
2057 /*
2058 * Action frame registered in one adapter which will
2059 * applicable to all interfaces
2060 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302061 ret = wlan_hdd_cfg80211_register_frames(adapter);
2062 if (ret < 0) {
2063 hdd_err("Failed to register frames - ret %d", ret);
2064 goto err_start_adapter;
2065 }
2066
Arun Khandavallifae92942016-08-01 13:31:08 +05302067 EXIT();
2068 return 0;
2069err_start_adapter:
2070 return -EINVAL;
2071}
2072
2073/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302074 * hdd_enable_power_management() - API to Enable Power Management
2075 *
2076 * API invokes Bus Interface Layer power management functionality
2077 *
2078 * Return: None
2079 */
2080static void hdd_enable_power_management(void)
2081{
2082 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2083
2084 if (!hif_ctx) {
2085 hdd_err("Bus Interface Context is Invalid");
2086 return;
2087 }
2088
2089 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2090}
2091
2092/**
2093 * hdd_disable_power_management() - API to disable Power Management
2094 *
2095 * API disable Bus Interface Layer Power management functionality
2096 *
2097 * Return: None
2098 */
2099static void hdd_disable_power_management(void)
2100{
2101 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2102
2103 if (!hif_ctx) {
2104 hdd_err("Bus Interface Context is Invalid");
2105 return;
2106 }
2107
2108 hif_disable_power_management(hif_ctx);
2109}
2110
2111/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302112 * hdd_update_hw_sw_info() - API to update the HW/SW information
2113 *
2114 * API to update the HW and SW information in the driver
2115 *
2116 * Return: None
2117 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002118static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302119{
2120 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002121 size_t target_hw_name_len;
2122 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302123
2124 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2125 if (!hif_sc) {
2126 hdd_err("HIF context is NULL");
2127 return;
2128 }
2129
2130 /*
2131 * target hw version/revision would only be retrieved after firmware
2132 * download
2133 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002134 hif_get_hw_info(hif_sc,
2135 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302136 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002137 &target_hw_name);
2138
2139 if (hdd_ctx->target_hw_name)
2140 qdf_mem_free(hdd_ctx->target_hw_name);
2141
2142 target_hw_name_len = strlen(target_hw_name) + 1;
2143 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2144 if (hdd_ctx->target_hw_name)
2145 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2146 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302147
2148 /* Get the wlan hw/fw version */
2149 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302150}
2151
2152/**
gbian62edd7e2017-03-07 13:12:13 +08002153 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2154 * @hdd_ctx: Pointer to hdd context
2155 *
2156 * Return: none
2157 */
2158static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002159hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002160{
2161 uint8_t num_entries = 0;
2162 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2163 uint8_t *tx_sched_wrr_ac;
2164 int i;
2165 cds_context_type *cds_ctx;
2166
2167 if (NULL == hdd_ctx)
2168 return;
2169
2170 if (NULL == hdd_ctx->config) {
2171 /* Do nothing if hdd_ctx is invalid */
2172 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2173 return;
2174 }
2175
2176 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2177
2178 if (!cds_ctx) {
2179 hdd_err("Invalid CDS Context");
2180 return;
2181 }
2182
2183 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2184 switch (i) {
2185 case OL_TX_WMM_AC_BE:
2186 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2187 break;
2188 case OL_TX_WMM_AC_BK:
2189 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2190 break;
2191 case OL_TX_WMM_AC_VI:
2192 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2193 break;
2194 case OL_TX_WMM_AC_VO:
2195 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2196 break;
2197 default:
2198 tx_sched_wrr_ac = NULL;
2199 break;
2200 }
2201
2202 hdd_string_to_u8_array(tx_sched_wrr_ac,
2203 tx_sched_wrr_param,
2204 &num_entries,
2205 sizeof(tx_sched_wrr_param));
2206
2207 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2208 cds_ctx->ac_specs[i].wrr_skip_weight =
2209 tx_sched_wrr_param[0];
2210 cds_ctx->ac_specs[i].credit_threshold =
2211 tx_sched_wrr_param[1];
2212 cds_ctx->ac_specs[i].send_limit =
2213 tx_sched_wrr_param[2];
2214 cds_ctx->ac_specs[i].credit_reserve =
2215 tx_sched_wrr_param[3];
2216 cds_ctx->ac_specs[i].discard_weight =
2217 tx_sched_wrr_param[4];
2218 }
2219
2220 num_entries = 0;
2221 }
2222}
2223
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002224#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002225static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2226 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2227{
Jeff Johnson9d295242017-08-29 14:39:48 -07002228 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002229 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002230
2231 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2232 if (!adapter) {
2233 hdd_err("Adapter is NULL");
2234 return PM_MAX_NUM_OF_MODE;
2235 }
2236
2237 return policy_mgr_convert_device_mode_to_qdf_type(
2238 adapter->device_mode);
2239}
2240
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002241static void hdd_register_policy_manager_callback(
2242 struct wlan_objmgr_psoc *psoc)
2243{
2244 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002245
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002246 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002247 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002248 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2249 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002250 hdd_cbacks.get_mode_for_non_connected_vdev =
2251 wlan_hdd_get_mode_for_non_connected_vdev;
2252
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002253 if (QDF_STATUS_SUCCESS !=
2254 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2255 hdd_err("HDD callback registration with policy manager failed");
2256 }
2257}
2258#else
2259static void hdd_register_policy_manager_callback(
2260 struct wlan_objmgr_psoc *psoc)
2261{
2262}
2263#endif
2264
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002265#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002266static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002267{
2268 struct nan_callbacks cb_obj = {0};
2269
2270 cb_obj.ndi_open = hdd_ndi_open;
2271 cb_obj.ndi_close = hdd_ndi_close;
2272 cb_obj.ndi_start = hdd_ndi_start;
2273 cb_obj.ndi_delete = hdd_ndi_delete;
2274 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2275 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2276
Naveen Rawat37f62c82017-03-26 22:24:43 -07002277 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2278 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002279 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002280
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002281 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2282}
2283#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002284static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002285{
2286}
2287#endif
2288
gbian62edd7e2017-03-07 13:12:13 +08002289/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302290 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2291 * @hdd_ctx: HDD context
2292 * @adapter: HDD adapter
2293 * @reinit: flag to indicate from SSR or normal path
2294 *
2295 * This function maintains the driver state machine it will be invoked from
2296 * startup, reinit and change interface. Depending on the driver state shall
2297 * perform the opening of the modules.
2298 *
2299 * Return: 0 for success; non-zero for failure
2300 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002301int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2302 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302303 bool reinit)
2304{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002305 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302306 qdf_device_t qdf_dev;
2307 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302308 bool unint = false;
2309 void *hif_ctx;
2310
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002311 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302312
2313 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2314 if (!qdf_dev) {
2315 hdd_err("QDF Device Context is Invalid return");
2316 return -EINVAL;
2317 }
2318
2319 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302320 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302321
2322 if (QDF_TIMER_STATE_RUNNING ==
2323 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2324
2325 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002326 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302327 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2328 }
2329
2330 switch (hdd_ctx->driver_status) {
2331 case DRIVER_MODULES_UNINITIALIZED:
2332 unint = true;
2333 /* Fall through dont add break here */
2334 case DRIVER_MODULES_CLOSED:
2335 if (!reinit && !unint) {
2336 ret = pld_power_on(qdf_dev->dev);
2337 if (ret) {
2338 hdd_err("Failed to Powerup the device: %d", ret);
2339 goto release_lock;
2340 }
2341 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002342
2343 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2344 hdd_ctx->config->enable_fw_log);
2345
Arun Khandavallifae92942016-08-01 13:31:08 +05302346 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2347 qdf_dev->bus_type,
2348 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2349 HIF_ENABLE_TYPE_PROBE);
2350 if (ret) {
2351 hdd_err("Failed to open hif: %d", ret);
2352 goto power_down;
2353 }
2354
2355 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302356 if (!hif_ctx) {
2357 hdd_err("hif context is null!!");
2358 goto power_down;
2359 }
2360
Arun Khandavallifae92942016-08-01 13:31:08 +05302361 status = ol_cds_init(qdf_dev, hif_ctx);
2362 if (status != QDF_STATUS_SUCCESS) {
2363 hdd_err("No Memory to Create BMI Context :%d", status);
2364 goto hif_close;
2365 }
2366
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002367 ret = hdd_update_config(hdd_ctx);
2368 if (ret) {
2369 hdd_err("Failed to update configuration :%d", ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002370 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002371 }
2372
gbian62edd7e2017-03-07 13:12:13 +08002373 hdd_update_cds_ac_specs_params(hdd_ctx);
2374
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302375 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002376 if (QDF_IS_STATUS_ERROR(status)) {
Arun Khandavallifae92942016-08-01 13:31:08 +05302377 hdd_err("Failed to Open CDS: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002378 ret = qdf_status_to_os_return(status);
2379 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302380 }
2381
Mukul Sharma9d797a02017-01-05 20:26:03 +05302382 /* initalize components configurations after psoc open */
2383 ret = hdd_update_components_config(hdd_ctx);
2384 if (ret) {
2385 hdd_err("Failed to update components configs :%d",
2386 ret);
2387 goto close;
2388 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002389 status = cds_dp_open(hdd_ctx->hdd_psoc);
2390 if (!QDF_IS_STATUS_SUCCESS(status)) {
2391 hdd_err("Failed to Open cds post open: %d", status);
2392 goto close;
2393 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302394
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002395 /*
2396 * NAN compoenet requires certian operations like, open adapter,
2397 * close adapter, etc. to be initiated by HDD, for those
2398 * register HDD callbacks with UMAC's NAN componenet.
2399 */
2400 hdd_nan_register_callbacks(hdd_ctx);
2401
Arun Khandavallifae92942016-08-01 13:31:08 +05302402 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2403
Jeff Johnson3a280122017-09-13 07:42:00 -07002404 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302405 if (!QDF_IS_STATUS_SUCCESS(status)) {
2406 hdd_err("Failed to pre-enable CDS: %d", status);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002407 ret = (status == QDF_STATUS_E_NOMEM) ? -ENOMEM : -EINVAL;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002408 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302409 }
2410
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002411 hdd_register_policy_manager_callback(
2412 hdd_ctx->hdd_psoc);
2413
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302414 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302415 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302416
Arun Khandavallifae92942016-08-01 13:31:08 +05302417 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2418 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2419 hdd_ftm_mc_process_msg);
2420 break;
2421 }
2422 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002423 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302424 break;
2425 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302426
2427 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002428 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2429 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002430 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002431 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302432 }
2433
Arun Khandavallifae92942016-08-01 13:31:08 +05302434 /* Fall through dont add break here */
2435 case DRIVER_MODULES_OPENED:
2436 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002437 hdd_alert("adapter is Null");
2438 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302439 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302440 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2441 hdd_err("in ftm mode, no need to configure cds modules");
2442 break;
2443 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302444 if (hdd_configure_cds(hdd_ctx, adapter)) {
2445 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002446 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302447 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302448 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302449 hdd_info("Driver Modules Successfully Enabled");
2450 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2451 break;
2452 case DRIVER_MODULES_ENABLED:
2453 hdd_info("Driver modules already Enabled");
2454 break;
2455 default:
2456 hdd_err("WLAN start invoked in wrong state! :%d\n",
2457 hdd_ctx->driver_status);
2458 goto release_lock;
2459 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302460 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302461 mutex_unlock(&hdd_ctx->iface_change_lock);
2462 EXIT();
2463 return 0;
2464
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002465post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002466 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002467
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002468cds_txrx_free:
2469 cds_dp_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302470close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002471 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002472 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302473
Dustin Brown28b17892017-10-10 13:29:38 -07002474deinit_config:
2475 cds_deinit_ini_config();
2476
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002477cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302478 ol_cds_free();
2479
2480hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002481 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2482 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302483power_down:
2484 if (!reinit && !unint)
2485 pld_power_off(qdf_dev->dev);
2486release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302487 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302488 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302489 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002490
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002491 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302492}
2493
Naveen Rawat910726a2017-03-06 11:42:51 -08002494#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002495static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002496{
2497 int ret = os_if_wifi_pos_register_nl();
2498
2499 if (ret)
2500 hdd_err("os_if_wifi_pos_register_nl failed");
2501
2502 return ret;
2503}
2504
2505static int hdd_deactivate_wifi_pos(void)
2506{
2507 int ret = os_if_wifi_pos_deregister_nl();
2508
2509 if (ret)
2510 hdd_err("os_if_wifi_pos_deregister_nl failed");
2511
2512 return ret;
2513}
2514
2515/**
2516 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2517 * @hdd_ctx: hdd context
2518 *
2519 * Return: status of operation
2520 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002521static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002522{
2523 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2524 struct hdd_config *cfg = hdd_ctx->config;
2525
2526 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2527 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2528 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2529 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2530 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2531 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2532 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2533 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2534}
2535#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002536static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002537{
2538 return oem_activate_service(hdd_ctx);
2539}
2540
2541static int hdd_deactivate_wifi_pos(void)
2542{
2543 return 0;
2544}
2545
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002546static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002547{
2548}
2549#endif
2550
Arun Khandavallifae92942016-08-01 13:31:08 +05302551/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002552 * __hdd_open() - HDD Open function
2553 * @dev: Pointer to net_device structure
2554 *
2555 * This is called in response to ifconfig up
2556 *
2557 * Return: 0 for success; non-zero for failure
2558 */
2559static int __hdd_open(struct net_device *dev)
2560{
Jeff Johnson9d295242017-08-29 14:39:48 -07002561 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002562 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002563 int ret;
2564
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002565 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302566 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302567 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002568
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302569 /* Nothing to be done if device is unloading */
2570 if (cds_is_driver_unloading()) {
2571 hdd_err("Driver is unloading can not open the hdd");
2572 return -EBUSY;
2573 }
2574
Dustin Brown01847752017-10-25 13:56:27 -07002575 if (cds_is_driver_recovering()) {
2576 hdd_err("WLAN is currently recovering; Please try again.");
2577 return -EBUSY;
2578 }
2579
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302580 mutex_lock(&hdd_init_deinit_lock);
2581
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302582 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2583
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302584 /*
2585 * This scenario can be hit in cases where in the wlan driver after
2586 * registering the netdevices and there is a failure in driver
2587 * initialization. So return error gracefully because the netdevices
2588 * will be de-registered as part of the load failure.
2589 */
2590
2591 if (!cds_is_driver_loaded()) {
2592 hdd_err("Failed to start the wlan driver!!");
2593 ret = -EIO;
2594 goto err_hdd_hdd_init_deinit_lock;
2595 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302596
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002597
Arun Khandavallifae92942016-08-01 13:31:08 +05302598 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2599 if (ret) {
2600 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302601 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302602 }
2603
2604
2605 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2606 ret = hdd_start_adapter(adapter);
2607 if (ret) {
2608 hdd_err("Failed to start adapter :%d",
2609 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302610 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302611 }
2612 }
2613
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002614 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2615 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002616 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002617 /* Enable TX queues only when we are connected */
2618 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302619 WLAN_START_ALL_NETIF_QUEUE,
2620 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002621 }
2622
Naveen Rawat286def52016-09-23 15:38:02 -07002623 /* Enable carrier and transmit queues for NDI */
2624 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002625 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002626 wlan_hdd_netif_queue_control(adapter,
2627 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2628 WLAN_CONTROL_PATH);
2629 }
2630
Naveen Rawat910726a2017-03-06 11:42:51 -08002631 hdd_populate_wifi_pos_cfg(hdd_ctx);
2632
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302633err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302634 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302635 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002636 return ret;
2637}
2638
Arun Khandavallifae92942016-08-01 13:31:08 +05302639
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002640/**
2641 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2642 * @dev: Pointer to net_device structure
2643 *
2644 * This is called in response to ifconfig up
2645 *
2646 * Return: 0 for success; non-zero for failure
2647 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002648static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002649{
2650 int ret;
2651
2652 cds_ssr_protect(__func__);
2653 ret = __hdd_open(dev);
2654 cds_ssr_unprotect(__func__);
2655
2656 return ret;
2657}
2658
2659/**
2660 * __hdd_stop() - HDD stop function
2661 * @dev: Pointer to net_device structure
2662 *
2663 * This is called in response to ifconfig down
2664 *
2665 * Return: 0 for success; non-zero for failure
2666 */
2667static int __hdd_stop(struct net_device *dev)
2668{
Jeff Johnson9d295242017-08-29 14:39:48 -07002669 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002670 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002671 int ret;
2672
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002673 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002674
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302675 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002676 adapter->sessionId, adapter->device_mode));
2677
2678 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302679 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002680 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002681
2682 /* Nothing to be done if the interface is not opened */
2683 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002684 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002685 return -ENODEV;
2686 }
2687
2688 /* Make sure the interface is marked as closed */
2689 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302690
2691 hdd_debug("Disabling Auto Power save timer");
2692 sme_ps_disable_auto_ps_timer(
2693 WLAN_HDD_GET_HAL_CTX(adapter),
2694 adapter->sessionId);
2695
2696 /*
2697 * Disable TX on the interface, after this hard_start_xmit() will not
2698 * be called on that interface
2699 */
2700 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302701 wlan_hdd_netif_queue_control(adapter,
2702 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2703 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002704
2705 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002706 * NAN data interface is different in some sense. The traffic on NDI is
2707 * bursty in nature and depends on the need to transfer. The service
2708 * layer may down the interface after the usage and up again when
2709 * required. In some sense, the NDI is expected to be available
2710 * (like SAP) iface until NDI delete request is issued by the service
2711 * layer. Skip BSS termination and adapter deletion for NAN Data
2712 * interface (NDI).
2713 */
2714 if (WLAN_HDD_IS_NDI(adapter))
2715 return 0;
2716
2717 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002718 * The interface is marked as down for outside world (aka kernel)
2719 * But the driver is pretty much alive inside. The driver needs to
2720 * tear down the existing connection on the netdev (session)
2721 * cleanup the data pipes and wait until the control plane is stabilized
2722 * for this interface. The call also needs to wait until the above
2723 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002724 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002725 * That is intentional to be able to scan if it is a STA/P2P interface
2726 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302727 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002728
2729 /* DeInit the adapter. This ensures datapath cleanup as well */
2730 hdd_deinit_adapter(hdd_ctx, adapter, true);
2731
Arun Khandavallifae92942016-08-01 13:31:08 +05302732
2733 /*
2734 * Find if any iface is up. If any iface is up then can't put device to
2735 * sleep/power save mode
2736 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302737 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002738 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302739 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302740 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302741 hdd_prevent_suspend_timeout(
2742 hdd_ctx->config->iface_change_wait_time,
2743 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302744 }
2745
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002746 EXIT();
2747 return 0;
2748}
2749
2750/**
2751 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2752 * @dev: pointer to net_device structure
2753 *
2754 * This is called in response to ifconfig down
2755 *
2756 * Return: 0 for success and error number for failure
2757 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002758static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002759{
2760 int ret;
2761
2762 cds_ssr_protect(__func__);
2763 ret = __hdd_stop(dev);
2764 cds_ssr_unprotect(__func__);
2765
2766 return ret;
2767}
2768
2769/**
2770 * __hdd_uninit() - HDD uninit function
2771 * @dev: Pointer to net_device structure
2772 *
2773 * This is called during the netdev unregister to uninitialize all data
2774 * associated with the device
2775 *
2776 * Return: None
2777 */
2778static void __hdd_uninit(struct net_device *dev)
2779{
Jeff Johnson9d295242017-08-29 14:39:48 -07002780 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002781 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002782
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002783 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002784
2785 do {
2786 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002787 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002788 break;
2789 }
2790
Jeff Johnson399c6272017-08-30 10:51:00 -07002791 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2792 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002793 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002794 break;
2795 }
2796
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002797 if (dev != adapter->dev)
2798 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002799
Jeff Johnson399c6272017-08-30 10:51:00 -07002800 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002801
2802 /* after uninit our adapter structure will no longer be valid */
2803 adapter->dev = NULL;
2804 adapter->magic = 0;
2805 } while (0);
2806
2807 EXIT();
2808}
2809
2810/**
2811 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2812 * @dev: pointer to net_device structure
2813 *
2814 * This is called during the netdev unregister to uninitialize all data
2815 * associated with the device
2816 *
2817 * Return: none
2818 */
2819static void hdd_uninit(struct net_device *dev)
2820{
2821 cds_ssr_protect(__func__);
2822 __hdd_uninit(dev);
2823 cds_ssr_unprotect(__func__);
2824}
2825
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002826static int hdd_open_cesium_nl_sock(void)
2827{
2828#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2829 struct netlink_kernel_cfg cfg = {
2830 .groups = WLAN_NLINK_MCAST_GRP_ID,
2831 .input = NULL
2832 };
2833#endif
2834 int ret = 0;
2835
2836#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2837 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2838#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2839 THIS_MODULE,
2840#endif
2841 &cfg);
2842#else
2843 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2844 WLAN_NLINK_MCAST_GRP_ID,
2845 NULL, NULL, THIS_MODULE);
2846#endif
2847
2848 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002849 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002850 ret = -ECONNREFUSED;
2851 }
2852
2853 return ret;
2854}
2855
2856static void hdd_close_cesium_nl_sock(void)
2857{
2858 if (NULL != cesium_nl_srv_sock) {
2859 netlink_kernel_release(cesium_nl_srv_sock);
2860 cesium_nl_srv_sock = NULL;
2861 }
2862}
2863
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002864/**
2865 * __hdd_set_mac_address() - set the user specified mac address
2866 * @dev: Pointer to the net device.
2867 * @addr: Pointer to the sockaddr.
2868 *
2869 * This function sets the user specified mac address using
2870 * the command ifconfig wlanX hw ether <mac adress>.
2871 *
2872 * Return: 0 for success, non zero for failure
2873 */
2874static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2875{
Jeff Johnson9d295242017-08-29 14:39:48 -07002876 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002877 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302879 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002880 int ret;
2881
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002882 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002883
2884 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2885 ret = wlan_hdd_validate_context(hdd_ctx);
2886 if (0 != ret)
2887 return ret;
2888
2889 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2890 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2891
2892 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302893 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002894}
2895
2896/**
2897 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2898 * function from SSR
2899 * @dev: pointer to net_device structure
2900 * @addr: Pointer to the sockaddr
2901 *
2902 * This function sets the user specified mac address using
2903 * the command ifconfig wlanX hw ether <mac adress>.
2904 *
2905 * Return: 0 for success.
2906 */
2907static int hdd_set_mac_address(struct net_device *dev, void *addr)
2908{
2909 int ret;
2910
2911 cds_ssr_protect(__func__);
2912 ret = __hdd_set_mac_address(dev, addr);
2913 cds_ssr_unprotect(__func__);
2914
2915 return ret;
2916}
2917
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002918uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002919{
2920 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002921
Anurag Chouhan6d760662016-02-20 16:05:43 +05302922 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002923 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2924 break;
2925 }
2926
Anurag Chouhan6d760662016-02-20 16:05:43 +05302927 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002928 return NULL;
2929
2930 hdd_ctx->config->intfAddrMask |= (1 << i);
2931 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2932}
2933
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07002934void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
2935 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002936{
2937 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002938
Anurag Chouhan6d760662016-02-20 16:05:43 +05302939 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002940 if (!memcmp(releaseAddr,
2941 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2942 6)) {
2943 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2944 break;
2945 }
2946 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947}
2948
2949#ifdef WLAN_FEATURE_PACKET_FILTERING
2950/**
2951 * __hdd_set_multicast_list() - set the multicast address list
2952 * @dev: Pointer to the WLAN device.
2953 * @skb: Pointer to OS packet (sk_buff).
2954 *
2955 * This funciton sets the multicast address list.
2956 *
2957 * Return: None
2958 */
2959static void __hdd_set_multicast_list(struct net_device *dev)
2960{
Jeff Johnson9d295242017-08-29 14:39:48 -07002961 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002962 int i = 0, status;
2963 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002964 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302965 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2966 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2967 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002968
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002969 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302970 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302971 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302972
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002973 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302974 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302975 goto out;
2976
Dustin Brownc788acb2017-08-01 17:43:51 -07002977 status = hdd_validate_adapter(adapter);
2978 if (status)
2979 goto out;
2980
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302981 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2982 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002983 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302984 goto out;
2985 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002986
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302987 /* Delete already configured multicast address list */
2988 if (adapter->mc_addr_list.mc_cnt > 0) {
2989 hdd_info("clear previously configured MC address list");
2990 hdd_disable_and_flush_mc_addr_list(adapter,
2991 pmo_mc_list_change_notify);
2992 }
2993
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002994 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002995 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302996 hdd_disable_and_flush_mc_addr_list(adapter,
2997 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002998 } else {
2999 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303000 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003001 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303002 pmo_ucfg_max_mc_addr_supported(psoc));
3003 hdd_disable_and_flush_mc_addr_list(adapter,
3004 pmo_mc_list_change_notify);
3005 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003006 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003007 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003008 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303009 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003010 if (i == mc_count)
3011 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303012 memset(&(mc_list_request->mc_addr[i].bytes),
3013 0, ETH_ALEN);
3014 memcpy(&(mc_list_request->mc_addr[i].bytes),
3015 ha->addr, ETH_ALEN);
3016 hdd_info("mlist[%d] = %pM", i,
3017 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003018 i++;
3019 }
3020 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303021
3022 mc_list_request->psoc = psoc;
3023 mc_list_request->vdev_id = adapter->sessionId;
3024 mc_list_request->count = mc_count;
3025 status = hdd_cache_mc_addr_list(mc_list_request);
3026 if (status == 0) {
3027 hdd_enable_mc_addr_filtering(adapter,
3028 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303030 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003031 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303032out:
3033 if (mc_list_request)
3034 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303035 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003036}
3037
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303038
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003039/**
3040 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3041 * @dev: pointer to net_device
3042 *
3043 * Return: none
3044 */
3045static void hdd_set_multicast_list(struct net_device *dev)
3046{
3047 cds_ssr_protect(__func__);
3048 __hdd_set_multicast_list(dev);
3049 cds_ssr_unprotect(__func__);
3050}
3051#endif
3052
3053/**
3054 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3055 * @dev: Pointer to the WLAN device.
3056 * @skb: Pointer to OS packet (sk_buff).
3057 *
3058 * This function is registered with the Linux OS for network
3059 * core to decide which queue to use first.
3060 *
3061 * Return: ac, Queue Index/access category corresponding to UP in IP header
3062 */
3063static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3064#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3065 , void *accel_priv
3066#endif
3067#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3068 , select_queue_fallback_t fallback
3069#endif
3070)
3071{
3072 return hdd_wmm_select_queue(dev, skb);
3073}
3074
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003075static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003076 .ndo_open = hdd_open,
3077 .ndo_stop = hdd_stop,
3078 .ndo_uninit = hdd_uninit,
3079 .ndo_start_xmit = hdd_hard_start_xmit,
3080 .ndo_tx_timeout = hdd_tx_timeout,
3081 .ndo_get_stats = hdd_get_stats,
3082 .ndo_do_ioctl = hdd_ioctl,
3083 .ndo_set_mac_address = hdd_set_mac_address,
3084 .ndo_select_queue = hdd_select_queue,
3085#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003086 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003087#endif
3088};
3089
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003090/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003091static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003092 .ndo_open = hdd_mon_open,
3093 .ndo_stop = hdd_stop,
3094 .ndo_get_stats = hdd_get_stats,
3095};
3096
3097/**
3098 * hdd_set_station_ops() - update net_device ops for monitor mode
3099 * @pWlanDev: Handle to struct net_device to be updated.
3100 * Return: None
3101 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003102void hdd_set_station_ops(struct net_device *pWlanDev)
3103{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003104 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
3105 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
3106 else
3107 pWlanDev->netdev_ops = &wlan_drv_ops;
3108}
3109
3110/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003111 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3112 * @hdd_ctx: global hdd context
3113 * @macAddr: mac address to assign to the interface
3114 * @name: User-visible name of the interface
3115 *
3116 * hdd adapter pointer would point to the netdev->priv space, this function
3117 * would retrive the pointer, and setup the hdd adapter configuration.
3118 *
3119 * Return: the pointer to hdd adapter, otherwise NULL
3120 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003121static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003123 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124 const char *name)
3125{
3126 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003127 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003128 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003129 /*
3130 * cfg80211 initialization and registration....
3131 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003132 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003133#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3134 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003135#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003136 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3137 hdd_mon_mode_ether_setup : ether_setup),
3138 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003139
3140 if (pWlanDev != NULL) {
3141
3142 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003143 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003144
Jeff Johnson9d295242017-08-29 14:39:48 -07003145 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303146 sta_ctx = &adapter->sessionCtx.station;
3147 qdf_mem_set(sta_ctx->conn_info.staId,
3148 sizeof(sta_ctx->conn_info.staId),
3149 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003151 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303153 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154
3155 init_completion(&adapter->session_open_comp_var);
3156 init_completion(&adapter->session_close_comp_var);
3157 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303158 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003159 init_completion(&adapter->linkup_event_var);
3160 init_completion(&adapter->cancel_rem_on_chan_var);
3161 init_completion(&adapter->rem_on_chan_ready_event);
3162 init_completion(&adapter->sta_authorized_event);
3163 init_completion(&adapter->offchannel_tx_event);
3164 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003165 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303167 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003168
3169 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003170 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003171 adapter->higherDtimTransition = true;
3172 /* Init the net_device structure */
3173 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3174
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303175 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003176 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303177 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178 sizeof(tSirMacAddr));
3179 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003180
3181 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3182 pWlanDev->features |=
3183 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3184 pWlanDev->features |= NETIF_F_RXCSUM;
3185
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003186 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188 hdd_set_station_ops(adapter->dev);
3189
Dustin Brownc81dd412017-08-15 16:26:28 -07003190 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003191 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003192 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003193 adapter->wdev.wiphy = hdd_ctx->wiphy;
3194 adapter->wdev.netdev = pWlanDev;
3195 /* set pWlanDev's parent to underlying device */
3196 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3197 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303198 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303200 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003201 }
3202
3203 return adapter;
3204}
3205
Jeff Johnson9d295242017-08-29 14:39:48 -07003206static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003207{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003208 struct net_device *dev = adapter->dev;
3209 int ret;
3210
3211 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003213 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003214 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3215
3216 ret = dev_alloc_name(dev, dev->name);
3217 if (ret < 0) {
3218 hdd_err(
3219 "unable to get dev name: %s, err = 0x%x",
3220 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303221 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003222 }
3223 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003224
3225 ret = register_netdevice(dev);
3226 if (ret) {
3227 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3228 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303229 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003230 }
3231 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003232 ret = register_netdev(dev);
3233 if (ret) {
3234 hdd_err("register_netdev(%s) failed, err = 0x%x",
3235 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303236 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003237 }
3238 }
3239 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3240
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003241 EXIT();
3242
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303243 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244}
3245
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003246QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003247{
Jeff Johnson9d295242017-08-29 14:39:48 -07003248 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003249
3250 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003251 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303252 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003253 }
3254
3255 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003256 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303257 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003258 }
3259
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003260 /*
3261 * For NAN Data interface, the close session results in the final
3262 * indication to the userspace
3263 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003264 if (adapter->device_mode == QDF_NDI_MODE)
3265 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003266
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3268
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269 /*
3270 * We can be blocked while waiting for scheduled work to be
3271 * flushed, and the adapter structure can potentially be freed, in
3272 * which case the magic will have been reset. So make sure the
3273 * magic is still good, and hence the adapter structure is still
3274 * valid, before signaling completion
3275 */
3276 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3277 complete(&adapter->session_close_comp_var);
3278
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303279 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003280}
3281
Jeff Johnson9d295242017-08-29 14:39:48 -07003282int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283{
Dustin Brownd28772b2017-03-17 14:16:07 -07003284 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003285
Dustin Brownd28772b2017-03-17 14:16:07 -07003286 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003287 if (QDF_IS_STATUS_ERROR(status))
3288 return qdf_status_to_os_return(status);
3289
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003290 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003291 if (QDF_IS_STATUS_ERROR(status))
3292 return qdf_status_to_os_return(status);
3293
3294 if (wma_capability_enhanced_mcast_filter())
3295 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3296 else
3297 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003298
3299 return qdf_status_to_os_return(status);
3300}
3301
Jeff Johnson9d295242017-08-29 14:39:48 -07003302int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003303{
3304 QDF_STATUS status;
3305 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003306 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003307 unsigned long rc;
3308
3309 hdd_info("destroying vdev %d", adapter->sessionId);
3310
3311 /* vdev created sanity check */
3312 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3313 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3314 return -EINVAL;
3315 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003316 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003317 /*
3318 * In SSR case, there is no need to destroy vdev in firmware since
3319 * it has already asserted. vdev can be released directly.
3320 */
3321 if (cds_is_driver_recovering())
3322 goto release_vdev;
3323
Dustin Brownd28772b2017-03-17 14:16:07 -07003324 /* close sme session (destroy vdev in firmware via legacy API) */
3325 INIT_COMPLETION(adapter->session_close_comp_var);
3326 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3327 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3328 hdd_sme_close_session_callback, adapter);
3329 if (QDF_IS_STATUS_ERROR(status)) {
3330 hdd_err("failed to close sme session: %d", status);
3331 return qdf_status_to_os_return(status);
3332 }
3333
3334 /* block on a completion variable until sme session is closed */
3335 rc = wait_for_completion_timeout(
3336 &adapter->session_close_comp_var,
3337 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3338 if (!rc) {
3339 hdd_err("timed out waiting for close sme session: %ld", rc);
3340 if (adapter->device_mode == QDF_NDI_MODE)
3341 hdd_ndp_session_end_handler(adapter);
3342 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3343 return -ETIMEDOUT;
3344 }
Yue Maf9782842017-05-08 12:49:49 -07003345release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003346 /* do vdev logical destroy via objmgr */
3347 errno = hdd_objmgr_destroy_vdev(adapter);
3348 if (errno) {
3349 hdd_err("failed to destroy objmgr vdev: %d", errno);
3350 return errno;
3351 }
3352
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003353 /* now that sme session is closed, allow physical vdev destroy */
3354 errno = hdd_objmgr_release_vdev(adapter);
3355 if (errno) {
3356 hdd_err("failed to release objmgr vdev: %d", errno);
3357 return errno;
3358 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003359 hdd_info("vdev destroyed successfully");
3360
3361 return 0;
3362}
3363
Jeff Johnson9d295242017-08-29 14:39:48 -07003364int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003365{
3366 QDF_STATUS status;
3367 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003368 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003369 uint32_t type;
3370 uint32_t sub_type;
3371 unsigned long rc;
3372
3373 hdd_info("creating new vdev");
3374
3375 /* determine vdev (sub)type */
3376 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303377 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003378 hdd_err("failed to get vdev type: %d", status);
3379 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003380 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003381
3382 /* do vdev create via objmgr */
3383 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003384 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003385 if (errno) {
3386 hdd_err("failed to create objmgr vdev: %d", errno);
3387 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003388 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003389
3390 /* Open a SME session (prepare vdev in firmware via legacy API) */
3391 INIT_COMPLETION(adapter->session_open_comp_var);
3392 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3393 (uint8_t *)&adapter->macAddressCurrent,
3394 adapter->sessionId, type, sub_type);
3395 if (QDF_IS_STATUS_ERROR(status)) {
3396 hdd_err("failed to open sme session: %d", status);
3397 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003398 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003399 }
3400
3401 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003402 rc = wait_for_completion_timeout(
3403 &adapter->session_open_comp_var,
3404 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3405 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003406 hdd_err("timed out waiting for open sme session: %ld", rc);
3407 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303408 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Krunal Soni4a020c72017-10-30 20:58:40 -07003409 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003410 }
3411
3412 /* firmware ready for component communication, raise vdev_ready event */
3413 errno = hdd_vdev_ready(adapter);
3414 if (errno) {
3415 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003416 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003417 }
3418
3419 hdd_info("vdev %d created successfully", adapter->sessionId);
3420
3421 return 0;
3422
3423 /*
3424 * Due to legacy constraints, we need to destroy in the same order as
3425 * create. So, split error handling into 2 cases to accommodate.
3426 */
3427
Krunal Soni4a020c72017-10-30 20:58:40 -07003428objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003429 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003430
3431 return errno;
3432
Krunal Soni4a020c72017-10-30 20:58:40 -07003433hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003434 QDF_BUG(!hdd_vdev_destroy(adapter));
3435
3436 return errno;
3437}
3438
Jeff Johnson9d295242017-08-29 14:39:48 -07003439QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003440{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003441 struct hdd_station_ctx *sta_ctx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003442 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003443 QDF_STATUS status;
3444 int ret_val;
3445
3446 ret_val = hdd_vdev_create(adapter);
3447 if (ret_val) {
3448 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303449 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450 }
3451
Dustin Brownd28772b2017-03-17 14:16:07 -07003452 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3453 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3454 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003455 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003456
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003457 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003458 status = hdd_register_wext(adapter->dev);
3459 if (QDF_IS_STATUS_ERROR(status)) {
3460 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461 goto error_register_wext;
3462 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003463 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003464
Jeff Johnsond377dce2017-10-04 10:32:42 -07003465 qdf_mem_set(sta_ctx->conn_info.staId,
3466 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303467
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003468 /* set fast roaming capability in sme session */
3469 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3470 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003472 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 hdd_ctx->config->OperatingChannel;
3474
3475 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003476 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477
3478 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303479 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003480 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003481 status, status);
3482 goto error_init_txrx;
3483 }
3484
3485 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3486
3487 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303488 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003489 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003490 status, status);
3491 goto error_wmm_init;
3492 }
3493
3494 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3495
Naveen Rawat247a8682017-06-05 15:00:31 -07003496 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003497 WMI_PDEV_PARAM_BURST_ENABLE,
3498 hdd_ctx->config->enableSifsBurst,
3499 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003500 if (ret_val)
3501 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003502
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003503 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303504
3505 /* rcpi info initialization */
3506 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3507
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303508 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003509
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003510error_wmm_init:
3511 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3512 hdd_deinit_tx_rx(adapter);
3513error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003514 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003515error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003516 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003517
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 return status;
3519}
3520
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303521/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003522 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303523 * @hdd_ctx: global hdd context
3524 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003525 * @rtnl_held: Used to indicate whether or not the caller is holding
3526 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303527 *
3528 * This function De-initializes the STA/P2P/OCB adapter.
3529 *
3530 * Return: None.
3531 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003532static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003533 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003534 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303535{
3536 ENTER_DEV(adapter->dev);
3537
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303538 if (adapter->dev) {
3539 if (rtnl_held)
3540 adapter->dev->wireless_handlers = NULL;
3541 else {
3542 rtnl_lock();
3543 adapter->dev->wireless_handlers = NULL;
3544 rtnl_unlock();
3545 }
3546 }
3547
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303548 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3549 hdd_deinit_tx_rx(adapter);
3550 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3551 }
3552
3553 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3554 hdd_wmm_adapter_close(adapter);
3555 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3556 }
3557
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303558 EXIT();
3559}
3560
Jeff Johnson9d295242017-08-29 14:39:48 -07003561void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 bool rtnl_held)
3563{
3564 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303565
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003566 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003567 case QDF_STA_MODE:
3568 case QDF_P2P_CLIENT_MODE:
3569 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003570 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003571 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003572 break;
3573 }
3574
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003575 case QDF_SAP_MODE:
3576 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003577 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003578 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003579 break;
3580 }
3581
3582 default:
3583 break;
3584 }
3585
3586 EXIT();
3587}
3588
Jeff Johnson9d295242017-08-29 14:39:48 -07003589static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003590 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591{
3592 struct net_device *pWlanDev = NULL;
3593
3594 if (adapter)
3595 pWlanDev = adapter->dev;
3596 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003597 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003598 return;
3599 }
3600
Rajeev Kumardca5f812016-02-04 17:28:06 -08003601 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303602
3603 if (adapter->scan_info.default_scan_ies) {
3604 qdf_mem_free(adapter->scan_info.default_scan_ies);
3605 adapter->scan_info.default_scan_ies = NULL;
3606 }
3607
Komal Seelama89be8d2016-09-29 11:09:26 +05303608 hdd_adapter_runtime_suspend_denit(adapter);
3609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610 /*
3611 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3612 * the driver is almost closed and cannot handle either control
3613 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003614 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3615 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 * is not right. Setting this flag helps hdd_stop() to recognize that
3617 * the interface is closed and restricts any operations on that
3618 */
3619 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3620
3621 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003622 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003623 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003624 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626 /*
3627 * Note that the adapter is no longer valid at this point
3628 * since the memory has been reclaimed
3629 */
3630 }
3631}
3632
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003633static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003634 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635{
3636 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003637 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303638 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003639
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003640 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303641 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003642 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003643 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303644 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303646 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003647 }
3648 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3649 adapterNode = pNext;
3650 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303651 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003652}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003653
Arun Khandavalli2358d522016-05-16 18:05:37 +05303654#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3655/**
3656 * hdd_set_fw_log_params() - Set log parameters to FW
3657 * @hdd_ctx: HDD Context
3658 * @adapter: HDD Adapter
3659 *
3660 * This function set the FW Debug log level based on the INI.
3661 *
3662 * Return: None
3663 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003664static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003665 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303666{
3667 uint8_t count = 0, numentries = 0,
3668 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3669 uint32_t value = 0;
3670 int ret;
3671
Arun Khandavallifae92942016-08-01 13:31:08 +05303672 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3673 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003674 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303675 return;
3676 }
3677
Arun Khandavallifae92942016-08-01 13:31:08 +05303678 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303679 hdd_ctx->fw_log_settings.dl_type =
3680 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003681 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303682 WMI_DBGLOG_TYPE,
3683 hdd_ctx->config->enableFwLogType,
3684 DBG_CMD);
3685 if (ret != 0)
3686 hdd_err("Failed to enable FW log type ret %d",
3687 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303688
3689 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303690 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003691 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303692 WMI_DBGLOG_LOG_LEVEL,
3693 hdd_ctx->config->enableFwLogLevel,
3694 DBG_CMD);
3695 if (ret != 0)
3696 hdd_err("Failed to enable FW log level ret %d",
3697 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303698
3699 hdd_string_to_u8_array(
3700 hdd_ctx->config->enableFwModuleLogLevel,
3701 moduleloglevel,
3702 &numentries,
3703 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3704
3705 while (count < numentries) {
3706 /*
3707 * FW module log level input string looks like
3708 * below:
3709 * gFwDebugModuleLoglevel=<FW Module ID>,
3710 * <Log Level>,...
3711 * For example:
3712 * gFwDebugModuleLoglevel=
3713 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3714 * Above input string means :
3715 * For FW module ID 1 enable log level 0
3716 * For FW module ID 2 enable log level 1
3717 * For FW module ID 3 enable log level 2
3718 * For FW module ID 4 enable log level 3
3719 * For FW module ID 5 enable log level 4
3720 * For FW module ID 6 enable log level 5
3721 * For FW module ID 7 enable log level 6
3722 */
3723
Nishank Aggarwale239d962017-03-03 12:26:02 +05303724 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3725 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3726 hdd_err("Module id %d and dbglog level %d input length is more than max",
3727 moduleloglevel[count],
3728 moduleloglevel[count + 1]);
3729 return;
3730 }
3731
3732 value = moduleloglevel[count] << 16;
3733 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003734 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303735 WMI_DBGLOG_MOD_LOG_LEVEL,
3736 value, DBG_CMD);
3737 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303738 hdd_err("Failed to enable FW module log level %d ret %d",
3739 value, ret);
3740
3741 count += 2;
3742 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303743
Arun Khandavalli2358d522016-05-16 18:05:37 +05303744}
3745#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003746static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003747 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303748{
3749}
3750
3751#endif
3752
3753/**
3754 * hdd_set_fw_params() - Set parameters to firmware
3755 * @adapter: HDD adapter
3756 *
3757 * This function Sets various parameters to fw once the
3758 * adapter is started.
3759 *
3760 * Return: 0 on success or errno on failure
3761 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003762int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303763{
3764 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003765 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303766
3767 ENTER_DEV(adapter->dev);
3768
3769 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3770 if (!hdd_ctx)
3771 return -EINVAL;
3772
Dustin Brown732ab9c2017-06-15 13:24:09 -07003773 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3774 hdd_debug("FTM Mode is active; nothing to do");
3775 return 0;
3776 }
3777
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303778 ret = sme_cli_set_command(adapter->sessionId,
3779 WMI_PDEV_PARAM_DTIM_SYNTH,
3780 hdd_ctx->config->enable_lprx, PDEV_CMD);
3781 if (ret) {
3782 hdd_err("Failed to set LPRx");
3783 goto error;
3784 }
3785
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303786 if (adapter->device_mode == QDF_STA_MODE) {
3787 sme_set_smps_cfg(adapter->sessionId,
3788 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3789 hdd_ctx->config->upper_brssi_thresh);
3790
3791 sme_set_smps_cfg(adapter->sessionId,
3792 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3793 hdd_ctx->config->lower_brssi_thresh);
3794
3795 sme_set_smps_cfg(adapter->sessionId,
3796 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3797 hdd_ctx->config->enable_dtim_1chrx);
3798 }
3799
Dustin Brown732ab9c2017-06-15 13:24:09 -07003800 if (hdd_ctx->config->enable2x2) {
3801 hdd_debug("configuring 2x2 mode fw params");
3802
Naveen Rawat247a8682017-06-05 15:00:31 -07003803 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003804 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3805 hdd_ctx->config->enable_cck_tx_fir_override,
3806 PDEV_CMD);
3807 if (ret) {
3808 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3809 ret);
3810 goto error;
3811 }
3812 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303813#define HDD_DTIM_1CHAIN_RX_ID 0x5
3814#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003815 hdd_debug("configuring 1x1 mode fw params");
3816
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003817 /*
3818 * Disable DTIM 1 chain Rx when in 1x1,
3819 * we are passing two value
3820 * as param_id << 29 | param_value.
3821 * Below param_value = 0(disable)
3822 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003823 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003824 WMI_STA_SMPS_PARAM_CMDID,
3825 HDD_DTIM_1CHAIN_RX_ID <<
3826 HDD_SMPS_PARAM_VALUE_S,
3827 VDEV_CMD);
3828 if (ret) {
3829 hdd_err("DTIM 1 chain set failed %d", ret);
3830 goto error;
3831 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303832
Naveen Rawat247a8682017-06-05 15:00:31 -07003833 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003834 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3835 hdd_ctx->config->txchainmask1x1,
3836 PDEV_CMD);
3837 if (ret) {
3838 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3839 ret);
3840 goto error;
3841 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303842
Naveen Rawat247a8682017-06-05 15:00:31 -07003843 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003844 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3845 hdd_ctx->config->rxchainmask1x1,
3846 PDEV_CMD);
3847 if (ret) {
3848 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3849 ret);
3850 goto error;
3851 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303852#undef HDD_DTIM_1CHAIN_RX_ID
3853#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003854 }
3855
Naveen Rawat247a8682017-06-05 15:00:31 -07003856 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003857 WMI_PDEV_PARAM_HYST_EN,
3858 hdd_ctx->config->enableMemDeepSleep,
3859 PDEV_CMD);
3860 if (ret) {
3861 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3862 goto error;
3863 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303864
Naveen Rawat247a8682017-06-05 15:00:31 -07003865 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003866 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3867 hdd_ctx->config->rts_profile,
3868 VDEV_CMD);
3869 if (ret) {
3870 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3871 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303872 }
3873
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003874 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3875
3876 ret = wma_cli_set_command(adapter->sessionId,
3877 GEN_VDEV_PARAM_AMSDU,
3878 hdd_ctx->config->max_amsdu_num,
3879 GEN_CMD);
3880 if (ret != 0) {
3881 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3882 goto error;
3883 }
3884
Arun Khandavalli2358d522016-05-16 18:05:37 +05303885 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303886 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003887
Arun Khandavalli2358d522016-05-16 18:05:37 +05303888 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303889
Arun Khandavalli2358d522016-05-16 18:05:37 +05303890error:
3891 return -EINVAL;
3892}
3893
Ryan Hsu07495ea2016-01-21 15:25:39 -08003894/**
3895 * hdd_open_adapter() - open and setup the hdd adatper
3896 * @hdd_ctx: global hdd context
3897 * @session_type: type of the interface to be created
3898 * @iface_name: User-visible name of the interface
3899 * @macAddr: MAC address to assign to the interface
3900 * @name_assign_type: the name of assign type of the netdev
3901 * @rtnl_held: the rtnl lock hold flag
3902 *
3903 * This function open and setup the hdd adpater according to the device
3904 * type request, assign the name, the mac address assigned, and then prepared
3905 * the hdd related parameters, queue, lock and ready to start.
3906 *
3907 * Return: the pointer of hdd adapter, otherwise NULL.
3908 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003909struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003910 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003911 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003912 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003913{
Jeff Johnson9d295242017-08-29 14:39:48 -07003914 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003915 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303916 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917
3918 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3919 /*
3920 * Max limit reached on the number of vdevs configured by the
3921 * host. Return error
3922 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303923 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3924 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925 return NULL;
3926 }
3927
3928 if (macAddr == NULL) {
3929 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303930 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931 return NULL;
3932 }
3933 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303934 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303935 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3936 " already exists",
3937 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003938 return NULL;
3939 }
3940
3941 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003942 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943 /* Reset locally administered bit if the device mode is STA */
3944 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303945 hdd_info("locally administered bit reset in sta mode: "
3946 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003948 case QDF_P2P_CLIENT_MODE:
3949 case QDF_P2P_DEVICE_MODE:
3950 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003951 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303952 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003953 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3954 name_assign_type,
3955 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956
3957 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303958 hdd_err("failed to allocate adapter for session %d",
3959 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003960 return NULL;
3961 }
3962
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003963 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003964 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003965 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303967 else if (QDF_MONITOR_MODE == session_type)
3968 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003969 else
3970 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3971
3972 adapter->device_mode = session_type;
3973
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003975 /*
3976 * Workqueue which gets scheduled in IPv4 notification
3977 * callback
3978 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3980 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981
3982#ifdef WLAN_NS_OFFLOAD
3983 /*
3984 * Workqueue which gets scheduled in IPv6
3985 * notification callback.
3986 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003987 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3988 hdd_ipv6_notifier_work_queue);
3989#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303991 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303993 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994 }
3995
3996 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003997 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303999 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4000 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304001
Ravi Joshi1a292562017-05-18 16:28:54 -07004002 /* Initialize NAN Data Interface */
4003 if (QDF_NDI_MODE == session_type) {
4004 status = hdd_init_nan_data_mode(adapter);
4005 if (QDF_STATUS_SUCCESS != status)
4006 goto err_free_netdev;
4007 }
4008
4009 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004011 case QDF_P2P_GO_MODE:
4012 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004013 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4014 name_assign_type,
4015 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004016 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004017 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304018 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 return NULL;
4020 }
4021
4022 adapter->wdev.iftype =
4023 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004024 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 NL80211_IFTYPE_P2P_GO;
4026 adapter->device_mode = session_type;
4027
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004028 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304029 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4031 goto err_free_netdev;
4032 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004033 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004034 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304035 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4036 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304037
4038 /*
4039 * Workqueue which gets scheduled in IPv4 notification
4040 * callback
4041 */
4042 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4043 hdd_ipv4_notifier_work_queue);
4044
4045#ifdef WLAN_NS_OFFLOAD
4046 /*
4047 * Workqueue which gets scheduled in IPv6
4048 * notification callback.
4049 */
4050 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4051 hdd_ipv6_notifier_work_queue);
4052#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004053 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304054 case QDF_FTM_MODE:
4055 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4056 name_assign_type,
4057 "wlan0");
4058 if (NULL == adapter) {
4059 hdd_err("Failed to allocate adapter for FTM mode");
4060 return NULL;
4061 }
4062 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4063 adapter->device_mode = session_type;
4064 status = hdd_register_interface(adapter, rtnl_held);
4065 if (QDF_STATUS_SUCCESS != status) {
4066 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4067 goto err_free_netdev;
4068 }
4069 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004070 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304071 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304072 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4073 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304074 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004075 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004076 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304077 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 return NULL;
4079 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080
hqueaa33ee2017-05-04 17:56:35 +08004081 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4082
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304083 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004084 /* Add it to the hdd's session list. */
4085 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304086 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004087 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304088 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004089 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004090 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004091 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4092 }
4093 }
4094
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304095 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004096 if (NULL != adapter) {
4097 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4098 adapter = NULL;
4099 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004100 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304101 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004102
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004103 return NULL;
4104 }
4105
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304106 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004107 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4108 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110 /* Adapter successfully added. Increment the vdev count */
4111 hdd_ctx->current_intf_count++;
4112
Jeff Johnson5880d792016-08-15 13:32:30 -07004113 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114 hdd_ctx->current_intf_count);
4115
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004116 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004117 }
4118
Rajeev Kumardca5f812016-02-04 17:28:06 -08004119 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004120 hdd_err("Interface %s wow debug_fs init failed",
4121 netdev_name(adapter->dev));
4122
4123 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4124 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004125
4126 return adapter;
4127
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004128err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004129 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304130 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004131
4132 return NULL;
4133}
4134
Jeff Johnson9d295242017-08-29 14:39:48 -07004135QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004136 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004137{
4138 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304139 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004140
4141 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304142 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004143 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144 status);
4145 return status;
4146 }
4147
Jeff Johnson57eb2732017-10-02 11:40:20 -07004148 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004149 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304150 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004151 break;
4152
4153 pCurrent = pNext;
4154 }
4155 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304156 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004157 /*
4158 * Here we are stopping global bus_bw timer & work per adapter.
4159 *
4160 * The reason is to fix one race condition between
4161 * bus bandwidth work and cleaning up an adapter.
4162 * Under some conditions, it is possible for the bus bandwidth
4163 * work to access a particularly destroyed adapter, leading to
4164 * use-after-free.
4165 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004166 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004167 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004168 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004169
4170 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004171 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4172 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004173 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004174 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304175 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004176 adapterNode = NULL;
4177
Dustin Brown5ec6b552017-03-31 12:11:40 -07004178 /* conditionally restart the bw timer */
4179 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4180
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004181 /* Adapter removed. Decrement vdev count */
4182 if (hdd_ctx->current_intf_count != 0)
4183 hdd_ctx->current_intf_count--;
4184
4185 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304186 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004187 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304188
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304189 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004190}
4191
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004192/**
4193 * hdd_close_all_adapters - Close all open adapters
4194 * @hdd_ctx: Hdd context
4195 * rtnl_held: True if RTNL lock held
4196 *
4197 * Close all open adapters.
4198 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304199 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004200 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004201QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004202{
4203 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304204 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004205
4206 ENTER();
4207
4208 do {
4209 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304210 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304211 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004212 pHddAdapterNode->adapter->macAddressCurrent.bytes);
4213 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004214 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304215 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304216 /* Adapter removed. Decrement vdev count */
4217 if (hdd_ctx->current_intf_count != 0)
4218 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004219 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304220 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221
4222 EXIT();
4223
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304224 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004225}
4226
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004227void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004228{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304229 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004231
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004232 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004233 case QDF_STA_MODE:
4234 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004235 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004236 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004237 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004238 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239 break;
4240 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004241 case QDF_SAP_MODE:
4242 case QDF_P2P_GO_MODE:
4243 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004244 {
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004245 bssid = &adapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004246 break;
4247 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004248 case QDF_FTM_MODE:
4249 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004250 default:
4251 /*
4252 * wlan_hdd_reset_prob_rspies should not have been called
4253 * for these kind of devices
4254 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004255 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004256 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004257 return;
4258 }
4259
Anurag Chouhanc5548422016-02-24 18:33:27 +05304260 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004261 updateIE.smeSessionId = adapter->sessionId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004262 updateIE.ieBufferlength = 0;
4263 updateIE.pAdditionIEBuffer = NULL;
4264 updateIE.append = true;
4265 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004266 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004267 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304268 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004269 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004270 }
4271}
4272
Jeff Johnson9d295242017-08-29 14:39:48 -07004273QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274 const bool bCloseSession)
4275{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304276 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004277 struct hdd_wext_state *pWextState =
4278 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004279 union iwreq_data wrqu;
4280 tSirUpdateIE updateIE;
4281 unsigned long rc;
4282
4283 ENTER();
4284
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004285 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304286 wlan_hdd_netif_queue_control(adapter,
4287 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4288 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004289 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004290 case QDF_STA_MODE:
4291 case QDF_P2P_CLIENT_MODE:
4292 case QDF_IBSS_MODE:
4293 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004294 case QDF_NDI_MODE:
4295 if ((QDF_NDI_MODE == adapter->device_mode) ||
4296 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004297 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4298 hdd_is_connecting(
4299 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004300 INIT_COMPLETION(adapter->disconnect_comp_var);
4301 /*
4302 * For NDI do not use pWextState from sta_ctx, if needed
4303 * extract from ndi_ctx.
4304 */
4305 if (QDF_NDI_MODE == adapter->device_mode)
4306 qdf_ret_status = sme_roam_disconnect(
4307 hdd_ctx->hHal,
4308 adapter->sessionId,
4309 eCSR_DISCONNECT_REASON_NDI_DELETE);
4310 else if (pWextState->roamProfile.BSSType ==
4311 eCSR_BSS_TYPE_START_IBSS)
4312 qdf_ret_status = sme_roam_disconnect(
4313 hdd_ctx->hHal,
4314 adapter->sessionId,
4315 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004316 else if (QDF_STA_MODE == adapter->device_mode)
4317 qdf_ret_status =
4318 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004319 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004320 qdf_ret_status = sme_roam_disconnect(
4321 hdd_ctx->hHal,
4322 adapter->sessionId,
4323 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004324 /* success implies disconnect command got
4325 * queued up successfully
4326 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004327 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4328 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004329 rc = wait_for_completion_timeout(
4330 &adapter->disconnect_comp_var,
4331 msecs_to_jiffies
4332 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004333 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004334 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004335 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004336 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4337 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338 memset(&wrqu, '\0', sizeof(wrqu));
4339 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4340 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4341 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4342 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304343 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004344 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004345
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304346 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304347 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348
4349#ifdef WLAN_OPEN_SOURCE
4350 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4351#endif
4352
4353 hdd_deregister_tx_flow_control(adapter);
4354
4355#ifdef WLAN_NS_OFFLOAD
4356#ifdef WLAN_OPEN_SOURCE
4357 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4358#endif
4359#endif
4360
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304361 if (adapter->device_mode == QDF_STA_MODE)
4362 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4363 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364 /*
4365 * It is possible that the caller of this function does not
4366 * wish to close the session
4367 */
Krunal Soni985b8132017-02-10 18:49:08 -08004368 if (true == bCloseSession) {
4369 if (0 != wlan_hdd_try_disconnect(adapter)) {
4370 hdd_err("Error: Can't disconnect adapter");
4371 return QDF_STATUS_E_FAILURE;
4372 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004373 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004374 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375 break;
4376
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004377 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304378 /* Flush IPA exception path packets */
4379 hdd_ipa_flush(hdd_ctx);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004380
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004381 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004382 if (QDF_SAP_MODE == adapter->device_mode) {
4383 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4384 cds_flush_delayed_work(
4385 &adapter->acs_pending_work);
4386 clear_bit(ACS_PENDING, &adapter->event_flags);
4387 }
4388 }
Krunal Soni22208392017-09-29 18:10:34 -07004389 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004390
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004391 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004392 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004393 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4395
4396 hdd_deregister_tx_flow_control(adapter);
4397
Kapil Guptac1224bf2017-06-22 21:22:40 +05304398 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399 mutex_lock(&hdd_ctx->sap_lock);
4400 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304401 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304402 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004403
4404 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004405 status = wlansap_stop_bss(
4406 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004407
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304408 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004409 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004410 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304411 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304412 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304413 qdf_status =
4414 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004415 qdf_stop_bss_event,
4416 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004417
Anurag Chouhance0dc992016-02-16 18:18:03 +05304418 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004419 hdd_err("failure waiting for wlansap_stop_bss %d",
4420 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004421 }
4422 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004423 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 }
4425 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004426 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4427 adapter->device_mode,
4428 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429
Anurag Chouhanc5548422016-02-24 18:33:27 +05304430 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004431 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004432 updateIE.smeSessionId = adapter->sessionId;
4433 updateIE.ieBufferlength = 0;
4434 updateIE.pAdditionIEBuffer = NULL;
4435 updateIE.append = false;
4436 updateIE.notify = false;
4437 /* Probe bcn reset */
4438 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4439 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304440 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004441 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004442 }
4443 /* Assoc resp reset */
4444 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4445 &updateIE,
4446 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304447 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004448 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004449 }
4450 /* Reset WNI_CFG_PROBE_RSP Flags */
4451 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004452 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004453 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4454 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304455 /*
4456 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4457 */
4458 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4459 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4460
Peng Xu66162de2016-02-11 17:01:20 -08004461 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004462 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004463 mutex_unlock(&hdd_ctx->sap_lock);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304464
4465#ifdef WLAN_OPEN_SOURCE
4466 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4467#endif
4468
4469#ifdef WLAN_NS_OFFLOAD
4470#ifdef WLAN_OPEN_SOURCE
4471 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4472#endif
4473#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004474 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004475 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004476 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004477 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004478 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004479 break;
4480 default:
4481 break;
4482 }
4483
4484 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304485 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486}
4487
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304488/**
4489 * hdd_deinit_all_adapters - deinit all adapters
4490 * @hdd_ctx: HDD context
4491 * @rtnl_held: True if RTNL lock held
4492 *
4493 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004494void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304495{
4496 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4497 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004498 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304499
4500 ENTER();
4501
4502 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4503
4504 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004505 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304506 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4507 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4508 adapter_node = next;
4509 }
4510
4511 EXIT();
4512}
4513
Dustin Brown27cd9942017-09-27 16:11:44 -07004514QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4515 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004516{
4517 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304518 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004519 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004520
4521 ENTER();
4522
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304523 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4524
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004525 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4526
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304527 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004528 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004529 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004530 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4531 adapterNode = pNext;
4532 }
4533
4534 EXIT();
4535
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304536 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537}
4538
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004539QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004540{
4541 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304542 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004543 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004544 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004545 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004546
4547 ENTER();
4548
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304549 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4550
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004551 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4552
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304553 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004554 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004555 hdd_notice("Disabling queues for adapter type: %d",
4556 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304557
4558 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004559 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304560 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004561 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304562
Arun Khandavallicc544b32017-01-30 19:52:16 +05304563 if (hdd_ctx->config->sap_internal_restart &&
4564 adapter->device_mode == QDF_SAP_MODE) {
4565 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304566 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304567 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004568 if (test_bit(SOFTAP_BSS_STARTED,
4569 &adapter->event_flags)) {
4570 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004571 hdd_sap_destroy_events(adapter);
4572 }
4573 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4574 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304575 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304576 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004577 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004578 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004579
Jeff Johnson690fe952017-10-25 11:48:39 -07004580 adapter->sessionCtx.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004581
4582 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004583 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4584 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004585 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4586 hdd_wmm_adapter_close(adapter);
4587 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4588 }
4589
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304590 if (adapter->device_mode == QDF_STA_MODE)
4591 hdd_clear_fils_connection_info(adapter);
4592
Wu Gao3545e642017-07-14 19:24:41 +08004593 if (adapter->device_mode == QDF_SAP_MODE) {
4594 /*
4595 * If adapter is SAP, set session ID to invalid
4596 * since SAP session will be cleanup during SSR.
4597 */
Wu Gao36717432016-11-21 15:09:48 +08004598 wlansap_set_invalid_session(
4599 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4600
Wu Gao3545e642017-07-14 19:24:41 +08004601 wlansap_cleanup_cac_timer(
4602 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4603 }
4604
Yue Mad5b4b9f2017-05-26 16:23:40 -07004605 /* Delete peers if any for STA and P2P client modes */
4606 if (adapter->device_mode == QDF_STA_MODE ||
4607 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004608 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004609 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004610 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004611
4612 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4613 peerMacAddr.bytes);
4614 }
4615
Yue Maf9782842017-05-08 12:49:49 -07004616 /* Destroy vdev which will be recreated during reinit. */
4617 hdd_vdev_destroy(adapter);
4618
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004619 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4620 adapterNode = pNext;
4621 }
4622
4623 EXIT();
4624
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304625 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004626}
4627
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004628bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304629{
4630 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4631 QDF_STATUS status;
4632 bool close_modules = true;
4633
Arun Khandavalliba479c42017-07-26 21:29:40 +05304634 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4635 hdd_info("FTM mode, don't close the module");
4636 return false;
4637 }
4638
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304639 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4640 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4641 if (test_bit(DEVICE_IFACE_OPENED,
Yeshwanth Sriram Guntuka4ce0a1b2017-10-17 17:55:45 +05304642 &adapter_node->adapter->event_flags) ||
4643 test_bit(SME_SESSION_OPENED,
4644 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004645 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304646 close_modules = false;
4647 break;
4648 }
4649 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4650 adapter_node = next;
4651 }
4652
4653 return close_modules;
4654}
4655
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304656bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304657{
4658 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4659 return true;
4660 else
4661 return false;
4662}
4663
Anurag Chouhanc4092922016-09-08 15:56:11 +05304664#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004665 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304666struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4667 struct ieee80211_channel *channel,
4668 const u8 *bssid, const u8 *ssid,
4669 size_t ssid_len)
4670{
4671 return cfg80211_get_bss(wiphy, channel, bssid,
4672 ssid, ssid_len,
4673 WLAN_CAPABILITY_ESS,
4674 WLAN_CAPABILITY_ESS);
4675}
4676#else
4677struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4678 struct ieee80211_channel *channel,
4679 const u8 *bssid, const u8 *ssid,
4680 size_t ssid_len)
4681{
4682 return cfg80211_get_bss(wiphy, channel, bssid,
4683 ssid, ssid_len,
4684 IEEE80211_BSS_TYPE_ESS,
4685 IEEE80211_PRIVACY_ANY);
4686}
4687#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304688
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304689#if defined CFG80211_CONNECT_BSS || \
4690 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304691#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304692 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304693/**
4694 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4695 * @timeout_reason: reason for connect timeout
4696 *
4697 * This function is used to convert host timeout
4698 * reason enum to kernel specific enum.
4699 *
4700 * Return: nl timeout enum
4701 */
4702static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4703 tSirResultCodes timeout_reason)
4704{
4705 switch (timeout_reason) {
4706 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4707 return NL80211_TIMEOUT_SCAN;
4708 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4709 return NL80211_TIMEOUT_AUTH;
4710 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4711 return NL80211_TIMEOUT_ASSOC;
4712 default:
4713 return NL80211_TIMEOUT_UNSPECIFIED;
4714 }
4715}
4716
4717/**
4718 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4719 * @dev: network device
4720 * @bssid: bssid to which we want to associate
4721 * @timeout_reason: reason for connect timeout
4722 *
4723 * This API is used to send connection timeout reason to supplicant
4724 *
4725 * Return: void
4726 */
4727static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4728 const u8 *bssid,
4729 tSirResultCodes timeout_reason)
4730{
4731 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004732
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304733 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4734
4735 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4736 nl_timeout_reason);
4737}
4738
4739/**
4740 * __hdd_connect_bss() - API to send connection status to supplicant
4741 * @dev: network device
4742 * @bssid: bssid to which we want to associate
4743 * @req_ie: Request Information Element
4744 * @req_ie_len: len of the req IE
4745 * @resp_ie: Response IE
4746 * @resp_ie_len: len of ht response IE
4747 * @status: status
4748 * @gfp: Kernel Flag
4749 * @timeout_reason: reason for connect timeout
4750 *
4751 * Return: void
4752 */
4753static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4754 struct cfg80211_bss *bss, const u8 *req_ie,
4755 size_t req_ie_len, const u8 *resp_ie,
4756 size_t resp_ie_len, int status, gfp_t gfp,
4757 tSirResultCodes timeout_reason)
4758{
4759 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004760
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304761 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4762
4763 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4764 resp_ie, resp_ie_len, status, gfp,
4765 nl_timeout_reason);
4766}
4767#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304768#if defined CFG80211_CONNECT_TIMEOUT || \
4769 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304770static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4771 const u8 *bssid,
4772 tSirResultCodes timeout_reason)
4773{
4774 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4775}
4776#endif
4777
4778static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4779 struct cfg80211_bss *bss, const u8 *req_ie,
4780 size_t req_ie_len, const u8 *resp_ie,
4781 size_t resp_ie_len, int status, gfp_t gfp,
4782 tSirResultCodes timeout_reason)
4783{
4784 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4785 resp_ie, resp_ie_len, status, gfp);
4786}
4787#endif
4788
Abhishek Singha84d3952016-09-13 13:45:05 +05304789/**
4790 * hdd_connect_bss() - API to send connection status to supplicant
4791 * @dev: network device
4792 * @bssid: bssid to which we want to associate
4793 * @req_ie: Request Information Element
4794 * @req_ie_len: len of the req IE
4795 * @resp_ie: Response IE
4796 * @resp_ie_len: len of ht response IE
4797 * @status: status
4798 * @gfp: Kernel Flag
4799 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304800 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304801 *
4802 * The API is a wrapper to send connection status to supplicant
4803 *
4804 * Return: Void
4805 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304806#if defined CFG80211_CONNECT_TIMEOUT || \
4807 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05304808static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4809 struct cfg80211_bss *bss, const u8 *req_ie,
4810 size_t req_ie_len, const u8 *resp_ie,
4811 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304812 bool connect_timeout,
4813 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304814{
4815 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304816 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304817 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304818 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4819 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304820}
4821#else
4822static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4823 struct cfg80211_bss *bss, const u8 *req_ie,
4824 size_t req_ie_len, const u8 *resp_ie,
4825 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304826 bool connect_timeout,
4827 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304828{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304829 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4830 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304831}
4832#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304833
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304834#if defined(WLAN_FEATURE_FILS_SK)
4835#if defined(CFG80211_CONNECT_DONE) || \
4836 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
4837#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
4838 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304839/**
4840 * hdd_populate_fils_params() - Populate FILS keys to connect response
4841 * @fils_params: connect response to supplicant
4842 * @fils_kek: FILS kek
4843 * @fils_kek_len: FILS kek length
4844 * @pmk: FILS PMK
4845 * @pmk_len: FILS PMK length
4846 * @pmkid: PMKID
4847 * @fils_seq_num: FILS Seq number
4848 *
4849 * Return: None
4850 */
4851static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4852 *fils_params, const uint8_t *fils_kek,
4853 size_t fils_kek_len, const uint8_t *pmk,
4854 size_t pmk_len, const uint8_t *pmkid,
4855 uint16_t fils_seq_num)
4856{
4857 /* Increament seq number to be used for next FILS */
4858 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4859 fils_params->update_erp_next_seq_num = true;
4860 fils_params->fils_kek = fils_kek;
4861 fils_params->fils_kek_len = fils_kek_len;
4862 fils_params->pmk = pmk;
4863 fils_params->pmk_len = pmk_len;
4864 fils_params->pmkid = pmkid;
4865}
4866#else
4867static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4868 *fils_params, const uint8_t
4869 *fils_kek, size_t fils_kek_len,
4870 const uint8_t *pmk, size_t pmk_len,
4871 const uint8_t *pmkid,
4872 uint16_t fils_seq_num)
4873{ }
4874#endif
4875
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304876void hdd_update_hlp_info(struct net_device *dev, tCsrRoamInfo *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304877{
4878 struct sk_buff *skb;
4879 uint16_t skb_len;
4880 struct llc_snap_hdr_t *llc_hdr;
4881 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304882 uint8_t *hlp_data;
4883 uint16_t hlp_data_len;
4884 struct fils_join_rsp_params *roam_fils_params
4885 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304886 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
4887
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304888 if (!roam_fils_params) {
4889 hdd_err("FILS Roam Param NULL");
4890 return;
4891 }
4892
4893 if (!roam_fils_params->hlp_data_len || !roam_fils_params->hlp_data) {
4894 hdd_err("FILS HLP Data NULL, len %d",
4895 roam_fils_params->hlp_data_len);
4896 return;
4897 }
4898
4899 hlp_data = roam_fils_params->hlp_data;
4900 hlp_data_len = roam_fils_params->hlp_data_len;
4901
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304902 /* Calculate skb length */
4903 skb_len = (2 * ETH_ALEN) + hlp_data_len;
4904 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
4905 if (skb == NULL) {
4906 hdd_err("HLP packet nbuf alloc fails");
4907 return;
4908 }
4909
4910 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
4911 QDF_MAC_ADDR_SIZE);
4912 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
4913 QDF_MAC_ADDR_SIZE);
4914
4915 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
4916 if (IS_SNAP(llc_hdr)) {
4917 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4918 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4919 }
4920
4921 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
4922
4923 /*
4924 * This HLP packet is formed from HLP info encapsulated
4925 * in assoc response frame which is AEAD encrypted.
4926 * Hence, this checksum validation can be set unnecessary.
4927 * i.e. network layer need not worry about checksum.
4928 */
4929 skb->ip_summed = CHECKSUM_UNNECESSARY;
4930
4931 status = hdd_rx_packet_cbk(padapter, skb);
4932 if (QDF_IS_STATUS_ERROR(status)) {
4933 hdd_err("Sending HLP packet fails");
4934 return;
4935 }
4936 hdd_debug("send HLP packet to netif successfully");
4937}
4938
4939/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304940 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4941 * @dev: network device
4942 * @bssid: bssid to which we want to associate
4943 * @bss: cfg80211 bss info
4944 * @roam_info: information about connected bss
4945 * @req_ie: Request Information Element
4946 * @req_ie_len: len of the req IE
4947 * @resp_ie: Response IE
4948 * @resp_ie_len: len of ht response IE
4949 * @status: status
4950 * @gfp: allocation flags
4951 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4952 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304953 *
4954 * This API is used as wrapper to send FILS key/sequence number
4955 * params etc. to supplicant in case of FILS connection
4956 *
4957 * Return: None
4958 */
4959static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4960 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4961 const u8 *req_ie, size_t req_ie_len,
4962 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004963 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304964 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304965{
4966 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304967 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
4968 struct fils_join_rsp_params *roam_fils_params =
4969 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004970
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304971 qdf_mem_zero(&fils_params, sizeof(fils_params));
4972
4973 if (!roam_fils_params) {
4974 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4975 } else {
4976 fils_params.status = status;
4977 fils_params.bssid = bssid;
4978 fils_params.timeout_reason = timeout_reason;
4979 fils_params.req_ie = req_ie;
4980 fils_params.req_ie_len = req_ie_len;
4981 fils_params.resp_ie = resp_ie;
4982 fils_params.resp_ie_len = resp_ie_len;
4983 fils_params.bss = bss;
4984 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4985 roam_fils_params->kek_len,
4986 roam_fils_params->fils_pmk,
4987 roam_fils_params->fils_pmk_len,
4988 roam_fils_params->fils_pmkid,
4989 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05304990 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304991 }
4992 hdd_debug("FILS indicate connect status %d seq no %d",
4993 fils_params.status,
4994 fils_params.fils_erp_next_seq_num);
4995
4996 cfg80211_connect_done(dev, &fils_params, gfp);
4997
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304998 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304999 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305000
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305001 /* Clear all the FILS key info */
5002 if (roam_fils_params && roam_fils_params->fils_pmk)
5003 qdf_mem_free(roam_fils_params->fils_pmk);
5004 if (roam_fils_params)
5005 qdf_mem_free(roam_fils_params);
5006 roam_info->fils_join_rsp = NULL;
5007}
5008#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005009static inline void
5010hdd_connect_done(struct net_device *dev, const u8 *bssid,
5011 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
5012 const u8 *req_ie, size_t req_ie_len,
5013 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5014 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305015 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305016{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305017#endif
5018#endif
5019
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305020#if defined(WLAN_FEATURE_FILS_SK) && \
5021 (defined(CFG80211_CONNECT_DONE) || \
5022 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305023/**
5024 * hdd_fils_update_connect_results() - API to send fils connection status to
5025 * supplicant.
5026 * @dev: network device
5027 * @bssid: bssid to which we want to associate
5028 * @bss: cfg80211 bss info
5029 * @roam_info: information about connected bss
5030 * @req_ie: Request Information Element
5031 * @req_ie_len: len of the req IE
5032 * @resp_ie: Response IE
5033 * @resp_ie_len: len of ht response IE
5034 * @status: status
5035 * @gfp: allocation flags
5036 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5037 * @timeout_reason: reason for connect timeout
5038 *
5039 * The API is a wrapper to send connection status to supplicant
5040 *
5041 * Return: 0 if success else failure
5042 */
5043static int hdd_fils_update_connect_results(struct net_device *dev,
5044 const u8 *bssid,
5045 struct cfg80211_bss *bss,
5046 tCsrRoamInfo *roam_info, const u8 *req_ie,
5047 size_t req_ie_len, const u8 *resp_ie,
5048 size_t resp_ie_len, u16 status, gfp_t gfp,
5049 bool connect_timeout,
5050 tSirResultCodes timeout_reason)
5051{
5052 ENTER();
5053 if (!roam_info || !roam_info->is_fils_connection)
5054 return -EINVAL;
5055
5056 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5057 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305058 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305059 return 0;
5060}
5061#else
5062static inline int hdd_fils_update_connect_results(struct net_device *dev,
5063 const u8 *bssid,
5064 struct cfg80211_bss *bss,
5065 tCsrRoamInfo *roam_info, const u8 *req_ie,
5066 size_t req_ie_len, const u8 *resp_ie,
5067 size_t resp_ie_len, u16 status, gfp_t gfp,
5068 bool connect_timeout,
5069 tSirResultCodes timeout_reason)
5070{
5071 return -EINVAL;
5072}
5073#endif
5074
Anurag Chouhanc4092922016-09-08 15:56:11 +05305075/**
5076 * hdd_connect_result() - API to send connection status to supplicant
5077 * @dev: network device
5078 * @bssid: bssid to which we want to associate
5079 * @roam_info: information about connected bss
5080 * @req_ie: Request Information Element
5081 * @req_ie_len: len of the req IE
5082 * @resp_ie: Response IE
5083 * @resp_ie_len: len of ht response IE
5084 * @status: status
5085 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305086 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305087 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305088 *
5089 * The API is a wrapper to send connection status to supplicant
5090 * and allow runtime suspend
5091 *
5092 * Return: Void
5093 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305094void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5095 tCsrRoamInfo *roam_info, const u8 *req_ie,
5096 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305097 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305098 bool connect_timeout,
5099 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305100{
Jeff Johnson9d295242017-08-29 14:39:48 -07005101 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305102 struct cfg80211_bss *bss = NULL;
5103
5104 if (WLAN_STATUS_SUCCESS == status) {
5105 struct ieee80211_channel *chan;
5106 int freq;
5107 int chan_no = roam_info->pBssDesc->channelId;
5108
5109 if (chan_no <= 14)
5110 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005111 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305112 else
5113 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005114 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305115
5116 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5117 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5118 roam_info->u.pConnectedProfile->SSID.ssId,
5119 roam_info->u.pConnectedProfile->SSID.length);
5120 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305121
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305122 if (hdd_fils_update_connect_results(dev, bssid, bss,
5123 roam_info, req_ie, req_ie_len, resp_ie,
5124 resp_ie_len, status, gfp, connect_timeout,
5125 timeout_reason) != 0) {
5126 hdd_connect_bss(dev, bssid, bss, req_ie,
5127 req_ie_len, resp_ie, resp_ie_len,
5128 status, gfp, connect_timeout, timeout_reason);
5129 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305130
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005131 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005132 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305133}
5134#else
5135void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5136 tCsrRoamInfo *roam_info, const u8 *req_ie,
5137 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305138 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305139 bool connect_timeout,
5140 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305141{
Jeff Johnson9d295242017-08-29 14:39:48 -07005142 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305143
Anurag Chouhanc4092922016-09-08 15:56:11 +05305144 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5145 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005146
5147 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005148 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305149}
5150#endif
5151
5152
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005153QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005154{
5155 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305156 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005157 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005158#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305159 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005160#endif
5161 eConnectionState connState;
5162
5163 ENTER();
5164
5165 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305166 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005167 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005168
Arun Khandavallifae92942016-08-01 13:31:08 +05305169 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305170 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305171
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005172 hdd_wmm_init(adapter);
5173
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005174 adapter->scan_info.mScanPending = false;
5175
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005177 case QDF_STA_MODE:
5178 case QDF_P2P_CLIENT_MODE:
5179 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005180
5181 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5182 ->conn_info.connState;
5183
5184 hdd_init_station_mode(adapter);
5185 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005186 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005187
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005188 /* Indicate disconnect event to supplicant
5189 * if associated previously
5190 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005191 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005192 eConnectionState_IbssConnected == connState ||
5193 eConnectionState_NotConnected == connState ||
5194 eConnectionState_IbssDisconnected == connState ||
5195 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005197
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198 memset(&wrqu, '\0', sizeof(wrqu));
5199 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5200 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5201 wireless_send_event(adapter->dev, SIOCGIWAP,
5202 &wrqu, NULL);
5203 adapter->sessionCtx.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005204 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205
5206 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305207 wlan_hdd_cfg80211_indicate_disconnect(
5208 adapter->dev, false,
5209 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 } else if (eConnectionState_Connecting == connState) {
5211 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005212 * Indicate connect failure to supplicant if we
5213 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005214 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305215 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305216 NULL, 0, NULL, 0,
5217 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005218 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005219 }
5220
5221 hdd_register_tx_flow_control(adapter,
5222 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005223 hdd_tx_resume_cb,
5224 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225
5226 break;
5227
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005228 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005229 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305230 hdd_init_ap_mode(adapter, true);
5231
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005232 break;
5233
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005234 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005235#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005236 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005237 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5238#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005239 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240 /* event supplicant to restart */
5241 cfg80211_del_sta(adapter->dev,
5242 (const u8 *)&bcastMac.bytes[0],
5243 GFP_KERNEL);
5244#endif
5245 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305246 case QDF_MONITOR_MODE:
5247 hdd_init_station_mode(adapter);
5248 hdd_set_mon_rx_cb(adapter->dev);
5249 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5250 adapter->mon_bandwidth);
5251 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252 default:
5253 break;
5254 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005255 /*
5256 * Action frame registered in one adapter which will
5257 * applicable to all interfaces
5258 */
5259 wlan_hdd_cfg80211_register_frames(adapter);
5260
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305261get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5263 adapterNode = pNext;
5264 }
5265
5266 EXIT();
5267
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305268 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005269}
5270
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005271QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005272 hdd_adapter_list_node_t **padapterNode)
5273{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305274 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005275
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005276 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305277 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5278 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005279 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005280 return status;
5281}
5282
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005283QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284 hdd_adapter_list_node_t *adapterNode,
5285 hdd_adapter_list_node_t **pNextAdapterNode)
5286{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305287 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005288
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005289 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305290 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5291 (qdf_list_node_t *) adapterNode,
5292 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005293
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005294 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005295 return status;
5296}
5297
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005298QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005299 hdd_adapter_list_node_t *adapterNode)
5300{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305301 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005302
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005303 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305304 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005306 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005307 return status;
5308}
5309
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005310QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005311 hdd_adapter_list_node_t **padapterNode)
5312{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305313 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005314
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005315 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305316 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5317 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005318 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319 return status;
5320}
5321
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005322QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005323 hdd_adapter_list_node_t *adapterNode)
5324{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305325 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005326
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005327 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305328 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5329 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005330 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005331 return status;
5332}
5333
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005334QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005335 hdd_adapter_list_node_t *adapterNode)
5336{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305337 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005338
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005339 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305340 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5341 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005342 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005343 return status;
5344}
5345
Jeff Johnson9d295242017-08-29 14:39:48 -07005346struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005347 tSirMacAddr macAddr)
5348{
5349 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005350 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305351 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005352
5353 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5354
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305355 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005356 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005357
5358 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305359 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005360 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005361 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005362
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005363 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5364 adapterNode = pNext;
5365 }
5366
5367 return NULL;
5368
5369}
5370
Jeff Johnson9d295242017-08-29 14:39:48 -07005371struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005372 uint32_t vdev_id)
5373{
5374 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005375 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305376 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005377
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305378 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005379
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305380 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005381 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005382
5383 if (adapter->sessionId == vdev_id)
5384 return adapter;
5385
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305386 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005387 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5388 adapterNode = pNext;
5389 }
5390
Jeff Johnson5880d792016-08-15 13:32:30 -07005391 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392
5393 return NULL;
5394}
5395
Abhishek Singh7996eb72015-12-30 17:24:02 +05305396/**
5397 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5398 * the sessionid
5399 * @hdd_ctx: hdd context.
5400 * @sme_session_id: sme session is for the adapter to get.
5401 *
5402 * This function is used to get the adapter with provided session id
5403 *
5404 * Return: adapter pointer if found
5405 *
5406 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005407struct hdd_adapter *
5408hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5409 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305410{
5411 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005412 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305413 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305414
5415
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305416 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305417
5418 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305419 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005420 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305421
5422 if (adapter &&
5423 adapter->sessionId == sme_session_id)
5424 return adapter;
5425
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305426 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305427 hdd_get_next_adapter(hdd_ctx,
5428 adapter_node, &next);
5429 adapter_node = next;
5430 }
5431 return NULL;
5432}
5433
Jeff Johnson9d295242017-08-29 14:39:48 -07005434struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005435 const char *iface_name)
5436{
5437 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005438 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005439 QDF_STATUS qdf_status;
5440
5441 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5442
5443 while ((NULL != adapter_node) &&
5444 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005445 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005446
5447 if (adapter &&
5448 !qdf_str_cmp(adapter->dev->name, iface_name))
5449 return adapter;
5450
5451 qdf_status =
5452 hdd_get_next_adapter(hdd_ctx,
5453 adapter_node, &next);
5454 adapter_node = next;
5455 }
5456 return NULL;
5457}
5458
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005459/**
5460 * hdd_get_adapter() - to get adapter matching the mode
5461 * @hdd_ctx: hdd context
5462 * @mode: adapter mode
5463 *
5464 * This routine will return the pointer to adapter matching
5465 * with the passed mode.
5466 *
5467 * Return: pointer to adapter or null
5468 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005469struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005470 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005471{
5472 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005473 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305474 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005475
5476 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5477
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305478 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005479 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005480
5481 if (adapter && (mode == adapter->device_mode))
5482 return adapter;
5483
5484 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5485 adapterNode = pNext;
5486 }
5487
5488 return NULL;
5489
5490}
5491
5492/**
5493 * hdd_get_operating_channel() - return operating channel of the device mode
5494 * @hdd_ctx: Pointer to the HDD context.
5495 * @mode: Device mode for which operating channel is required.
5496 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005497 * QDF_STA_MODE,
5498 * QDF_P2P_CLIENT_MODE,
5499 * QDF_SAP_MODE,
5500 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005501 *
5502 * This API returns the operating channel of the requested device mode
5503 *
5504 * Return: channel number. "0" id the requested device is not found OR it is
5505 * not connected.
5506 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005507uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005508 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005509{
5510 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305511 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005512 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005513 uint8_t operatingChannel = 0;
5514
5515 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5516
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305517 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005518 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005519
5520 if (mode == adapter->device_mode) {
5521 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005522 case QDF_STA_MODE:
5523 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005524 if (hdd_conn_is_connected
5525 (WLAN_HDD_GET_STATION_CTX_PTR
5526 (adapter))) {
5527 operatingChannel =
5528 (WLAN_HDD_GET_STATION_CTX_PTR
5529 (adapter))->conn_info.
5530 operationChannel;
5531 }
5532 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005533 case QDF_SAP_MODE:
5534 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005535 /* softap connection info */
5536 if (test_bit
5537 (SOFTAP_BSS_STARTED,
5538 &adapter->event_flags))
5539 operatingChannel =
5540 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005541 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005542 break;
5543 default:
5544 break;
5545 }
5546
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005547 /* Found the device of interest. break the loop */
5548 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005549 }
5550
5551 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5552 adapterNode = pNext;
5553 }
5554 return operatingChannel;
5555}
5556
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005557static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005558 hdd_ctx)
5559{
5560 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305561 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005562 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005563
5564 ENTER();
5565
5566 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5567
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305568 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005569 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005570 if ((adapter->device_mode == QDF_STA_MODE) ||
5571 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5572 (adapter->device_mode == QDF_IBSS_MODE) ||
5573 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5574 (adapter->device_mode == QDF_SAP_MODE) ||
5575 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005576 wlan_hdd_cfg80211_deregister_frames(adapter);
5577 hdd_unregister_wext(adapter->dev);
5578 }
5579 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5580 adapterNode = pNext;
5581 }
5582
5583 EXIT();
5584
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305585 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005586}
5587
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005588QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005589{
5590 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305591 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005592 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005593
5594 ENTER();
5595
5596 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5597
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305598 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005599 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005600 if ((adapter->device_mode == QDF_STA_MODE) ||
5601 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5602 (adapter->device_mode == QDF_IBSS_MODE) ||
5603 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5604 (adapter->device_mode == QDF_SAP_MODE) ||
5605 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005606 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5607 adapter->sessionId, INVALID_SCAN_ID,
5608 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005609 }
5610 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5611 adapterNode = pNext;
5612 }
5613
5614 EXIT();
5615
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305616 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005617}
5618
Dustin Brownf27bce82016-11-03 12:52:27 -07005619/**
5620 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5621 * adapters
5622 * @hdd_ctx: The HDD context containing the adapters to operate on
5623 *
5624 * return: QDF_STATUS_SUCCESS
5625 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005626static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005627{
5628 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5629 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005630 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005631 int err;
5632
5633 ENTER();
5634
5635 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5636
5637 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005638 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005639 if ((adapter->device_mode == QDF_STA_MODE) ||
5640 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5641 (adapter->device_mode == QDF_IBSS_MODE) ||
5642 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5643 (adapter->device_mode == QDF_SAP_MODE) ||
5644 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5645 err = wlan_hdd_sched_scan_stop(adapter->dev);
5646 if (err)
5647 hdd_err("Unable to stop scheduled scan");
5648 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005649 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5650 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005651 adapter_node = next_node;
5652 }
5653
5654 EXIT();
5655
5656 return QDF_STATUS_SUCCESS;
5657}
5658
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005659#ifdef WLAN_NS_OFFLOAD
5660/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005661 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005662 * @hdd_ctx: Pointer to hdd context
5663 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005664 * Unregister for IPv6 address change notifications.
5665 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005666 * Return: None
5667 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005668static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005669{
5670 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671}
5672
5673/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005674 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005675 * @hdd_ctx: Pointer to hdd context
5676 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005677 * Register for IPv6 address change notifications.
5678 *
5679 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005680 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005681static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005682{
5683 int ret;
5684
5685 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5686 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005687 if (ret) {
5688 hdd_err("Failed to register IPv6 notifier: %d", ret);
5689 goto out;
5690 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005691
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005692 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005693out:
5694 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005695}
5696#else
5697/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005698 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005699 * @hdd_ctx: Pointer to hdd context
5700 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005701 * Unregister for IPv6 address change notifications.
5702 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703 * Return: None
5704 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005705static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005706{
5707}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005708
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005709/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005710 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005711 * @hdd_ctx: Pointer to hdd context
5712 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005713 * Register for IPv6 address change notifications.
5714 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715 * Return: None
5716 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005717static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005718{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005719 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005720}
5721#endif
5722
5723/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005724 * hdd_register_notifiers - Register netdev notifiers.
5725 * @hdd_ctx: HDD context
5726 *
5727 * Register netdev notifiers like IPv4 and IPv6.
5728 *
5729 * Return: 0 on success and errno on failure
5730 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005731static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005732{
5733 int ret;
5734
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005735 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5736 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305737 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005738
5739 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5740 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5741 if (ret) {
5742 hdd_err("Failed to register IPv4 notifier: %d", ret);
5743 goto unregister_ip6_notifier;
5744 }
5745
5746 return 0;
5747
5748unregister_ip6_notifier:
5749 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005750out:
5751 return ret;
5752
5753}
5754
5755/**
5756 * hdd_unregister_notifiers - Unregister netdev notifiers.
5757 * @hdd_ctx: HDD context
5758 *
5759 * Unregister netdev notifiers like IPv4 and IPv6.
5760 *
5761 * Return: None.
5762 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005763void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005764{
5765 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5766
5767 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005768}
5769
5770/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005771 * hdd_exit_netlink_services - Exit netlink services
5772 * @hdd_ctx: HDD context
5773 *
5774 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5775 * nl service.
5776 *
5777 * Return: None.
5778 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005779static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005780{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005781 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005782 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005783 ptt_sock_deactivate_svc();
5784
5785 nl_srv_exit();
5786}
5787
5788/**
5789 * hdd_init_netlink_services- Init netlink services
5790 * @hdd_ctx: HDD context
5791 *
5792 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5793 * nl service.
5794 *
5795 * Return: 0 on success and errno on failure.
5796 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005797static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005798{
5799 int ret;
5800
Ryan Hsuceddceb2016-04-28 10:20:14 -07005801 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005802 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005803 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005804 goto out;
5805 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005806 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005807
Naveen Rawat910726a2017-03-06 11:42:51 -08005808 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005809 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005810 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005811 goto err_nl_srv;
5812 }
5813
5814 ret = ptt_sock_activate_svc();
5815 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005816 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005817 goto err_nl_srv;
5818 }
5819
5820 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005821 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005822 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005823
5824 ret = cnss_diag_activate_service();
5825 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005826 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005827 goto err_close_cesium;
5828 }
5829
5830 return 0;
5831
5832err_close_cesium:
5833 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005834 ptt_sock_deactivate_svc();
5835err_nl_srv:
5836 nl_srv_exit();
5837out:
5838 return ret;
5839}
5840
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005841/**
5842 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5843 * @hdd_ctx: HDD context.
5844 *
5845 * Destroy RX wakelock.
5846 *
5847 * Return: None.
5848 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005849static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005850{
5851 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5852}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005853
5854/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005855 * hdd_rx_wake_lock_create() - Create RX wakelock
5856 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005857 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005858 * Create RX wakelock.
5859 *
5860 * Return: None.
5861 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005862static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005863{
5864 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5865}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005866
5867/**
Houston Hoffman160db392016-10-10 17:37:51 -07005868 * hdd_context_deinit() - Deinitialize HDD context
5869 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005870 *
Houston Hoffman160db392016-10-10 17:37:51 -07005871 * Deinitialize HDD context along with all the feature specific contexts but
5872 * do not free hdd context itself. Caller of this API is supposed to free
5873 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005874 *
Houston Hoffman160db392016-10-10 17:37:51 -07005875 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005876 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005877static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005878{
Houston Hoffman160db392016-10-10 17:37:51 -07005879 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005880
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005881 hdd_sap_context_destroy(hdd_ctx);
5882
5883 hdd_rx_wake_lock_destroy(hdd_ctx);
5884
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005885 hdd_scan_context_destroy(hdd_ctx);
5886
5887 qdf_list_destroy(&hdd_ctx->hddAdapters);
5888
Houston Hoffman160db392016-10-10 17:37:51 -07005889 return 0;
5890}
5891
5892/**
5893 * hdd_context_destroy() - Destroy HDD context
5894 * @hdd_ctx: HDD context to be destroyed.
5895 *
5896 * Free config and HDD context as well as destroy all the resources.
5897 *
5898 * Return: None
5899 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005900static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005901{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005902 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305903
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305904 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5905
Houston Hoffman160db392016-10-10 17:37:51 -07005906 hdd_context_deinit(hdd_ctx);
5907
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305908 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005909 hdd_ctx->config = NULL;
5910
5911 wiphy_free(hdd_ctx->wiphy);
5912}
5913
5914/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305915 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5916 *
5917 * This function is used to destroy bug report lock
5918 *
5919 * Return: None
5920 */
5921static void wlan_destroy_bug_report_lock(void)
5922{
5923 p_cds_contextType p_cds_context;
5924
5925 p_cds_context = cds_get_global_context();
5926 if (!p_cds_context) {
5927 hdd_err("cds context is NULL");
5928 return;
5929 }
5930
5931 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5932}
5933
5934/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005935 * hdd_wlan_exit() - HDD WLAN exit function
5936 * @hdd_ctx: Pointer to the HDD Context
5937 *
5938 * This is the driver exit point (invoked during rmmod)
5939 *
5940 * Return: None
5941 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005942static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005943{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305944 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005945 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305946 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005947
5948 ENTER();
5949
Arun Khandavallifae92942016-08-01 13:31:08 +05305950 if (QDF_TIMER_STATE_RUNNING ==
5951 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005952 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305953 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954 }
5955
Arun Khandavallifae92942016-08-01 13:31:08 +05305956 if (!QDF_IS_STATUS_SUCCESS
5957 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5958 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005959
Arun Khandavallifae92942016-08-01 13:31:08 +05305960
5961 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005962
Prashanth Bhattaab004382016-10-11 16:08:11 -07005963 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005964
5965#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305966 if (QDF_TIMER_STATE_RUNNING ==
5967 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5968 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005969 }
5970
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305971 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305972 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005973 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005974 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005975 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5976 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5977 hdd_ctx->last_acs_channel_list = NULL;
5978 hdd_ctx->num_of_channels = 0;
5979 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005981
Arun Khandavallifae92942016-08-01 13:31:08 +05305982 mutex_lock(&hdd_ctx->iface_change_lock);
5983 driver_status = hdd_ctx->driver_status;
5984 mutex_unlock(&hdd_ctx->iface_change_lock);
5985
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005986 /*
5987 * Powersave Offload Case
5988 * Disable Idle Power Save Mode
5989 */
5990 hdd_set_idle_ps_config(hdd_ctx, false);
5991
Arun Khandavallifae92942016-08-01 13:31:08 +05305992 if (driver_status != DRIVER_MODULES_CLOSED) {
5993 hdd_unregister_wext_all_adapters(hdd_ctx);
5994 /*
5995 * Cancel any outstanding scan requests. We are about to close
5996 * all of our adapters, but an adapter structure is what SME
5997 * passes back to our callback function. Hence if there
5998 * are any outstanding scan requests then there is a
5999 * race condition between when the adapter is closed and
6000 * when the callback is invoked. We try to resolve that
6001 * race condition here by canceling any outstanding scans
6002 * before we close the adapters.
6003 * Note that the scans may be cancelled in an asynchronous
6004 * manner, so ideally there needs to be some kind of
6005 * synchronization. Rather than introduce a new
6006 * synchronization here, we will utilize the fact that we are
6007 * about to Request Full Power, and since that is synchronized,
6008 * the expectation is that by the time Request Full Power has
6009 * completed, all scans will be cancelled
6010 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07006011 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05306012 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006013 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006014 hdd_stop_all_adapters(hdd_ctx, true);
bings29c99862017-11-01 13:54:13 +08006015 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006016 }
6017
6018 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306019 * Close the scheduler before calling cds_close to make sure
6020 * no thread is scheduled after the each module close is
6021 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006022 */
Jeff Johnson7d562272017-09-13 15:12:54 -07006023 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306024 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05306025 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306026 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006027 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006028
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306029 unregister_netdevice_notifier(&hdd_netdev_notifier);
6030
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006031 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306032
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306033 qdf_nbuf_deinit_replenish_timer();
6034
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306035 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6036 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6037 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6038
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006039 /*
6040 * Close CDS
6041 * This frees pMac(HAL) context. There should not be any call
6042 * that requires pMac access after this.
6043 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006045 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006046 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006047
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006048 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006049
6050 hdd_ipa_cleanup(hdd_ctx);
6051
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306052 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306053 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306054 /*
6055 * If there is re_init failure wiphy would have already de-registered
6056 * check the wiphy status before un-registering again
6057 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306058 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306059 wiphy_unregister(wiphy);
6060 wlan_hdd_cfg80211_deinit(wiphy);
6061 hdd_lpass_notify_stop(hdd_ctx);
6062 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006063
Arun Khandavallifae92942016-08-01 13:31:08 +05306064 hdd_exit_netlink_services(hdd_ctx);
6065 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306066#ifdef FEATURE_WLAN_CH_AVOID
6067 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6068#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306069
6070 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6071 if (driver_status)
6072 hdd_err("Pdev delete failed");
6073
6074 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6075 if (driver_status)
6076 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006077
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006078 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006079}
6080
6081void __hdd_wlan_exit(void)
6082{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006083 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006084
6085 ENTER();
6086
Anurag Chouhan6d760662016-02-20 16:05:43 +05306087 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006088 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006089 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006090 EXIT();
6091 return;
6092 }
6093
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006094 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306095 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006096
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006097 /* Do all the cleanup before deregistering the driver */
6098 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006099
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006100 EXIT();
6101}
6102
6103#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006104/**
6105 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006106 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006107 *
6108 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6109 * Then new ACS request will do a fresh scan without reusing the cached
6110 * scan information.
6111 *
6112 * Return: void
6113 */
Tang Yingying523322d2017-01-17 23:28:43 +08006114static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006115{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006116 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006117
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006118 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006119 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006120 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6121 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6122 hdd_ctx->last_acs_channel_list = NULL;
6123 hdd_ctx->num_of_channels = 0;
6124 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006125
6126 if (!hdd_ctx->hHal)
6127 return;
6128 sme_scan_flush_result(hdd_ctx->hHal);
6129}
6130#endif
6131
6132#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006133int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6134 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006135{
6136 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306137 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006138 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006139
6140 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6141
6142 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306143 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006144 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306145
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006146 if (!hdd_ctx->hHal)
6147 return -EINVAL;
6148
Jeff Johnsone7672e72017-10-21 15:10:04 -07006149 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006150 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306151 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006152 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006153 return -EINVAL;
6154 }
6155
6156 return 0;
6157}
6158#endif
6159
6160/**
6161 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6162 * @state: state
6163 *
6164 * This function notifies FW with modem power status
6165 *
6166 * Return: 0 if successful, error number otherwise
6167 */
6168int hdd_wlan_notify_modem_power_state(int state)
6169{
6170 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306171 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006172 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173
Anurag Chouhan6d760662016-02-20 16:05:43 +05306174 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006175 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306176 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006177 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306178
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006179 if (!hdd_ctx->hHal)
6180 return -EINVAL;
6181
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306182 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6183 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006184 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006185 state);
6186 return -EINVAL;
6187 }
6188 return 0;
6189}
6190
6191/**
6192 *
6193 * hdd_post_cds_enable_config() - HDD post cds start config helper
6194 * @adapter - Pointer to the HDD
6195 *
6196 * Return: None
6197 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006198QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006199{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306200 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006201
6202 /*
6203 * Send ready indication to the HDD. This will kick off the MAC
6204 * into a 'running' state and should kick off an initial scan.
6205 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306206 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6207 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006208 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6209 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306210 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211 }
6212
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306213 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006214}
6215
6216/* wake lock APIs for HDD */
6217void hdd_prevent_suspend(uint32_t reason)
6218{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306219 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220}
6221
6222void hdd_allow_suspend(uint32_t reason)
6223{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306224 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006225}
6226
6227void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6228{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306229 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6230 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006231}
6232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006233/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006234QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006235{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006236
Amar Singhal6f8592b2017-04-26 14:31:58 -07006237 return sme_init_chan_list(hdd_ctx->hHal,
6238 hdd_ctx->reg.alpha2,
6239 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240}
6241
6242/**
6243 * hdd_is_5g_supported() - check if hardware supports 5GHz
6244 * @hdd_ctx: Pointer to the hdd context
6245 *
6246 * HDD function to know if hardware supports 5GHz
6247 *
6248 * Return: true if hardware supports 5GHz
6249 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006250bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006252 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006253 return true;
6254
Amar Singhal58b45ef2017-08-01 13:43:54 -07006255 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006256 return true;
6257 else
6258 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006259}
6260
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006261static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006262{
6263 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006264 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006265
6266 wiphy = hdd_ctx->wiphy;
6267
6268 /*
6269 * The channel information in
6270 * wiphy needs to be initialized before wiphy registration
6271 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006272 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6273 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006274 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006275 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006276 }
6277
6278#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6279 wiphy->wowlan = &wowlan_support_reg_init;
6280#else
6281 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6282 WIPHY_WOWLAN_MAGIC_PKT |
6283 WIPHY_WOWLAN_DISCONNECT |
6284 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6285 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6286 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6287 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6288 WIPHY_WOWLAN_RFKILL_RELEASE;
6289
6290 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6291 WOW_MAX_FILTERS_PER_LIST);
6292 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6293 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6294#endif
6295
6296 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006297 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306298 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006299 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306300 return ret_val;
6301 }
6302
Amar Singhal5cccafe2017-02-15 12:42:58 -08006303 if (!hdd_ctx->reg_offload)
6304 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006305
Amar Singhale4f28ee2015-10-21 14:36:56 -07006306 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006307}
6308
Ravi Joshie2331e82015-07-01 18:18:54 -07006309/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006310 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006311 * @hdd_ctx - handle to hdd context
6312 * @tx_packets - transmit packet count
6313 * @rx_packets - receive packet count
6314 *
6315 * The function controls the bus bandwidth and dynamic control of
6316 * tcp delayed ack configuration
6317 *
6318 * Returns: None
6319 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006320#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006321static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006322 const uint64_t tx_packets,
6323 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006324{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006325 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006326 uint64_t temp_rx = 0;
6327 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006328 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006329 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006330 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006331 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006332 uint16_t index = 0;
6333 bool vote_level_change = false;
6334 bool rx_level_change = false;
6335 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006336
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006337 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006338 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006339 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006340 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006341 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006342 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006343 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006344 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006345
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006347 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6348 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006349 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006350 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006351 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306352 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306353 if (hdd_ctx->hbw_requested) {
6354 pld_remove_pm_qos(hdd_ctx->parent_dev);
6355 hdd_ctx->hbw_requested = false;
6356 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306357 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006358 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006359 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306360 if (!hdd_ctx->hbw_requested) {
6361 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6362 hdd_ctx->hbw_requested = true;
6363 }
6364
Nirav Shah3bbfa512016-05-12 16:43:49 +05306365 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006366 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006367 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006368 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006369 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006370
Mohit Khannaf8f96822017-05-17 17:11:59 -07006371 qdf_dp_trace_throttle_live_mode(
6372 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6373
Mohit Khannae71e2262015-11-10 09:37:24 -08006374 /* fine-tuning parameters for RX Flows */
6375 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6376
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006377 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006378
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306379 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6380 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6381 else
6382 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6383
Ravi Joshifed83572016-10-07 16:20:37 -07006384 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6385 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6386 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6387 next_rx_level = WLAN_SVC_TP_HIGH;
6388 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006389 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006390 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006391 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006392 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006393
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006394 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006395 struct wlan_rx_tp_data rx_tp_data = {0};
6396
Ravi Joshie2331e82015-07-01 18:18:54 -07006397 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006398 next_rx_level, temp_rx);
6399 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006400 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006401 /* Send throughput indication only if it is enabled.
6402 * Disabling tcp_del_ack will revert the tcp stack behavior
6403 * to default delayed ack. Note that this will disable the
6404 * dynamic delayed ack mechanism across the system
6405 */
6406 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006407 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6408
6409 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6410 rx_tp_data.level = next_rx_level;
6411 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6412 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6413 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006414 }
6415
Mohit Khannae71e2262015-11-10 09:37:24 -08006416 /* fine-tuning parameters for TX Flows */
6417 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6418 hdd_ctx->prev_tx = tx_packets;
6419 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6420 next_tx_level = WLAN_SVC_TP_HIGH;
6421 else
6422 next_tx_level = WLAN_SVC_TP_LOW;
6423
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006424 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006425 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6426 next_tx_level, temp_tx);
6427 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006428 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306429 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6430 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006431 &next_tx_level,
6432 sizeof(next_tx_level));
6433 }
6434
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006435 index = hdd_ctx->hdd_txrx_hist_idx;
6436
6437 if (vote_level_change || tx_level_change || rx_level_change) {
6438 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6439 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6440 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6441 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6442 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6443 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6444 hdd_ctx->hdd_txrx_hist_idx++;
6445 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6446 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006447}
6448
6449#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306450static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006451{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006452 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306453 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006454 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306455 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306456 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6457 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006458 uint64_t total_tx = 0, total_rx = 0;
6459 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306460 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306461 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006462 bool connected = false;
6463 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6464
Prashanth Bhattaab004382016-10-11 16:08:11 -07006465 if (wlan_hdd_validate_context(hdd_ctx))
6466 return;
6467
Jingxiang Gec64e1932017-08-22 14:38:59 +08006468 if (hdd_ctx->isWiphySuspended)
6469 goto restart_timer;
6470
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006471 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306472 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006473 status =
6474 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6475
Jeff Johnson57eb2732017-10-02 11:40:20 -07006476 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006477 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006478 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306479 /*
6480 * Validate magic so we don't end up accessing
6481 * an invalid adapter.
6482 */
6483 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6484 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006485
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006486 if ((adapter->device_mode == QDF_STA_MODE ||
6487 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006488 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6489 != eConnectionState_Associated) {
6490
6491 continue;
6492 }
6493
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006494 if ((adapter->device_mode == QDF_SAP_MODE ||
6495 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006496 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006497
6498 continue;
6499 }
6500
6501 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6502 adapter->prev_tx_packets);
6503 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6504 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306505
6506 if (adapter->device_mode == QDF_SAP_MODE ||
6507 adapter->device_mode == QDF_P2P_GO_MODE ||
6508 adapter->device_mode == QDF_IBSS_MODE) {
6509
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006510 ret = cdp_get_intra_bss_fwd_pkts_count(
6511 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306512 adapter->sessionId,
6513 &fwd_tx_packets, &fwd_rx_packets);
6514 if (ret == A_OK) {
6515 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6516 fwd_tx_packets,
6517 adapter->prev_fwd_tx_packets);
6518 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6519 fwd_tx_packets,
6520 adapter->prev_fwd_rx_packets);
6521 }
6522 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006523
6524 total_rx += adapter->stats.rx_packets;
6525 total_tx += adapter->stats.tx_packets;
6526
6527 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6528 adapter->prev_tx_packets = adapter->stats.tx_packets;
6529 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306530 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6531 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006532 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6533 connected = true;
6534 }
6535
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306536 /* add intra bss forwarded tx and rx packets */
6537 tx_packets += fwd_tx_packets_diff;
6538 rx_packets += fwd_rx_packets_diff;
6539
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6541 tx_packets += (uint64_t)ipa_tx_packets;
6542 rx_packets += (uint64_t)ipa_rx_packets;
6543
Yun Park2aa880c2017-08-22 10:58:10 -07006544 if (adapter) {
6545 adapter->stats.tx_packets += ipa_tx_packets;
6546 adapter->stats.rx_packets += ipa_rx_packets;
6547 }
6548
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006549 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006550 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006551 return;
6552 }
6553
Yuanyuan Liu13738502016-04-06 17:41:37 -07006554 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006555
6556 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6557 hdd_ipa_uc_stat_request(adapter, 2);
6558
Jingxiang Gec64e1932017-08-22 14:38:59 +08006559restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006560 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006561 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006562 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306563 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006564 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006565 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006566}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006567
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306568/**
6569 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6570 * @arg: Argument of timer function
6571 *
6572 * Schedule a workqueue in this function where all the processing is done.
6573 *
6574 * Return: None.
6575 */
6576static void __hdd_bus_bw_cbk(void *arg)
6577{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006578 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306579
6580 if (wlan_hdd_validate_context(hdd_ctx))
6581 return;
6582
6583 schedule_work(&hdd_ctx->bus_bw_work);
6584}
6585
6586/**
6587 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6588 * @arg: Argument of timer function
6589 *
6590 * Return: None.
6591 */
6592static void hdd_bus_bw_cbk(void *arg)
6593{
6594 cds_ssr_protect(__func__);
6595 __hdd_bus_bw_cbk(arg);
6596 cds_ssr_unprotect(__func__);
6597}
6598
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006599int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006600{
6601 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306602 INIT_WORK(&hdd_ctx->bus_bw_work,
6603 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006604 hdd_ctx->bus_bw_timer_running = false;
6605 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306606 qdf_timer_init(NULL,
6607 &hdd_ctx->bus_bw_timer,
6608 hdd_bus_bw_cbk, (void *)hdd_ctx,
6609 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006610
6611 return 0;
6612}
6613
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006614void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006615{
Dustin Brownfce08d12017-01-17 16:29:38 -08006616 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006617 hdd_reset_tcp_delack(hdd_ctx);
6618
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006619 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306620 cancel_work_sync(&hdd_ctx->bus_bw_work);
6621 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006622 hdd_ctx->bus_bw_timer_running = false;
6623 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006624}
Lin Baic5c06882017-09-21 13:58:43 +08006625
6626void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6627{
6628 if (hdd_ctx)
6629 cancel_work_sync(&hdd_ctx->bus_bw_work);
6630}
jiadcdaf9bd2017-10-26 12:20:21 +08006631
6632void hdd_send_wlan_tp_ind(struct hdd_context *hdd_ctx)
6633{
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006634 struct wlan_rx_tp_data rx_tp_data = {0};
6635
jiadcdaf9bd2017-10-26 12:20:21 +08006636 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006637 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6638 sizeof(rx_tp_data));
jiadcdaf9bd2017-10-26 12:20:21 +08006639}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006640#endif
6641
6642/**
Nirav Shahed34b212016-04-25 10:59:16 +05306643 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6644 * @hdd_ctx: hdd context
6645 *
6646 * Return: 0 for success or error code
6647 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006648static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306649{
6650 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6651 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6652 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006653 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306654 return -ENOMEM;
6655 }
6656 return 0;
6657}
6658
6659/**
6660 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6661 * @hdd_ctx: hdd context
6662 *
6663 * Return: none
6664 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006665void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306666{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306667 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6668 return;
6669
6670 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6671 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306672}
6673
Nirav Shahda008342016-05-17 18:50:40 +05306674static uint8_t *convert_level_to_string(uint32_t level)
6675{
6676 switch (level) {
6677 /* initialize the wlan sub system */
6678 case WLAN_SVC_TP_NONE:
6679 return "NONE";
6680 case WLAN_SVC_TP_LOW:
6681 return "LOW";
6682 case WLAN_SVC_TP_MEDIUM:
6683 return "MED";
6684 case WLAN_SVC_TP_HIGH:
6685 return "HIGH";
6686 default:
6687 return "INVAL";
6688 }
6689}
6690
Nirav Shahed34b212016-04-25 10:59:16 +05306691
6692/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006693 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6694 * @hdd_ctx: hdd context
6695 *
6696 * Return: none
6697 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006698void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006699{
6700 int i;
6701
6702#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006703 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306704 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006705 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006706 hdd_ctx->config->busBandwidthHighThreshold,
6707 hdd_ctx->config->busBandwidthMediumThreshold,
6708 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006709 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306710 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006711 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006712 hdd_ctx->config->tcpDelackThresholdHigh,
6713 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006714 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306715 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006716#endif
6717
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006718 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306719 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6720
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006721 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006722
6723 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006724 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006725 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006726 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006727 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6728 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006729 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006730 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6731 convert_level_to_string(
6732 hdd_ctx->hdd_txrx_hist[i].
6733 next_vote_level),
6734 convert_level_to_string(
6735 hdd_ctx->hdd_txrx_hist[i].
6736 next_rx_level),
6737 convert_level_to_string(
6738 hdd_ctx->hdd_txrx_hist[i].
6739 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006740 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006741}
6742
6743/**
6744 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6745 * @hdd_ctx: hdd context
6746 *
6747 * Return: none
6748 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006749void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006750{
6751 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306752 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6753 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006754}
6755
6756/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006757 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006758 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006759 *
6760 * Return: none
6761 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006762void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006763{
6764
Jeff Johnson9d295242017-08-29 14:39:48 -07006765 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306767 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006768 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306769 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006770
6771 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306772 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006773 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006774
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006775 hdd_debug("Netif queue operation statistics:");
6776 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306777 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006778 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306779 curr_time = qdf_system_ticks();
6780 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306781 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306782 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306783 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306784 unpause = adapter->total_unpause_time;
6785 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306786 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306787 pause = adapter->total_pause_time;
6788 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006789 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306790 qdf_system_ticks_to_msecs(total),
6791 qdf_system_ticks_to_msecs(pause),
6792 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006793 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006794
Nirav Shahda008342016-05-17 18:50:40 +05306795 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6796 qdf_time_t pause_delta = 0;
6797
6798 if (adapter->pause_map & (1 << i))
6799 pause_delta = delta;
6800
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006801 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006802 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006803 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006804 hdd_reason_type_to_string(i),
6805 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306806 adapter->queue_oper_stats[i].unpause_count,
6807 qdf_system_ticks_to_msecs(
6808 adapter->queue_oper_stats[i].total_pause_time +
6809 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006810 }
6811
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006812 hdd_debug("Netif queue operation history:");
6813 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306814 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6815
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006816 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006817
6818 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006819 /* using hdd_log to avoid printing function name */
6820 if (adapter->queue_oper_history[i].time == 0)
6821 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006822 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006823 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306824 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006825 adapter->queue_oper_history[i].time),
6826 hdd_action_type_to_string(
6827 adapter->queue_oper_history[i].netif_action),
6828 hdd_reason_type_to_string(
6829 adapter->queue_oper_history[i].netif_reason),
6830 adapter->queue_oper_history[i].pause_map);
6831 }
6832
6833 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6834 adapter_node = next;
6835 }
6836
6837
6838}
6839
6840/**
6841 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6842 * @hdd_ctx: hdd context
6843 *
6844 * Return: none
6845 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006846void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006847{
Jeff Johnson9d295242017-08-29 14:39:48 -07006848 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006849 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306850 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006851
6852 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306853 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006854 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006855
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306856 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006857 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306858 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006859 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306860 adapter->history_index = 0;
6861 adapter->start_time = adapter->last_time = qdf_system_ticks();
6862 adapter->total_pause_time = 0;
6863 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006864 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6865 adapter_node = next;
6866 }
6867}
6868
6869/**
6870 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6871 * @halHandle: Hal handle
6872 * @pContext: Pointer to the context
6873 * @sessionId: Session ID
6874 * @scanId: Scan ID
6875 * @status: Status
6876 *
6877 * This is the callback to be executed when 11d scan is completed to flush out
6878 * the scan results
6879 *
6880 * 11d scan is done during driver load and is a passive scan on all
6881 * channels supported by the device, 11d scans may find some APs on
6882 * frequencies which are forbidden to be used in the regulatory domain
6883 * the device is operating in. If these APs are notified to the supplicant
6884 * it may try to connect to these APs, thus flush out all the scan results
6885 * which are present in SME after 11d scan is done.
6886 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306887 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306889static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006890 uint8_t sessionId, uint32_t scanId,
6891 eCsrScanStatus status)
6892{
6893 ENTER();
6894
6895 sme_scan_flush_result(halHandle);
6896
6897 EXIT();
6898
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306899 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006900}
6901
6902#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6903/**
6904 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6905 * @hdd_ctx: hdd global context
6906 *
6907 * Return: none
6908 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006909static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006910{
6911 uint8_t i;
6912
6913 mutex_init(&hdd_ctx->op_ctx.op_lock);
6914 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6915 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6916 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6917 }
6918}
6919#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006920static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006921{
6922}
6923#endif
6924
Yingying Tang95409972016-10-20 15:16:15 +08006925#ifdef WLAN_FEATURE_WOW_PULSE
6926/**
6927 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006928 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006929 * @enable: enable or disable this behaviour
6930 *
6931 * Return: int
6932 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006933static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006934{
6935 struct hdd_config *pcfg_ini = phddctx->config;
6936 struct wow_pulse_mode wow_pulse_set_info;
6937 QDF_STATUS status;
6938
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006939 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006940
6941 if (false == phddctx->config->wow_pulse_support)
6942 return 0;
6943
6944 /* prepare the request to send to SME */
6945 if (enable == true) {
6946 wow_pulse_set_info.wow_pulse_enable = true;
6947 wow_pulse_set_info.wow_pulse_pin =
6948 pcfg_ini->wow_pulse_pin;
6949 wow_pulse_set_info.wow_pulse_interval_low =
6950 pcfg_ini->wow_pulse_interval_low;
6951 wow_pulse_set_info.wow_pulse_interval_high =
6952 pcfg_ini->wow_pulse_interval_high;
6953 } else {
6954 wow_pulse_set_info.wow_pulse_enable = false;
6955 wow_pulse_set_info.wow_pulse_pin = 0;
6956 wow_pulse_set_info.wow_pulse_interval_low = 0;
6957 wow_pulse_set_info.wow_pulse_interval_high = 0;
6958 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006959 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006960 wow_pulse_set_info.wow_pulse_enable,
6961 wow_pulse_set_info.wow_pulse_pin,
6962 wow_pulse_set_info.wow_pulse_interval_low,
6963 wow_pulse_set_info.wow_pulse_interval_high);
6964
6965 status = sme_set_wow_pulse(&wow_pulse_set_info);
6966 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006967 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006968 return -EIO;
6969 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006970 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006971 return 0;
6972}
6973#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006974static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006975{
6976 return 0;
6977}
6978#endif
6979
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006980#ifdef WLAN_FEATURE_FASTPATH
6981/**
6982 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6983 * @hdd_cfg: hdd config
6984 * @context: lower layer context
6985 *
6986 * Return: none
6987 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306988void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006989 void *context)
6990{
6991 if (hdd_cfg->fastpath_enable)
6992 hif_enable_fastpath(context);
6993}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006994#endif
6995
Yuanyuan Liu13738502016-04-06 17:41:37 -07006996#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006997/**
6998 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006999 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007000 * @level: thermal level
7001 *
7002 * Change IPA data path to SW path when the thermal throttle level greater
7003 * than 0, and restore the original data path when throttle level is 0
7004 *
7005 * Return: none
7006 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007007static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007008{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007009 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007010
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007011 /* Change IPA to SW path when throttle level greater than 0 */
7012 if (level > THROTTLE_LEVEL_0)
7013 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7014 else
7015 /* restore original concurrency mode */
7016 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7017}
7018
7019/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307020 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7021 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307022 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007023 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307024 * Get a safe channel to restart SAP. PCL already takes into account the
7025 * unsafe channels. So, the PCL is validated with the ACS range to provide
7026 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007027 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307028 * Return: Channel number to restart SAP in case of success. In case of any
7029 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007030 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307031static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007032 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007033{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307034 struct sir_pcl_list pcl;
7035 QDF_STATUS status;
7036 uint32_t i, j;
7037 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007038 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307039 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007040
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307041 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7042 if (!hdd_ctx) {
7043 hdd_err("invalid HDD context");
7044 return INVALID_CHANNEL_ID;
7045 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007046
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307047 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7048 if (!hal_handle) {
7049 hdd_err("invalid HAL handle");
7050 return INVALID_CHANNEL_ID;
7051 }
7052
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007053 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7054 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007055 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7056 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307057 if (QDF_IS_STATUS_ERROR(status)) {
7058 hdd_err("Get PCL failed");
7059 return INVALID_CHANNEL_ID;
7060 }
7061
Frank Liudc2cefb2017-06-21 15:38:18 +08007062 /*
7063 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7064 * channel is unsafe channel, the pcl may be empty, instead of return,
7065 * try to choose a safe channel from acs range.
7066 */
7067 if (!pcl.pcl_len)
7068 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307069
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007070 hdd_debug("start:%d end:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007071 adapter->sessionCtx.ap.sap_config.acs_cfg.start_ch,
7072 adapter->sessionCtx.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307073
7074 /* PCL already takes unsafe channel into account */
7075 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007076 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307077 if ((pcl.pcl_list[i] >=
Jeff Johnson91df29d2017-10-27 19:29:50 -07007078 adapter->sessionCtx.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307079 (pcl.pcl_list[i] <=
Jeff Johnson91df29d2017-10-27 19:29:50 -07007080 adapter->sessionCtx.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007081 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307082 return pcl.pcl_list[i];
7083 }
7084 }
7085
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007086 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307087
7088 /* Try for safe channel from all valid channel */
7089 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007090 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307091 &pcl.pcl_len);
7092 if (QDF_IS_STATUS_ERROR(status)) {
7093 hdd_err("error in getting valid channel list");
7094 return INVALID_CHANNEL_ID;
7095 }
7096
7097 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007098 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307099 found = false;
7100 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007101 if (pcl.pcl_list[i] ==
7102 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007103 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307104 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007105 break;
7106 }
7107 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307108
7109 if (found)
7110 continue;
7111
7112 if ((pcl.pcl_list[i] >=
Jeff Johnson91df29d2017-10-27 19:29:50 -07007113 adapter->sessionCtx.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307114 (pcl.pcl_list[i] <=
Jeff Johnson91df29d2017-10-27 19:29:50 -07007115 adapter->sessionCtx.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007116 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307117 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007118 }
7119 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307120
7121 return INVALID_CHANNEL_ID;
7122}
7123
7124/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007125 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307126 * @adapter: AP adapter
7127 * @channel: Channel
7128 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007129 * Moves the SAP interface by invoking the function which
7130 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307131 *
7132 * Return: None
7133 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007134void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307135{
Jeff Johnson87251032017-08-29 13:31:11 -07007136 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307137 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007138 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307139
7140 if (!adapter) {
7141 hdd_err("invalid adapter");
7142 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007143 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307144
7145 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7146
7147 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7148 if (!hal_handle) {
7149 hdd_err("invalid HAL handle");
7150 return;
7151 }
7152
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007153 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7154
Jeff Johnson91df29d2017-10-27 19:29:50 -07007155 hdd_ap_ctx->sap_config.channel = channel;
7156 hdd_ap_ctx->sap_config.ch_params.ch_width =
7157 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307158
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007159 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007160 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307161
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007162 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007163 hdd_ap_ctx->sap_config.channel,
7164 hdd_ap_ctx->sap_config.sec_ch,
7165 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307166
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007167 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7168 adapter->sessionId, channel,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007169 hdd_ap_ctx->sap_config.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007170}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307171
Jeff Johnson9d295242017-08-29 14:39:48 -07007172int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307173{
7174 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307175 int status;
7176 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307177
7178 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7179
7180 if (QDF_TIMER_STATE_RUNNING ==
7181 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7182 ap.vendor_acs_timer)) {
7183 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7184 }
7185 timer_context = (struct hdd_external_acs_timer_context *)
7186 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7187 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307188 qdf_status =
7189 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7190 WLAN_VENDOR_ACS_WAIT_TIME);
7191 if (qdf_status != QDF_STATUS_SUCCESS) {
7192 hdd_err("failed to start external acs timer");
7193 return -ENOSPC;
7194 }
7195 /* Update config to application */
7196 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307197 hdd_notice("Updated ACS config to nl with reason %d", reason);
7198
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307199 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307200}
7201
Agrawal Ashish467dde42016-09-08 18:44:22 +05307202/**
7203 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7204 * @hdd_ctx: hdd context pointer
7205 *
7206 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7207 * and if ACS is enabled, driver will ask userspace to restart the
7208 * sap. User space on LTE coex indication restart driver.
7209 *
7210 * Return - none
7211 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007212void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307213{
7214 QDF_STATUS status;
7215 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007216 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307217 uint32_t i;
7218 bool found = false;
7219 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007220
Agrawal Ashish467dde42016-09-08 18:44:22 +05307221 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7222 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007223 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307224
7225 if (!adapter_temp) {
7226 hdd_err("adapter is NULL, moving to next one");
7227 goto next_adapater;
7228 }
7229
7230 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
Jeff Johnson91df29d2017-10-27 19:29:50 -07007231 (adapter_temp->sessionCtx.ap.sap_config.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007232 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307233 adapter_temp->device_mode,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007234 adapter_temp->sessionCtx.ap.sap_config.
Agrawal Ashish467dde42016-09-08 18:44:22 +05307235 acs_cfg.acs_mode);
7236 goto next_adapater;
7237 }
7238
7239 found = false;
7240 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Jeff Johnson01206862017-10-27 20:55:59 -07007241 if (adapter_temp->sessionCtx.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307242 hdd_ctxt->unsafe_channel_list[i]) {
7243 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007244 hdd_debug("operating ch:%d is unsafe",
Jeff Johnson01206862017-10-27 20:55:59 -07007245 adapter_temp->sessionCtx.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307246 break;
7247 }
7248 }
7249
7250 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007251 hdd_debug("ch:%d is safe. no need to change channel",
Jeff Johnson01206862017-10-27 20:55:59 -07007252 adapter_temp->sessionCtx.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307253 goto next_adapater;
7254 }
7255
Kapil Gupta8878ad92017-02-13 11:56:04 +05307256 if (hdd_ctxt->config->vendor_acs_support &&
7257 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7258 hdd_update_acs_timer_reason(adapter_temp,
7259 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7260 goto next_adapater;
7261 } else
7262 restart_chan =
7263 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307264 adapter_temp);
7265 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007266 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307267 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007268 /*
7269 * SAP restart due to unsafe channel. While
7270 * restarting the SAP, make sure to clear
7271 * acs_channel, channel to reset to
7272 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307273 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007274 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307275 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnson91df29d2017-10-27 19:29:50 -07007276 adapter_temp->sessionCtx.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307277 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007278 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307279 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7280 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007281 hdd_debug("driver to start sap: %d",
7282 hdd_ctxt->config->sap_internal_restart);
7283 if (hdd_ctxt->config->sap_internal_restart)
7284 hdd_switch_sap_channel(adapter_temp, restart_chan);
7285 else
7286 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307287 }
7288
7289next_adapater:
7290 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7291 adapter_node = next;
7292 }
7293}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307294
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007295/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007296 * hdd_init_channel_avoidance() - Initialize channel avoidance
7297 * @hdd_ctx: HDD global context
7298 *
7299 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007300 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007301 * down to the lower layers. Then subscribe to subsequent channel
7302 * avoidance events.
7303 *
7304 * Return: None
7305 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007306static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007307{
7308 uint16_t unsafe_channel_count;
7309 int index;
7310
Yuanyuan Liu13738502016-04-06 17:41:37 -07007311 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7312 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007313 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007314 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007315
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007316 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007317 hdd_ctx->unsafe_channel_count);
7318
Anurag Chouhan6d760662016-02-20 16:05:43 +05307319 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007320 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007321
7322 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007323 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007324 hdd_ctx->unsafe_channel_list[index]);
7325
7326 }
7327
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007328}
Dustin Brown676a2322017-08-15 13:16:13 -07007329
Jeff Johnson9d295242017-08-29 14:39:48 -07007330static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007331 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007332{
7333 uint8_t restart_chan;
7334
7335 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7336 if (!restart_chan) {
7337 hdd_alert("fail to restart SAP");
7338 return;
7339 }
7340
7341 /* SAP restart due to unsafe channel. While restarting
7342 * the SAP, make sure to clear acs_channel, channel to
7343 * reset to 0. Otherwise these settings will override
7344 * the ACS while restart.
7345 */
7346 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnson91df29d2017-10-27 19:29:50 -07007347 adapter->sessionCtx.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007348
7349 hdd_debug("sending coex indication");
7350
7351 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7352 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7353 hdd_switch_sap_channel(adapter, restart_chan);
7354}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007355
7356int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7357 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7358{
7359 uint32_t size;
7360 uint16_t *unsafe_list;
7361 uint16_t chan_count;
7362
7363 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7364 return -EINVAL;
7365
7366 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7367 NUM_CHANNELS);
7368 if (chan_count) {
7369 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7370 unsafe_list = qdf_mem_malloc(size);
7371 if (!unsafe_list) {
7372 hdd_err("No memory for unsafe chan list size%d",
7373 size);
7374 return -ENOMEM;
7375 }
7376 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7377 } else {
7378 unsafe_list = NULL;
7379 }
7380
7381 *local_unsafe_list = unsafe_list;
7382 *local_unsafe_list_count = chan_count;
7383
7384 return 0;
7385}
7386
7387bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7388 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7389{
7390 int i, j;
7391
7392 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7393 return true;
7394 if (local_unsafe_list_count == 0)
7395 return false;
7396 for (i = 0; i < local_unsafe_list_count; i++) {
7397 for (j = 0; j < local_unsafe_list_count; j++)
7398 if (local_unsafe_list[i] ==
7399 hdd_ctx->unsafe_channel_list[j])
7400 break;
7401 if (j >= local_unsafe_list_count)
7402 break;
7403 }
7404 if (i >= local_unsafe_list_count) {
7405 hdd_info("unsafe chan list same");
7406 return false;
7407 }
7408
7409 return true;
7410}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007411#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007412static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007413{
7414}
Dustin Brown676a2322017-08-15 13:16:13 -07007415
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007416static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007417{
7418}
Dustin Brown676a2322017-08-15 13:16:13 -07007419
Jeff Johnson9d295242017-08-29 14:39:48 -07007420static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007421 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007422{
7423 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7424}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007425#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007426
7427/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007428 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7429 * user space
7430 * @frame_ind: Management frame data to be informed.
7431 *
7432 * This function is used to indicate management frame to
7433 * user space
7434 *
7435 * Return: None
7436 *
7437 */
7438void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7439{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007440 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007441 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007442 int i;
7443
Rajeev Kumard004abc2016-02-17 12:09:56 -08007444 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007445 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007446
7447 if (0 != wlan_hdd_validate_context(hdd_ctx))
7448 return;
7449
7450 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7451 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7452 adapter =
7453 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7454 if (adapter)
7455 break;
7456 }
7457 } else {
7458 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7459 frame_ind->sessionId);
7460 }
7461
7462 if ((NULL != adapter) &&
7463 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7464 __hdd_indicate_mgmt_frame(adapter,
7465 frame_ind->frame_len,
7466 frame_ind->frameBuf,
7467 frame_ind->frameType,
7468 frame_ind->rxChan,
7469 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007470}
7471
Kapil Gupta8878ad92017-02-13 11:56:04 +05307472void hdd_acs_response_timeout_handler(void *context)
7473{
7474 struct hdd_external_acs_timer_context *timer_context =
7475 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007476 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007477 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307478 uint8_t reason;
7479
7480 ENTER();
7481 if (!timer_context) {
7482 hdd_err("invlaid timer context");
7483 return;
7484 }
7485 adapter = timer_context->adapter;
7486 reason = timer_context->reason;
7487
7488
7489 if ((!adapter) ||
7490 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7491 hdd_err("invalid adapter or adapter has invalid magic");
7492 return;
7493 }
7494 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7495 if (wlan_hdd_validate_context(hdd_ctx))
7496 return;
7497
7498 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7499 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7500 else
7501 return;
7502
7503 hdd_err("ACS timeout happened for %s reason %d",
7504 adapter->dev->name, reason);
7505 switch (reason) {
7506 /* SAP init case */
7507 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7508 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7509 false);
7510 wlan_hdd_cfg80211_start_acs(adapter);
7511 break;
7512 /* DFS detected on current channel */
7513 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7514 wlan_sap_update_next_channel(
7515 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7516 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7517 adapter->sessionId);
7518 break;
7519 /* LTE coex event on current channel */
7520 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7521 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7522 break;
7523 default:
7524 hdd_info("invalid reason for timer invoke");
7525
7526 }
7527}
7528
Rajeev Kumard004abc2016-02-17 12:09:56 -08007529/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007530 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7531 * @hdd_ctx: HDD context
7532 *
7533 * Disables all the dual mac features like DBS, Agile DFS etc.
7534 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307535 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007536 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007537static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007538{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007539 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307540 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007541
7542 if (!hdd_ctx) {
7543 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307544 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007545 }
7546
7547 cfg.scan_config = 0;
7548 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007549 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007550
7551 hdd_debug("Disabling all dual mac features...");
7552
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007553 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307554 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007555 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7556 return status;
7557 }
7558
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307559 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007560}
7561
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007562static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007563wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007564{
7565 struct policy_mgr_dual_mac_config cfg = {0};
7566 QDF_STATUS status;
7567
7568 if (!hdd_ctx) {
7569 hdd_err("HDD context is NULL");
7570 return QDF_STATUS_E_FAILURE;
7571 }
7572
7573 cfg.scan_config = 0;
7574 cfg.fw_mode_config = 0;
7575 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7576 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7577 hdd_ctx->hdd_psoc, &cfg.scan_config,
7578 &cfg.fw_mode_config,
7579 hdd_ctx->config->dual_mac_feature_disable);
7580
7581 if (status != QDF_STATUS_SUCCESS) {
7582 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7583 status);
7584 return status;
7585 }
7586
7587 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7588 cfg.scan_config, cfg.fw_mode_config);
7589
7590 status = sme_soc_set_dual_mac_config(cfg);
7591 if (status != QDF_STATUS_SUCCESS) {
7592 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7593 return status;
7594 }
7595
7596 return QDF_STATUS_SUCCESS;
7597}
7598
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007599/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007600 * hdd_override_ini_config - Override INI config
7601 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007602 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007603 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007604 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007605 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007606 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007607static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007608{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007609
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007610 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7611 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007612 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007613 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007614 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007615 if (0 == enable_11d || 1 == enable_11d) {
7616 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007617 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007618 }
Leo Chang11545d62016-10-17 14:53:50 -07007619
7620 if (!hdd_ipa_is_present(hdd_ctx))
7621 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007622}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007623
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007624/**
7625 * hdd_set_trace_level_for_each - Set trace level for each INI config
7626 * @hdd_ctx - HDD context
7627 *
7628 * Set trace level for each module based on INI config.
7629 *
7630 * Return: None
7631 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007632static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007633{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307634 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7635 hdd_ctx->config->qdf_trace_enable_wdi);
7636 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7637 hdd_ctx->config->qdf_trace_enable_hdd);
7638 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7639 hdd_ctx->config->qdf_trace_enable_sme);
7640 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7641 hdd_ctx->config->qdf_trace_enable_pe);
7642 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7643 hdd_ctx->config->qdf_trace_enable_wma);
7644 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7645 hdd_ctx->config->qdf_trace_enable_sys);
7646 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7647 hdd_ctx->config->qdf_trace_enable_qdf);
7648 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7649 hdd_ctx->config->qdf_trace_enable_sap);
7650 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7651 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7652 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7653 hdd_ctx->config->qdf_trace_enable_bmi);
7654 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7655 hdd_ctx->config->qdf_trace_enable_cfg);
7656 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7657 hdd_ctx->config->qdf_trace_enable_epping);
7658 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7659 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7660 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007661 hdd_ctx->config->qdf_trace_enable_txrx);
7662 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7663 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307664 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7665 hdd_ctx->config->qdf_trace_enable_htc);
7666 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7667 hdd_ctx->config->qdf_trace_enable_hif);
7668 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7669 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7670 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7671 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007672 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7673 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007674 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7675 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007676 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7677 hdd_ctx->config->qdf_trace_enable_regulatory);
7678
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007679 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007680}
7681
7682/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007683 * hdd_context_init() - Initialize HDD context
7684 * @hdd_ctx: HDD context.
7685 *
7686 * Initialize HDD context along with all the feature specific contexts.
7687 *
7688 * return: 0 on success and errno on failure.
7689 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007690static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007691{
7692 int ret;
7693
7694 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7695 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7696
7697 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307698 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007699
7700 init_completion(&hdd_ctx->mc_sus_event_var);
7701 init_completion(&hdd_ctx->ready_to_suspend);
7702
7703 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307704 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007705 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307706
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007707 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7708
7709 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7710
7711 ret = hdd_scan_context_init(hdd_ctx);
7712 if (ret)
7713 goto list_destroy;
7714
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007715 hdd_rx_wake_lock_create(hdd_ctx);
7716
7717 ret = hdd_sap_context_init(hdd_ctx);
7718 if (ret)
7719 goto scan_destroy;
7720
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007721 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7722
7723 hdd_init_offloaded_packets_ctx(hdd_ctx);
7724
7725 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7726 hdd_ctx->config);
7727 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08007728 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007729
7730 return 0;
7731
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007732sap_destroy:
7733 hdd_sap_context_destroy(hdd_ctx);
7734
7735scan_destroy:
7736 hdd_scan_context_destroy(hdd_ctx);
7737 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007738list_destroy:
7739 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007740
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007741 return ret;
7742}
7743
7744/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307745 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7746 * @hdd_ctx: pointer to hdd context
7747 *
7748 * Return: status of initialization
7749 * 0 - success
7750 * negative value - failure
7751 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007752static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307753{
7754 int ret;
7755
7756 if (!hdd_ctx->config->probe_req_ie_whitelist)
7757 return 0;
7758
7759 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7760 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7761 hdd_ctx->config->probe_req_ie_whitelist = false;
7762 return -EINVAL;
7763 }
7764
7765 /* parse ini string probe req oui */
7766 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7767 if (ret) {
7768 hdd_err("parsing error: disable ie whitelisting");
7769 hdd_ctx->config->probe_req_ie_whitelist = false;
7770 }
7771
7772 return ret;
7773}
7774
7775/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007776 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307777 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007778 *
7779 * Allocate and initialize HDD context. HDD context is allocated as part of
7780 * wiphy allocation and then context is initialized.
7781 *
7782 * Return: HDD context on success and ERR_PTR on failure
7783 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007784static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007785{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307786 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007787 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007788 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007789
7790 ENTER();
7791
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007792 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007793 if (hdd_ctx == NULL) {
7794 ret = -ENOMEM;
7795 goto err_out;
7796 }
7797
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007798 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307799 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007800
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307801 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007802 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007803 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007804 ret = -ENOMEM;
7805 goto err_free_hdd_context;
7806 }
7807
7808 /* Read and parse the qcom_cfg.ini file */
7809 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307810 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307811 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007812 WLAN_INI_FILE);
7813 ret = -EINVAL;
7814 goto err_free_config;
7815 }
7816
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307817 ie_whitelist_attrs_init(hdd_ctx);
7818
Dustin Brown7f939932017-05-18 15:02:17 -07007819 hdd_debug("setting timer multiplier: %u",
7820 hdd_ctx->config->timer_multiplier);
7821 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7822
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007823
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307824 if (hdd_ctx->config->fhostNSOffload)
7825 hdd_ctx->ns_offload_enable = true;
7826
Abhishek Singh5ea86532016-04-27 14:10:53 +05307827 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7828
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007829 hdd_override_ini_config(hdd_ctx);
7830
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007831 ret = hdd_context_init(hdd_ctx);
7832
7833 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007834 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007835
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007836 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307837 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007838
Anurag Chouhan6d760662016-02-20 16:05:43 +05307839 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007840 goto skip_multicast_logging;
7841
7842 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7843
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007844 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7845 if (ret)
7846 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307847
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007848 ret = hdd_init_netlink_services(hdd_ctx);
7849 if (ret)
7850 goto err_deinit_txrx_histogram;
7851
Dustin Brown7b3dea22017-07-10 13:02:47 -07007852 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7853 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307854
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007855skip_multicast_logging:
7856 hdd_set_trace_level_for_each(hdd_ctx);
7857
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007858 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7859
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007860 EXIT();
7861
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007862 return hdd_ctx;
7863
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007864err_deinit_txrx_histogram:
7865 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7866
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007867err_deinit_hdd_context:
7868 hdd_context_deinit(hdd_ctx);
7869
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007870err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307871 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007872
7873err_free_hdd_context:
7874 wiphy_free(hdd_ctx->wiphy);
7875
7876err_out:
7877 return ERR_PTR(ret);
7878}
7879
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007880#ifdef WLAN_OPEN_P2P_INTERFACE
7881/**
7882 * hdd_open_p2p_interface - Open P2P interface
7883 * @hdd_ctx: HDD context
7884 * @rtnl_held: True if RTNL lock held
7885 *
7886 * Open P2P interface during probe. This function called to open the P2P
7887 * interface at probe along with STA interface.
7888 *
7889 * Return: 0 on success and errno on failure
7890 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007891static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007892{
Jeff Johnson9d295242017-08-29 14:39:48 -07007893 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007894 uint8_t *p2p_dev_addr;
7895
7896 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7897 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307898 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007899 hdd_ctx->config->intfMacAddr[0].bytes,
7900 sizeof(tSirMacAddr));
7901
7902 /*
7903 * Generate the P2P Device Address. This consists of
7904 * the device's primary MAC address with the locally
7905 * administered bit set.
7906 */
7907 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7908 } else {
7909 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7910 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007911 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007912 return -ENOSPC;
7913 }
7914
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307915 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307916 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007917 }
7918
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007919 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007920 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007921 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007922
7923 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007924 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007925 return -ENOSPC;
7926 }
7927
7928 return 0;
7929}
7930#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007931static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007932 bool rtnl_held)
7933{
7934 return 0;
7935}
7936#endif
7937
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007938static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007939{
Jeff Johnson9d295242017-08-29 14:39:48 -07007940 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007941 int ret = 0;
7942
7943 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7944 wlan_hdd_get_intf_addr(hdd_ctx),
7945 NET_NAME_UNKNOWN, rtnl_held);
7946 if (adapter == NULL) {
7947 hdd_err("Failed to open 802.11p interface");
7948 ret = -ENOSPC;
7949 }
7950
7951 return ret;
7952}
7953
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007954/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307955 * hdd_start_station_adapter()- Start the Station Adapter
7956 * @adapter: HDD adapter
7957 *
7958 * This function initializes the adapter for the station mode.
7959 *
7960 * Return: 0 on success or errno on failure.
7961 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007962int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307963{
7964 QDF_STATUS status;
7965
7966 ENTER_DEV(adapter->dev);
7967
7968 status = hdd_init_station_mode(adapter);
7969
7970 if (QDF_STATUS_SUCCESS != status) {
7971 hdd_err("Error Initializing station mode: %d", status);
7972 return qdf_status_to_os_return(status);
7973 }
7974
Arun Khandavallifae92942016-08-01 13:31:08 +05307975 hdd_register_tx_flow_control(adapter,
7976 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007977 hdd_tx_resume_cb,
7978 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307979
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307980 EXIT();
7981 return 0;
7982}
7983
7984/**
7985 * hdd_start_ap_adapter()- Start AP Adapter
7986 * @adapter: HDD adapter
7987 *
7988 * This function initializes the adapter for the AP mode.
7989 *
7990 * Return: 0 on success errno on failure.
7991 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007992int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307993{
7994 QDF_STATUS status;
7995
7996 ENTER();
7997
Arun Khandavallicc544b32017-01-30 19:52:16 +05307998 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307999
8000 if (QDF_STATUS_SUCCESS != status) {
8001 hdd_err("Error Initializing the AP mode: %d", status);
8002 return qdf_status_to_os_return(status);
8003 }
8004
Arun Khandavallifae92942016-08-01 13:31:08 +05308005 hdd_register_tx_flow_control(adapter,
8006 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008007 hdd_softap_tx_resume_cb,
8008 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308009
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308010 EXIT();
8011 return 0;
8012}
8013
8014/**
8015 * hdd_start_ftm_adapter()- Start FTM adapter
8016 * @adapter: HDD adapter
8017 *
8018 * This function initializes the adapter for the FTM mode.
8019 *
8020 * Return: 0 on success or errno on failure.
8021 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008022int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308023{
8024 QDF_STATUS qdf_status;
8025
8026 ENTER_DEV(adapter->dev);
8027
8028 qdf_status = hdd_init_tx_rx(adapter);
8029
8030 if (QDF_STATUS_SUCCESS != qdf_status) {
8031 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8032 return qdf_status_to_os_return(qdf_status);
8033 }
8034
8035 return 0;
8036 EXIT();
8037}
8038
8039/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008040 * hdd_open_interfaces - Open all required interfaces
8041 * hdd_ctx: HDD context
8042 * rtnl_held: True if RTNL lock is held
8043 *
8044 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8045 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008046 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008047 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008048static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008049{
Jeff Johnson9d295242017-08-29 14:39:48 -07008050 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008051 int ret;
8052
Ravi Joshia307f632017-07-17 23:41:41 -07008053 /* open monitor mode adapter if con_mode is monitor mode */
8054 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8055 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8056 wlan_hdd_get_intf_addr(hdd_ctx),
8057 NET_NAME_UNKNOWN, rtnl_held);
8058 if (!adapter) {
8059 hdd_err("open adapter failed");
8060 return -ENOSPC;
8061 }
8062 return 0;
8063 }
8064
Jeff Johnson957bc272017-02-02 08:54:48 -08008065 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308066 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008067 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008068
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008069 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008070 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008071 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008072
8073 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008074 return -ENOSPC;
8075
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008076 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8077 adapter->fast_roaming_allowed = true;
8078
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008079 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8080 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008081 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008082
8083 /* Open 802.11p Interface */
8084 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008085 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8086 if (ret)
8087 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008088 }
8089
Jeff Johnson957bc272017-02-02 08:54:48 -08008090 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008091
Jeff Johnson957bc272017-02-02 08:54:48 -08008092err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008093 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008094 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008095}
8096
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008097/**
8098 * hdd_update_country_code - Update country code
8099 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008100 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008101 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008102 *
8103 * Return: 0 on success and errno on failure
8104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008105static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008106{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008107 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008108 return 0;
8109
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008110 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008111}
8112
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308113#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8114/**
8115 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8116 * @cds_cfg: CDS Configuration
8117 * @hdd_ctx: Pointer to hdd context
8118 *
8119 * Return: none
8120 */
8121static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8122 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008123 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308124{
8125 cds_cfg->tx_flow_stop_queue_th =
8126 hdd_ctx->config->TxFlowStopQueueThreshold;
8127 cds_cfg->tx_flow_start_queue_offset =
8128 hdd_ctx->config->TxFlowStartQueueOffset;
8129}
8130#else
8131static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8132 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008133 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308134{
8135}
8136#endif
8137
8138#ifdef FEATURE_WLAN_RA_FILTERING
8139/**
8140 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8141 * @cds_cfg: CDS Configuration
8142 * @hdd_ctx: Pointer to hdd context
8143 *
8144 * Return: none
8145 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308146static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008147 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308148{
8149 cds_cfg->ra_ratelimit_interval =
8150 hdd_ctx->config->RArateLimitInterval;
8151 cds_cfg->is_ra_ratelimit_enabled =
8152 hdd_ctx->config->IsRArateLimitEnabled;
8153}
8154#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308155static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008156 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308157{
8158}
8159#endif
8160
8161/**
8162 * hdd_update_cds_config() - API to update cds configuration parameters
8163 * @hdd_ctx: HDD Context
8164 *
8165 * Return: 0 for Success, errno on failure
8166 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008167static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308168{
8169 struct cds_config_info *cds_cfg;
8170
8171 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8172 if (!cds_cfg) {
8173 hdd_err("failed to allocate cds config");
8174 return -ENOMEM;
8175 }
8176
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008177 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008178 if (!hdd_ctx->config->nMaxPsPoll ||
8179 !hdd_ctx->config->enablePowersaveOffload) {
8180 cds_cfg->powersave_offload_enabled =
8181 hdd_ctx->config->enablePowersaveOffload;
8182 } else {
8183 if ((hdd_ctx->config->enablePowersaveOffload ==
8184 PS_QPOWER_NODEEPSLEEP) ||
8185 (hdd_ctx->config->enablePowersaveOffload ==
8186 PS_LEGACY_NODEEPSLEEP))
8187 cds_cfg->powersave_offload_enabled =
8188 PS_LEGACY_NODEEPSLEEP;
8189 else
8190 cds_cfg->powersave_offload_enabled =
8191 PS_LEGACY_DEEPSLEEP;
8192 hdd_info("Qpower disabled in cds config, %d",
8193 cds_cfg->powersave_offload_enabled);
8194 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308195 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8196 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8197 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8198 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8199 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8200
8201 /* Here ol_ini_info is used to store ini status of arp offload
8202 * ns offload and others. Currently 1st bit is used for arp
8203 * off load and 2nd bit for ns offload currently, rest bits are unused
8204 */
8205 if (hdd_ctx->config->fhostArpOffload)
8206 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8207 if (hdd_ctx->config->fhostNSOffload)
8208 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8209
8210 /*
8211 * Copy the DFS Phyerr Filtering Offload status.
8212 * This parameter reflects the value of the
8213 * dfs_phyerr_filter_offload flag as set in the ini.
8214 */
8215 cds_cfg->dfs_phyerr_filter_offload =
8216 hdd_ctx->config->fDfsPhyerrFilterOffload;
8217 if (hdd_ctx->config->ssdp)
8218 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8219
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308220 cds_cfg->force_target_assert_enabled =
8221 hdd_ctx->config->crash_inject_enabled;
8222
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308223 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8224 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8225
8226 cds_cfg->ap_maxoffload_reorderbuffs =
8227 hdd_ctx->config->apMaxOffloadReorderBuffs;
8228
8229 cds_cfg->ap_disable_intrabss_fwd =
8230 hdd_ctx->config->apDisableIntraBssFwd;
8231
8232 cds_cfg->dfs_pri_multiplier =
8233 hdd_ctx->config->dfsRadarPriMultiplier;
8234 cds_cfg->reorder_offload =
8235 hdd_ctx->config->reorderOffloadSupport;
8236
8237 /* IPA micro controller data path offload resource config item */
8238 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008239 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8240 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008241 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008242 hdd_ctx->config->IpaUcTxBufCount);
8243 hdd_ctx->config->IpaUcTxBufCount =
8244 rounddown_pow_of_two(
8245 hdd_ctx->config->IpaUcTxBufCount);
8246 if (!hdd_ctx->config->IpaUcTxBufCount) {
8247 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308248 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008249 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008250 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008251 hdd_ctx->config->IpaUcTxBufCount);
8252 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308253 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8254 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008255 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8256 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008257 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008258 hdd_ctx->config->IpaUcRxIndRingCount);
8259 hdd_ctx->config->IpaUcRxIndRingCount =
8260 rounddown_pow_of_two(
8261 hdd_ctx->config->IpaUcRxIndRingCount);
8262 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8263 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308264 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008265 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008266 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008267 hdd_ctx->config->IpaUcRxIndRingCount);
8268 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308269 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008270 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308271 cds_cfg->uc_tx_partition_base =
8272 hdd_ctx->config->IpaUcTxPartitionBase;
8273 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8274
8275 cds_cfg->ip_tcp_udp_checksum_offload =
8276 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308277 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308278 cds_cfg->ce_classify_enabled =
8279 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008280 cds_cfg->bpf_packet_filter_enable =
8281 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308282 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8283 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8284 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008285 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008286 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008287 cds_cfg->max_msdus_per_rxinorderind =
8288 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008289 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008290 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308291 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8292 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308293 cds_cfg->auto_power_save_fail_mode =
8294 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308295
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308296 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008297 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308298
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308299 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8300 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8301 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008302 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308303 cds_init_ini_config(cds_cfg);
8304 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308305
8306exit:
8307 qdf_mem_free(cds_cfg);
8308 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308309}
8310
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008311/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008312 * hdd_update_user_config() - API to update user configuration
8313 * parameters to obj mgr which are used by multiple components
8314 * @hdd_ctx: HDD Context
8315 *
8316 * Return: 0 for Success, errno on failure
8317 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008318static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008319{
8320 struct wlan_objmgr_psoc_user_config *user_config;
8321
8322 user_config = qdf_mem_malloc(sizeof(*user_config));
8323 if (user_config == NULL) {
8324 hdd_alert("Failed to alloc memory for user_config!");
8325 return -ENOMEM;
8326 }
8327
8328 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8329 user_config->dual_mac_feature_disable =
8330 hdd_ctx->config->dual_mac_feature_disable;
8331 user_config->indoor_channel_support =
8332 hdd_ctx->config->indoor_channel_support;
8333 user_config->is_11d_support_enabled =
8334 hdd_ctx->config->Is11dSupportEnabled;
8335 user_config->is_11h_support_enabled =
8336 hdd_ctx->config->Is11hSupportEnabled;
8337 user_config->optimize_chan_avoid_event =
8338 hdd_ctx->config->goptimize_chan_avoid_event;
8339 user_config->skip_dfs_chnl_in_p2p_search =
8340 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008341 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008342 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8343
8344 qdf_mem_free(user_config);
8345 return 0;
8346}
8347
8348/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008349 * hdd_init_thermal_info - Initialize thermal level
8350 * @hdd_ctx: HDD context
8351 *
8352 * Initialize thermal level at SME layer and set the thermal level callback
8353 * which would be called when a configured thermal threshold is hit.
8354 *
8355 * Return: 0 on success and errno on failure
8356 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008357static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008358{
8359 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308360 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008361
8362 thermal_param.smeThermalMgmtEnabled =
8363 hdd_ctx->config->thermalMitigationEnable;
8364 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8365
Poddar, Siddarth83905022016-04-16 17:56:08 -07008366 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8367 hdd_ctx->config->throttle_dutycycle_level0;
8368 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8369 hdd_ctx->config->throttle_dutycycle_level1;
8370 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8371 hdd_ctx->config->throttle_dutycycle_level2;
8372 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8373 hdd_ctx->config->throttle_dutycycle_level3;
8374
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008375 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8376 hdd_ctx->config->thermalTempMinLevel0;
8377 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8378 hdd_ctx->config->thermalTempMaxLevel0;
8379 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8380 hdd_ctx->config->thermalTempMinLevel1;
8381 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8382 hdd_ctx->config->thermalTempMaxLevel1;
8383 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8384 hdd_ctx->config->thermalTempMinLevel2;
8385 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8386 hdd_ctx->config->thermalTempMaxLevel2;
8387 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8388 hdd_ctx->config->thermalTempMinLevel3;
8389 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8390 hdd_ctx->config->thermalTempMaxLevel3;
8391
8392 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8393
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308394 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308395 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008396
8397 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8398 hdd_set_thermal_level_cb);
8399
8400 return 0;
8401
8402}
8403
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008404#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8405/**
8406 * hdd_hold_rtnl_lock - Hold RTNL lock
8407 *
8408 * Hold RTNL lock
8409 *
8410 * Return: True if held and false otherwise
8411 */
8412static inline bool hdd_hold_rtnl_lock(void)
8413{
8414 rtnl_lock();
8415 return true;
8416}
8417
8418/**
8419 * hdd_release_rtnl_lock - Release RTNL lock
8420 *
8421 * Release RTNL lock
8422 *
8423 * Return: None
8424 */
8425static inline void hdd_release_rtnl_lock(void)
8426{
8427 rtnl_unlock();
8428}
8429#else
8430static inline bool hdd_hold_rtnl_lock(void) { return false; }
8431static inline void hdd_release_rtnl_lock(void) { }
8432#endif
8433
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008434#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008435
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308436/* MAX iwpriv command support */
8437#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308438#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308439#define MAX_PKTLOG_SIZE 16
8440
8441/**
8442 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8443 * @hdd_ctx: hdd context
8444 * @set_value2: pktlog buffer size value
8445 *
8446 *
8447 * Return: 0 for success or error.
8448 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008449static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308450{
8451 struct sir_wifi_start_log start_log = { 0 };
8452 QDF_STATUS status;
8453
8454 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8455 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8456 start_log.ini_triggered = cds_is_packet_log_enabled();
8457 start_log.user_triggered = 1;
8458 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308459 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308460
8461 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8462 if (!QDF_IS_STATUS_SUCCESS(status)) {
8463 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8464 EXIT();
8465 return -EINVAL;
8466 }
8467
8468 return 0;
8469}
8470
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008471/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308472 * hdd_pktlog_clear_buff() - clear pktlog buffer
8473 * @hdd_ctx: hdd context
8474 *
8475 * Return: 0 for success or error.
8476 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008477static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308478{
8479 struct sir_wifi_start_log start_log;
8480 QDF_STATUS status;
8481
8482 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8483 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8484 start_log.ini_triggered = cds_is_packet_log_enabled();
8485 start_log.user_triggered = 1;
8486 start_log.size = 0;
8487 start_log.is_pktlog_buff_clear = true;
8488
8489 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8490 if (!QDF_IS_STATUS_SUCCESS(status)) {
8491 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8492 EXIT();
8493 return -EINVAL;
8494 }
8495
8496 return 0;
8497}
8498
8499
8500/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008501 * hdd_process_pktlog_command() - process pktlog command
8502 * @hdd_ctx: hdd context
8503 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308504 * @set_value2: pktlog buffer size value
8505 *
8506 * This function process pktlog command.
8507 * set_value2 only matters when set_value is 3 (set buff size)
8508 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008509 *
8510 * Return: 0 for success or error.
8511 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008512int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308513 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008514{
8515 int ret;
8516 bool enable;
8517 uint8_t user_triggered = 0;
8518
8519 ret = wlan_hdd_validate_context(hdd_ctx);
8520 if (0 != ret)
8521 return ret;
8522
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008523 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008524
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308525 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008526 hdd_err("invalid pktlog value %d", set_value);
8527 return -EINVAL;
8528 }
8529
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308530 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8531 if (set_value2 <= 0) {
8532 hdd_err("invalid pktlog size %d", set_value2);
8533 return -EINVAL;
8534 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8535 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8536 return -EINVAL;
8537 }
8538 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308539 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8540 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308541 }
8542
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008543 /*
8544 * set_value = 0 then disable packetlog
8545 * set_value = 1 enable packetlog forcefully
8546 * set_vlaue = 2 then disable packetlog if disabled through ini or
8547 * enable packetlog with AUTO type.
8548 */
8549 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8550 true : false;
8551
8552 if (1 == set_value) {
8553 enable = true;
8554 user_triggered = 1;
8555 }
8556
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308557 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008558}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008559
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008560/**
8561 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8562 * @hdd_ctx: HDD context
8563 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308564 * @user_triggered: triggered through iwpriv
8565 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008566 *
8567 * Return: 0 on success; error number otherwise
8568 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008569int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308570 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008571{
8572 struct sir_wifi_start_log start_log;
8573 QDF_STATUS status;
8574
8575 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8576 start_log.verbose_level =
8577 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008578 start_log.ini_triggered = cds_is_packet_log_enabled();
8579 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308580 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308581 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308582 /*
8583 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8584 * commands. Host uses this flag to decide whether to send pktlog
8585 * disable command to fw without sending pktlog enable command
8586 * previously. For eg, If vendor sends pktlog disable command without
8587 * sending pktlog enable command, then host discards the packet
8588 * but for iwpriv command, host will send it to fw.
8589 */
8590 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008591 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8592 if (!QDF_IS_STATUS_SUCCESS(status)) {
8593 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8594 EXIT();
8595 return -EINVAL;
8596 }
8597
8598 return 0;
8599}
8600#endif /* REMOVE_PKT_LOG */
8601
Komal Seelam92fff912016-03-24 11:51:41 +05308602/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008603 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8604 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308605 * @dev: Device Pointer
8606 * @num: Number of Valid Mac address
8607 *
8608 * Return: Pointer to MAC address buffer
8609 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008610static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8611 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308612{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008613 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308614}
Komal Seelam92fff912016-03-24 11:51:41 +05308615
8616/**
8617 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8618 * @hdd_ctx: HDD Context
8619 * @num: Number of random mac addresses needed
8620 *
8621 * Generate random addresses using bit manipulation on the base mac address
8622 *
8623 * Return: None
8624 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008625void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308626{
8627 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8628 uint32_t iter;
8629 struct hdd_config *ini = hdd_ctx->config;
8630 uint8_t *buf = NULL;
8631 uint8_t macaddr_b3, tmp_br3;
8632 uint8_t *src = ini->intfMacAddr[0].bytes;
8633
8634 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8635 buf = ini->intfMacAddr[iter].bytes;
8636 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8637 macaddr_b3 = buf[3];
8638 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8639 INTF_MACADDR_MASK;
8640 macaddr_b3 += tmp_br3;
8641 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8642 buf[0] |= 0x02;
8643 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008644 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308645 }
8646}
8647
8648/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008649 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308650 * @hdd_ctx: HDD Context
8651 *
8652 * API to get mac addresses from platform driver and update the driver
8653 * structures and configure FW with the base mac address.
8654 * Return: int
8655 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008656static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308657{
8658 uint32_t no_of_mac_addr, iter;
8659 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8660 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8661 uint8_t *addr, *buf;
8662 struct device *dev = hdd_ctx->parent_dev;
8663 struct hdd_config *ini = hdd_ctx->config;
8664 tSirMacAddr mac_addr;
8665 QDF_STATUS status;
8666
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008667 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308668
8669 if (no_of_mac_addr == 0 || !addr) {
8670 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8671 return -EINVAL;
8672 }
8673
8674 if (no_of_mac_addr > max_mac_addr)
8675 no_of_mac_addr = max_mac_addr;
8676
8677 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8678
8679 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8680 buf = ini->intfMacAddr[iter].bytes;
8681 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008682 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308683 }
8684
8685 status = sme_set_custom_mac_addr(mac_addr);
8686
8687 if (!QDF_IS_STATUS_SUCCESS(status))
8688 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008689
Komal Seelam92fff912016-03-24 11:51:41 +05308690 if (no_of_mac_addr < max_mac_addr)
8691 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8692 no_of_mac_addr);
8693 return 0;
8694}
8695
8696/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008697 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8698 * @hdd_ctx: HDD Context
8699 *
8700 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8701 * will generate its own MAC and update it to FW.
8702 *
8703 * Return: 0 for success
8704 * Non-zero error code for failure
8705 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008706static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008707{
8708 tSirMacAddr customMacAddr;
8709 QDF_STATUS status;
8710
8711 qdf_mem_copy(&customMacAddr,
8712 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8713 sizeof(tSirMacAddr));
8714 status = sme_set_custom_mac_addr(customMacAddr);
8715 if (!QDF_IS_STATUS_SUCCESS(status))
8716 return -EAGAIN;
8717 return 0;
8718}
8719
8720/**
Komal Seelam92fff912016-03-24 11:51:41 +05308721 * hdd_initialize_mac_address() - API to get wlan mac addresses
8722 * @hdd_ctx: HDD Context
8723 *
8724 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8725 * is provisioned with mac addresses, driver uses it, else it will use
8726 * wlan_mac.bin to update HW MAC addresses.
8727 *
8728 * Return: None
8729 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008730static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308731{
8732 QDF_STATUS status;
8733 int ret;
8734
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008735 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308736 if (ret == 0)
8737 return;
8738
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008739 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8740 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308741
8742 status = hdd_update_mac_config(hdd_ctx);
8743
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008744 if (QDF_IS_STATUS_SUCCESS(status))
8745 return;
8746
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008747 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8748 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008749
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008750 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008751 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008752 if (ret != 0) {
8753 hdd_err("MAC address out-of-sync, ret:%d", ret);
8754 QDF_ASSERT(ret);
8755 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008756 }
Komal Seelam92fff912016-03-24 11:51:41 +05308757}
8758
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008759static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008760{
8761 int vdev_id = 0;
8762 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8763 int value = hdd_ctx->config->smart_chainmask_enabled;
8764 int vpdev = PDEV_CMD;
8765 int ret;
8766
Naveen Rawat247a8682017-06-05 15:00:31 -07008767 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008768 if (ret)
8769 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8770
8771 return ret;
8772}
8773
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008774static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008775{
8776 int vdev_id = 0;
8777 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8778 int value = hdd_ctx->config->alternative_chainmask_enabled;
8779 int vpdev = PDEV_CMD;
8780 int ret;
8781
Naveen Rawat247a8682017-06-05 15:00:31 -07008782 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008783 if (ret)
8784 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8785 ret);
8786
8787 return ret;
8788}
8789
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008790static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008791{
8792 int vdev_id = 0;
8793 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8794 int value = hdd_ctx->config->ani_enabled;
8795 int vpdev = PDEV_CMD;
8796 int ret;
8797
Naveen Rawat247a8682017-06-05 15:00:31 -07008798 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008799 if (ret)
8800 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8801
8802 return ret;
8803}
8804
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008805/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008806 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8807 * @hdd_ctx: HDD context
8808 *
8809 * Pre configurations to be done at lower layer before calling cds enable.
8810 *
8811 * Return: 0 on success and errno on failure.
8812 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008813static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008814{
8815 int ret;
8816 QDF_STATUS status;
8817 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008818 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008819
Leo Changfdb45c32016-10-28 11:09:23 -07008820 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008821 /*
8822 * Set 802.11p config
8823 * TODO-OCB: This has been temporarily added here to ensure this
8824 * parameter is set in CSR when we init the channel list. This should
8825 * be removed once the 5.9 GHz channels are added to the regulatory
8826 * domain.
8827 */
8828 hdd_set_dot11p_config(hdd_ctx);
8829
8830 /*
8831 * Note that the cds_pre_enable() sequence triggers the cfg download.
8832 * The cfg download must occur before we update the SME config
8833 * since the SME config operation must access the cfg database
8834 */
8835 status = hdd_set_sme_config(hdd_ctx);
8836
8837 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008838 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008839 ret = qdf_status_to_os_return(status);
8840 goto out;
8841 }
8842
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008843 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8844 if (QDF_STATUS_SUCCESS != status) {
8845 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8846 ret = qdf_status_to_os_return(status);
8847 goto out;
8848 }
8849
Naveen Rawat247a8682017-06-05 15:00:31 -07008850 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008851 hdd_ctx->config->tx_chain_mask_1ss,
8852 PDEV_CMD);
8853 if (0 != ret) {
8854 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8855 goto out;
8856 }
8857
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008858 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8859 if (ret)
8860 goto out;
8861
8862 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8863 if (ret)
8864 goto out;
8865
Jeff Johnson12a744b2017-04-04 08:19:37 -07008866 ret = hdd_set_ani_enabled(hdd_ctx);
8867 if (ret)
8868 goto out;
8869
Naveen Rawat247a8682017-06-05 15:00:31 -07008870 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008871 hdd_ctx->config->arp_ac_category,
8872 PDEV_CMD);
8873 if (0 != ret) {
8874 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8875 hdd_ctx->config->arp_ac_category, ret);
8876 goto out;
8877 }
8878
8879
Prashanth Bhatta07998752016-04-28 12:35:33 -07008880 status = hdd_set_sme_chan_list(hdd_ctx);
8881 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008882 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008883 ret = qdf_status_to_os_return(status);
8884 goto out;
8885 }
8886
8887 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008888 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008889 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008890 ret = -EINVAL;
8891 goto out;
8892 }
8893
Prashanth Bhatta07998752016-04-28 12:35:33 -07008894 /*
8895 * Set the MAC Address Currently this is used by HAL to add self sta.
8896 * Remove this once self sta is added as part of session open.
8897 */
8898 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8899 hdd_ctx->config->intfMacAddr[0].bytes,
8900 sizeof(hdd_ctx->config->intfMacAddr[0]));
8901
8902 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8903 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8904 hal_status, hal_status);
8905 ret = -EINVAL;
8906 goto out;
8907 }
8908
8909 hdd_init_channel_avoidance(hdd_ctx);
8910
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308911 /* update enable sap mandatory chan list */
8912 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8913 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008914out:
8915 return ret;
8916}
8917
8918/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008919 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8920 * @context_ptr - hdd context pointer
8921 * @event_ptr - event structure pointer
8922 *
8923 * This is the p2p listen offload stop event handler, it sends vendor
8924 * event back to supplicant to notify the stop reason.
8925 *
8926 * Return: None
8927 */
8928static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8929 void *event_ptr)
8930{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008931 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008932 struct sir_p2p_lo_event *evt = event_ptr;
8933 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008934 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008935
8936 ENTER();
8937
8938 if (hdd_ctx == NULL) {
8939 hdd_err("Invalid HDD context pointer");
8940 return;
8941 }
8942
Peng Xu5c682812017-08-06 07:39:13 -07008943 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8944 if (!adapter) {
8945 hdd_err("Cannot find adapter by vdev_id = %d",
8946 evt->vdev_id);
8947 return;
8948 }
8949
Peng Xu8fdaa492016-06-22 10:20:47 -07008950 vendor_event =
8951 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008952 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008953 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8954 GFP_KERNEL);
8955
8956 if (!vendor_event) {
8957 hdd_err("cfg80211_vendor_event_alloc failed");
8958 return;
8959 }
8960
8961 if (nla_put_u32(vendor_event,
8962 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8963 evt->reason_code)) {
8964 hdd_err("nla put failed");
8965 kfree_skb(vendor_event);
8966 return;
8967 }
8968
8969 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008970 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8971 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008972}
8973
8974/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308975 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8976 * @hdd_ctx: HDD context
8977 *
8978 * This function sends the adaptive dwell time config configuration to the
8979 * firmware via WMA
8980 *
8981 * Return: 0 - success, < 0 - failure
8982 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008983static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308984{
8985 QDF_STATUS status;
8986 struct adaptive_dwelltime_params dwelltime_params;
8987
8988 dwelltime_params.is_enabled =
8989 hdd_ctx->config->adaptive_dwell_mode_enabled;
8990 dwelltime_params.dwelltime_mode =
8991 hdd_ctx->config->global_adapt_dwelltime_mode;
8992 dwelltime_params.lpf_weight =
8993 hdd_ctx->config->adapt_dwell_lpf_weight;
8994 dwelltime_params.passive_mon_intval =
8995 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8996 dwelltime_params.wifi_act_threshold =
8997 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8998
8999 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9000 &dwelltime_params);
9001
9002 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9003 if (!QDF_IS_STATUS_SUCCESS(status)) {
9004 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9005 return -EAGAIN;
9006 }
9007 return 0;
9008}
9009
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009010int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309011{
9012 QDF_STATUS status;
9013 struct wmi_dbs_scan_sel_params dbs_scan_params;
9014 uint32_t i = 0;
9015 uint8_t count = 0, numentries = 0;
9016 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9017 * CDS_DBS_SCAN_CLIENTS_MAX];
9018
9019 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009020 if (hdd_ctx->config->dual_mac_feature_disable ==
9021 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309022 return -EINVAL;
9023
9024 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9025 dbs_scan_config, &numentries,
9026 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9027 * CDS_DBS_SCAN_CLIENTS_MAX));
9028
9029 hdd_info("numentries %hu", numentries);
9030 if (!numentries) {
9031 hdd_info("Donot send scan_selection_config");
9032 return 0;
9033 }
9034
9035 /* hdd_set_fw_log_params */
9036 dbs_scan_params.num_clients = 0;
9037 while (count < (numentries - 2)) {
9038 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9039 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9040 dbs_scan_params.num_non_dbs_scans[i] =
9041 dbs_scan_config[count + 2];
9042 dbs_scan_params.num_clients++;
9043 hdd_debug("module:%d NDS:%d NNDS:%d",
9044 dbs_scan_params.module_id[i],
9045 dbs_scan_params.num_dbs_scans[i],
9046 dbs_scan_params.num_non_dbs_scans[i]);
9047 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9048 i++;
9049 }
9050
9051 dbs_scan_params.pdev_id = 0;
9052
9053 hdd_debug("clients:%d pdev:%d",
9054 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9055
9056 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9057 &dbs_scan_params);
9058 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9059 if (!QDF_IS_STATUS_SUCCESS(status)) {
9060 hdd_err("Failed to send DBS Scan selection configuration!");
9061 return -EAGAIN;
9062 }
9063 return 0;
9064}
9065
Arun Khandavallid4349a92016-07-25 11:10:43 +05309066#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9067/**
9068 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9069 * @hdd_ctx: HDD context
9070 *
9071 * Set auto shutdown callback to get indications from firmware to indicate
9072 * userspace to shutdown WLAN after a configured amount of inactivity.
9073 *
9074 * Return: 0 on success and errno on failure.
9075 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009076static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309077{
9078 QDF_STATUS status;
9079
9080 if (!hdd_ctx->config->WlanAutoShutdown)
9081 return 0;
9082
9083 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9084 wlan_hdd_auto_shutdown_cb);
9085 if (status != QDF_STATUS_SUCCESS)
9086 hdd_err("Auto shutdown feature could not be enabled: %d",
9087 status);
9088
9089 return qdf_status_to_os_return(status);
9090}
9091#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009092static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309093{
9094 return 0;
9095}
9096#endif
9097
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009098static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009099{
9100 QDF_STATUS status = QDF_STATUS_SUCCESS;
9101
9102 switch (hdd_ctx->config->dual_mac_feature_disable) {
9103 case DISABLE_DBS_CXN_AND_SCAN:
9104 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9105 if (status != QDF_STATUS_SUCCESS)
9106 hdd_err("Failed to disable dual mac features");
9107 break;
9108 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9109 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9110 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9111 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9112 if (status != QDF_STATUS_SUCCESS)
9113 hdd_err("Failed to set dbs scan and fw mode config");
9114 break;
9115 default:
9116 break;
9117 }
9118
9119 return status;
9120}
9121
Arun Khandavallid4349a92016-07-25 11:10:43 +05309122/**
9123 * hdd_features_init() - Init features
9124 * @hdd_ctx: HDD context
9125 * @adapter: Primary adapter context
9126 *
9127 * Initialize features and their feature context after WLAN firmware is up.
9128 *
9129 * Return: 0 on success and errno on failure.
9130 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009131static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309132{
9133 tSirTxPowerLimit hddtxlimit;
9134 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309135 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309136 int ret;
9137
9138 ENTER();
9139
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009140 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309141 if (ret) {
9142 hdd_err("Failed to update country code: %d", ret);
9143 goto out;
9144 }
9145
9146 /* FW capabilities received, Set the Dot11 mode */
9147 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009148 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9149 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309150
Arun Khandavallid4349a92016-07-25 11:10:43 +05309151
9152 if (hdd_ctx->config->fIsImpsEnabled)
9153 hdd_set_idle_ps_config(hdd_ctx, true);
9154 else
9155 hdd_set_idle_ps_config(hdd_ctx, false);
9156
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309157 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009158 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309159
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309160 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9161 hdd_warn("Error in setting Voltage Corner mode config to FW");
9162
Arun Khandavallid4349a92016-07-25 11:10:43 +05309163 if (hdd_lro_init(hdd_ctx))
9164 hdd_err("Unable to initialize LRO in fw");
9165
9166 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9167 hdd_err("Unable to send adaptive dwelltime setting to FW");
9168
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309169 if (hdd_dbs_scan_selection_init(hdd_ctx))
9170 hdd_err("Unable to send DBS scan selection setting to FW");
9171
Arun Khandavallid4349a92016-07-25 11:10:43 +05309172 ret = hdd_init_thermal_info(hdd_ctx);
9173 if (ret) {
9174 hdd_err("Error while initializing thermal information");
9175 goto deregister_frames;
9176 }
9177
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309178 if (cds_is_packet_log_enabled())
9179 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9180
Arun Khandavallid4349a92016-07-25 11:10:43 +05309181 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9182 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9183 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9184 if (!QDF_IS_STATUS_SUCCESS(status))
9185 hdd_err("Error setting txlimit in sme: %d", status);
9186
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009187 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309188
Arun Khandavallid4349a92016-07-25 11:10:43 +05309189 ret = hdd_register_cb(hdd_ctx);
9190 if (ret) {
9191 hdd_err("Failed to register HDD callbacks!");
9192 goto deregister_frames;
9193 }
9194
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009195 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9196 if (!QDF_IS_STATUS_SUCCESS(status)) {
9197 hdd_err("Failed to set dbs scan and fw mode cfg");
9198 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309199 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009200
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309201 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9202 status = sme_enable_disable_chanavoidind_event(
9203 hdd_ctx->hHal, 0);
9204 if (!QDF_IS_STATUS_SUCCESS(status)) {
9205 hdd_err("Failed to disable Chan Avoidance Indication");
9206 goto deregister_cb;
9207 }
9208 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309209
Manjeet Singha9cae432017-02-28 11:58:22 +05309210 if (hdd_ctx->config->enable_5g_band_pref) {
9211 band_pref_params.rssi_boost_threshold_5g =
9212 hdd_ctx->config->rssi_boost_threshold_5g;
9213 band_pref_params.rssi_boost_factor_5g =
9214 hdd_ctx->config->rssi_boost_factor_5g;
9215 band_pref_params.max_rssi_boost_5g =
9216 hdd_ctx->config->max_rssi_boost_5g;
9217 band_pref_params.rssi_penalize_threshold_5g =
9218 hdd_ctx->config->rssi_penalize_threshold_5g;
9219 band_pref_params.rssi_penalize_factor_5g =
9220 hdd_ctx->config->rssi_penalize_factor_5g;
9221 band_pref_params.max_rssi_penalize_5g =
9222 hdd_ctx->config->max_rssi_penalize_5g;
9223 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9224 }
9225
Arun Khandavallid4349a92016-07-25 11:10:43 +05309226 /* register P2P Listen Offload event callback */
9227 if (wma_is_p2p_lo_capable())
9228 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9229 wlan_hdd_p2p_lo_event_callback);
9230
9231 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9232
9233 if (ret)
9234 goto deregister_cb;
9235
9236 EXIT();
9237 return 0;
9238
9239deregister_cb:
9240 hdd_deregister_cb(hdd_ctx);
9241deregister_frames:
9242 wlan_hdd_cfg80211_deregister_frames(adapter);
9243out:
9244 return -EINVAL;
9245
9246}
9247
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009248/**
9249 * hdd_features_deinit() - Deinit features
9250 * @hdd_ctx: HDD context
9251 *
9252 * De-Initialize features and their feature context.
9253 *
9254 * Return: none.
9255 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009256static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009257{
9258 wlan_hdd_tsf_deinit(hdd_ctx);
9259}
9260
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309261/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009262 * hdd_register_bcn_cb() - register scan beacon callback
9263 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309264 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009265 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309266 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009267static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309268{
9269 QDF_STATUS status;
9270
9271 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9272 wlan_cfg80211_inform_bss_frame,
9273 SCAN_CB_TYPE_INFORM_BCN);
9274 if (!QDF_IS_STATUS_SUCCESS(status)) {
9275 hdd_err("failed with status code %08d [x%08x]",
9276 status, status);
9277 return status;
9278 }
9279
9280 return QDF_STATUS_SUCCESS;
9281}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309282
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309283/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309284 * hdd_configure_cds() - Configure cds modules
9285 * @hdd_ctx: HDD context
9286 * @adapter: Primary adapter context
9287 *
9288 * Enable Cds modules after WLAN firmware is up.
9289 *
9290 * Return: 0 on success and errno on failure.
9291 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009292int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309293{
9294 int ret;
9295 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309296 int set_value;
9297 uint32_t num_abg_tx_chains = 0;
9298 uint32_t num_11b_tx_chains = 0;
9299 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009300 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309301
9302 if (hdd_ctx->config->sifs_burst_duration) {
9303 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9304 hdd_ctx->config->sifs_burst_duration;
9305
9306 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9307 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9308 set_value, PDEV_CMD);
9309 }
9310
9311 if (hdd_ctx->config->is_force_1x1)
9312 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9313 1, PDEV_CMD);
9314 /* set chip power save failure detected callback */
9315 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9316 hdd_chip_pwr_save_fail_detected_cb);
9317
9318 if (hdd_ctx->config->max_mpdus_inampdu) {
9319 set_value = hdd_ctx->config->max_mpdus_inampdu;
9320 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9321 set_value, PDEV_CMD);
9322 }
9323
9324 if (hdd_ctx->config->enable_rts_sifsbursting) {
9325 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9326 sme_cli_set_command(0,
9327 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9328 set_value, PDEV_CMD);
9329 }
9330
9331 if (hdd_ctx->config->sap_get_peer_info) {
9332 set_value = hdd_ctx->config->sap_get_peer_info;
9333 sme_cli_set_command(0,
9334 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9335 set_value, PDEV_CMD);
9336 }
9337
9338 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9339 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9340 if (!hdd_ctx->config->enable2x2) {
9341 if (num_11b_tx_chains > 1)
9342 num_11b_tx_chains = 1;
9343 if (num_11ag_tx_chains > 1)
9344 num_11ag_tx_chains = 1;
9345 }
9346 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9347 num_11b_tx_chains);
9348 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9349 num_11ag_tx_chains);
9350 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9351 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309352
9353 ret = hdd_pre_enable_configure(hdd_ctx);
9354 if (ret) {
9355 hdd_err("Failed to pre-configure cds");
9356 goto out;
9357 }
9358
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009359 /* Always get latest IPA resources allocated from cds_open and configure
9360 * IPA module before configuring them to FW. Sequence required as crash
9361 * observed otherwise.
9362 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009363 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9364 hdd_err("Failed to setup pipes");
9365 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009366 }
9367
Arun Khandavallifae92942016-08-01 13:31:08 +05309368 /*
9369 * Start CDS which starts up the SME/MAC/HAL modules and everything
9370 * else
9371 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009372 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309373
9374 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009375 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309376 goto out;
9377 }
9378
9379 status = hdd_post_cds_enable_config(hdd_ctx);
9380 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009381 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009382 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309383 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309384 status = hdd_register_bcn_cb(hdd_ctx);
9385 if (!QDF_IS_STATUS_SUCCESS(status)) {
9386 hdd_alert("hdd_post_cds_enable_config failed");
9387 goto cds_disable;
9388 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309389
9390 ret = hdd_features_init(hdd_ctx, adapter);
9391 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009392 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309393
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009394 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009395 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009396 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9397 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009398 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009399 goto cds_disable;
9400 }
9401
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309402 if (hdd_enable_egap(hdd_ctx))
9403 hdd_debug("enhance green ap is not enabled");
9404
Nachiket Kukadedd302662017-07-13 17:31:44 +05309405 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9406 hdd_debug("Failed to set wow pulse");
9407
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309408 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9409 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9410
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309411
9412 if (hdd_ctx->config->enable_phy_reg_retention)
9413 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9414 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9415
Arun Khandavallifae92942016-08-01 13:31:08 +05309416 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009417
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009418cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009419 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009420
Arun Khandavallifae92942016-08-01 13:31:08 +05309421out:
9422 return -EINVAL;
9423}
9424
9425/**
9426 * hdd_deconfigure_cds() -De-Configure cds
9427 * @hdd_ctx: HDD context
9428 *
9429 * Deconfigure Cds modules before WLAN firmware is down.
9430 *
9431 * Return: 0 on success and errno on failure.
9432 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009433static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309434{
9435 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009436 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309437
9438 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009439
9440 /* De-init features */
9441 hdd_features_deinit(hdd_ctx);
9442
Arun Khandavallifae92942016-08-01 13:31:08 +05309443 /* De-register the SME callbacks */
9444 hdd_deregister_cb(hdd_ctx);
9445
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009446 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309447 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9448 hdd_err("Failed to Disable the CDS Modules! :%d",
9449 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009450 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309451 }
9452
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309453 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9454 hdd_err("Failed to disconnect pipes");
9455 ret = -EINVAL;
9456 }
9457
Arun Khandavallifae92942016-08-01 13:31:08 +05309458 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009459 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309460}
9461
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009462#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9463static void hdd_deregister_policy_manager_callback(
9464 struct wlan_objmgr_psoc *psoc)
9465{
9466 if (QDF_STATUS_SUCCESS !=
9467 policy_mgr_deregister_hdd_cb(psoc)) {
9468 hdd_err("HDD callback deregister with policy manager failed");
9469 }
9470}
9471#else
9472static void hdd_deregister_policy_manager_callback(
9473 struct wlan_objmgr_psoc *psoc)
9474{
9475}
9476#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309477
9478/**
9479 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9480 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009481 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309482 *
9483 * This function maintains the driver state machine it will be invoked from
9484 * exit, shutdown and con_mode change handler. Depending on the driver state
9485 * shall perform the stopping/closing of the modules.
9486 *
9487 * Return: 0 for success; non-zero for failure
9488 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009489int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309490{
9491 void *hif_ctx;
9492 qdf_device_t qdf_ctx;
9493 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309494 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009495 bool is_idle_stop = !cds_is_driver_unloading() &&
9496 !cds_is_driver_recovering();
9497 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309498
9499 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009500 hdd_alert("stop WLAN module: entering driver status=%d",
9501 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309502
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009503 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9504
Arun Khandavallifae92942016-08-01 13:31:08 +05309505 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9506 if (!qdf_ctx) {
9507 hdd_err("QDF device context NULL");
9508 return -EINVAL;
9509 }
9510
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309511 mutex_lock(&hdd_ctx->iface_change_lock);
9512 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009513 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +05309514
Dustin Brown70111822017-03-30 15:31:40 -07009515 active_threads = cds_return_external_threads_count();
9516 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009517 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009518 active_threads, hdd_ctx->isWiphySuspended);
9519
9520 cds_print_external_threads();
9521
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009522 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009523 mutex_unlock(&hdd_ctx->iface_change_lock);
9524 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009525 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309526 hdd_prevent_suspend_timeout(
9527 hdd_ctx->config->iface_change_wait_time,
9528 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009529 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009530 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -07009531 return 0;
9532 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009533 }
9534
Arun Khandavallifae92942016-08-01 13:31:08 +05309535 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9536
9537 switch (hdd_ctx->driver_status) {
9538 case DRIVER_MODULES_UNINITIALIZED:
9539 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309540 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309541 case DRIVER_MODULES_CLOSED:
9542 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309543 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309544 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309545 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309546 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009547 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309548 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309549 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309550 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009551 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309552 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9553 break;
9554 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009555 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309556 break;
9557 default:
9558 hdd_err("Trying to stop wlan in a wrong state: %d",
9559 hdd_ctx->driver_status);
9560 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309561 ret = -EINVAL;
9562 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309563 }
9564
Rajeev Kumarbe021242017-02-16 16:12:23 -08009565 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309566 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9567 hdd_err("Failed to process post CDS disable Modules! :%d",
9568 qdf_status);
9569 ret = -EINVAL;
9570 QDF_ASSERT(0);
9571 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07009572
9573 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
9574 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9575 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
9576 ret = -EINVAL;
9577 QDF_ASSERT(0);
9578 }
9579
Jeff Johnsone4b14592017-09-13 14:23:33 -07009580 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309581 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009582 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309583 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309584 QDF_ASSERT(0);
9585 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009586
Arun Khandavallifae92942016-08-01 13:31:08 +05309587 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9588 if (!hif_ctx) {
9589 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309590 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309591 }
9592
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309593 hdd_runtime_suspend_context_deinit(hdd_ctx);
9594
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309595 if (hdd_ctx->target_hw_name) {
9596 qdf_mem_free(hdd_ctx->target_hw_name);
9597 hdd_ctx->target_hw_name = NULL;
9598 }
9599
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309600 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309601
9602 ol_cds_free();
9603
Dustin Brown70111822017-03-30 15:31:40 -07009604 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309605 ret = pld_power_off(qdf_ctx->dev);
9606 if (ret)
9607 hdd_err("CNSS power down failed put device into Low power mode:%d",
9608 ret);
9609 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309610
9611 /* Once the firmware sequence is completed reset this flag */
9612 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309613 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009614 /*
9615 * Reset total mac phy during module stop such that during
9616 * next module start same psoc is used to populate new service
9617 * ready data
9618 */
9619 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309620
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309621done:
9622 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009623 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309624 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07009625 hdd_alert("stop WLAN module: exit driver status=%d",
9626 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309627 EXIT();
9628
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309629 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309630
9631}
9632
9633/**
9634 * hdd_iface_change_callback() - Function invoked when stop modules expires
9635 * @priv: pointer to hdd context
9636 *
9637 * This function is invoked when the timer waiting for the interface change
9638 * expires, it shall cut-down the power to wlan and stop all the modules.
9639 *
9640 * Return: void
9641 */
9642static void hdd_iface_change_callback(void *priv)
9643{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009644 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309645 int ret;
9646 int status = wlan_hdd_validate_context(hdd_ctx);
9647
9648 if (status)
9649 return;
9650
9651 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009652 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009653 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309654 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009655 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309656 EXIT();
9657}
9658
9659/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309660 * hdd_state_info_dump() - prints state information of hdd layer
9661 * @buf: buffer pointer
9662 * @size: size of buffer to be filled
9663 *
9664 * This function is used to dump state information of hdd layer
9665 *
9666 * Return: None
9667 */
9668static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9669{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009670 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309671 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9672 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009673 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009674 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309675 uint16_t len = 0;
9676 char *buf = *buf_ptr;
9677
9678 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9679 if (!hdd_ctx) {
9680 hdd_err("Failed to get hdd context ");
9681 return;
9682 }
9683
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009684 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309685
9686 len += scnprintf(buf + len, *size - len,
9687 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9688 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009689 "\n is_scheduler_suspended %d",
9690 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309691
9692 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9693
9694 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009695 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309696 if (adapter->dev)
9697 len += scnprintf(buf + len, *size - len,
9698 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009699 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309700 "\n device_mode: %d", adapter->device_mode);
9701 switch (adapter->device_mode) {
9702 case QDF_STA_MODE:
9703 case QDF_P2P_CLIENT_MODE:
9704 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9705 len += scnprintf(buf + len, *size - len,
9706 "\n connState: %d",
9707 hdd_sta_ctx->conn_info.connState);
9708 break;
9709
9710 default:
9711 break;
9712 }
9713 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9714 adapter_node = next;
9715 }
9716
9717 *size -= len;
9718 *buf_ptr += len;
9719}
9720
9721/**
9722 * hdd_register_debug_callback() - registration function for hdd layer
9723 * to print hdd state information
9724 *
9725 * Return: None
9726 */
9727static void hdd_register_debug_callback(void)
9728{
9729 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9730}
9731
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309732/*
9733 * wlan_init_bug_report_lock() - Initialize bug report lock
9734 *
9735 * This function is used to create bug report lock
9736 *
9737 * Return: None
9738 */
9739static void wlan_init_bug_report_lock(void)
9740{
9741 p_cds_contextType p_cds_context;
9742
9743 p_cds_context = cds_get_global_context();
9744 if (!p_cds_context) {
9745 hdd_err("cds context is NULL");
9746 return;
9747 }
9748
9749 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9750}
9751
Mohit Khannaf8f96822017-05-17 17:11:59 -07009752void hdd_dp_trace_init(struct hdd_config *config)
9753{
9754
9755 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9756 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9757 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9758 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9759 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9760 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9761 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +08009762 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -07009763
9764 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9765 &num_entries, sizeof(config_params));
9766
9767 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +08009768 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
9769 if (bw_compute_interval)
9770 thresh_time_limit = 1000 / bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -07009771 else
9772 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9773
9774 switch (num_entries) {
9775 case 4:
9776 proto_bitmap = config_params[3];
9777 case 3:
9778 verbosity = config_params[2];
9779 case 2:
9780 thresh = config_params[1];
9781 case 1:
9782 live_mode = config_params[0];
9783 default:
9784 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9785 live_mode, thresh, thresh_time_limit,
9786 verbosity, proto_bitmap);
9787 };
9788
9789 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9790 verbosity, proto_bitmap);
9791
9792}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309793/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009794 * hdd_wlan_startup() - HDD init function
9795 * @dev: Pointer to the underlying device
9796 *
9797 * This is the driver startup code executed once a WLAN device has been detected
9798 *
9799 * Return: 0 for success, < 0 for failure
9800 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309801int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009802{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309803 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009804 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009805 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009806 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009807
9808 ENTER();
9809
Arun Khandavallifae92942016-08-01 13:31:08 +05309810 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009811
9812 if (IS_ERR(hdd_ctx))
9813 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009814
Abhishek Singhe9068f12017-03-31 14:14:52 +05309815 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9816 DEFAULT_PSOC_ID);
9817 if (ret) {
9818 hdd_err("Psoc creation fails!");
9819 QDF_BUG(0);
9820 goto err_hdd_free_context;
9821 }
9822
Arun Khandavallifae92942016-08-01 13:31:08 +05309823 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9824 hdd_iface_change_callback, (void *)hdd_ctx);
9825
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309826 qdf_nbuf_init_replenish_timer();
9827
Arun Khandavallifae92942016-08-01 13:31:08 +05309828 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309829#ifdef FEATURE_WLAN_CH_AVOID
9830 mutex_init(&hdd_ctx->avoid_freq_lock);
9831#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309832
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009833 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009834 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309835
Jeff Johnson957bc272017-02-02 08:54:48 -08009836 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309837 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009838 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009839 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009840 }
9841
Yingying Tang80e15f32016-09-27 18:23:01 +08009842 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009843
Anurag Chouhan6d760662016-02-20 16:05:43 +05309844 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009845
9846 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009847 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309848 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009849 }
9850
Prashanth Bhatta07998752016-04-28 12:35:33 -07009851 ret = hdd_wiphy_init(hdd_ctx);
9852 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009853 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309854 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009855 }
9856
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309857 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009858 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309859
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309860 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009861 goto err_wiphy_unregister;
9862
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309863 wlan_hdd_init_chan_info(hdd_ctx);
9864
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009865 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009866
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309867 ret = hdd_register_notifiers(hdd_ctx);
9868 if (ret)
9869 goto err_ipa_cleanup;
9870
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009871 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009872
Jeff Johnson957bc272017-02-02 08:54:48 -08009873 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9874 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009875 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009876 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009877 }
9878
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009879 hdd_release_rtnl_lock();
9880 rtnl_held = false;
9881
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009882 wlan_hdd_update_11n_mode(hdd_ctx->config);
9883
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009884#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309885 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309886 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009887 hdd_skip_acs_scan_timer_handler,
9888 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309889 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009890 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009891 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009892#endif
9893
Prashanth Bhattaab004382016-10-11 16:08:11 -07009894 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009895
Jeff Johnson9afc5012016-09-23 13:56:27 -07009896 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009897
Nirav Shahbd36b062016-07-18 11:12:59 +05309898 if (hdd_ctx->rps)
9899 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009900
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309901 status = wlansap_global_init();
9902 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009903 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009904
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009905 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309906 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009907
Arun Khandavallifae92942016-08-01 13:31:08 +05309908 if (hdd_ctx->config->fIsImpsEnabled)
9909 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -07009910 else
9911 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309912
Mukul Sharma07bd8752017-10-10 16:58:14 +05309913 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309914 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309915 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309916 hdd_prevent_suspend_timeout(
9917 hdd_ctx->config->iface_change_wait_time,
9918 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
9919 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309920
Sachin Ahujadddd2632017-03-07 19:07:24 +05309921 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009922 goto success;
9923
Jeff Johnson957bc272017-02-02 08:54:48 -08009924err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009925 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009926
Jeff Johnson46bde382017-02-01 15:31:16 -08009927err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309928 if (rtnl_held)
9929 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009930
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309931 unregister_netdevice_notifier(&hdd_netdev_notifier);
9932
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309933err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309934 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009936err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009937 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009938
Arun Khandavallifae92942016-08-01 13:31:08 +05309939err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009940 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309941
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009942err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309943 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009944 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309945 if (!QDF_IS_STATUS_SUCCESS(status)) {
9946 hdd_err("Failed to close CDS Scheduler");
9947 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9948 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009949 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009950
Houston Hoffman47a4a052016-11-14 23:22:44 -08009951 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009952 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009953 hdd_exit_netlink_services(hdd_ctx);
9954
Dustin Brown20912462017-06-07 13:48:25 -07009955 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9956
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009957err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309958 if (cds_is_fw_down())
9959 hdd_err("Not setting the complete event as fw is down");
9960 else
9961 hdd_start_complete(ret);
9962
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309963 qdf_nbuf_deinit_replenish_timer();
Arun Khandavallifae92942016-08-01 13:31:08 +05309964 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9965 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009966 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07009967 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009968
9969success:
9970 EXIT();
9971 return 0;
9972}
9973
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009974/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309975 * hdd_wlan_update_target_info() - update target type info
9976 * @hdd_ctx: HDD context
9977 * @context: hif context
9978 *
9979 * Update target info received from firmware in hdd context
9980 * Return:None
9981 */
9982
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009983void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309984{
9985 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9986
9987 if (!tgt_info) {
9988 hdd_err("Target info is Null");
9989 return;
9990 }
9991
9992 hdd_ctx->target_type = tgt_info->target_type;
9993}
9994
9995/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05309996 * hdd_get_nud_stats_cb() - callback api to update the stats
9997 * received from the firmware
9998 * @data: pointer to adapter.
9999 * @rsp: pointer to data received from FW.
10000 *
10001 * This is called when wlan driver received response event for
10002 * get arp stats to firmware.
10003 *
10004 * Return: None
10005 */
10006static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10007{
10008 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10009 struct hdd_nud_stats_context *context;
10010 int status;
10011 struct hdd_adapter *adapter = NULL;
10012
10013 ENTER();
10014
10015 if (!rsp) {
10016 hdd_err("data is null");
10017 return;
10018 }
10019
10020 status = wlan_hdd_validate_context(hdd_ctx);
10021 if (0 != status)
10022 return;
10023
10024 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10025 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10026 hdd_err("Invalid adapter or adapter has invalid magic");
10027 return;
10028 }
10029
10030 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10031 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10032 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10033 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10034 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10035 rsp->out_of_order_arp_rsp_drop_cnt);
10036 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10037 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10038 hdd_notice("rsp->ba_session_establishment_status :%x",
10039 rsp->ba_session_establishment_status);
10040
10041 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10042 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10043 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10044 adapter->dad |= rsp->dad_detected;
10045 adapter->con_status = rsp->connect_status;
10046
10047 spin_lock(&hdd_context_lock);
10048 context = &hdd_ctx->nud_stats_context;
10049 complete(&context->response_event);
10050 spin_unlock(&hdd_context_lock);
10051
10052 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010053}
10054
10055/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010056 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010057 * @hdd_ctx: HDD context
10058 *
10059 * Register the HDD callbacks to CDS/SME.
10060 *
10061 * Return: 0 for success or Error code for failure
10062 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010063int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010064{
10065 QDF_STATUS status;
10066 int ret = 0;
10067
10068 ENTER();
10069
10070 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10071
10072 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10073 hdd_send_oem_data_rsp_msg);
10074
10075 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10076 wlan_hdd_cfg80211_fw_mem_dump_cb);
10077 if (!QDF_IS_STATUS_SUCCESS(status)) {
10078 hdd_err("Failed to register memdump callback");
10079 ret = -EINVAL;
10080 return ret;
10081 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010082 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10083 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010084 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10085 sme_nan_register_callback(hdd_ctx->hHal,
10086 wlan_hdd_cfg80211_nan_callback);
10087 sme_stats_ext_register_callback(hdd_ctx->hHal,
10088 wlan_hdd_cfg80211_stats_ext_callback);
10089
10090 sme_ext_scan_register_callback(hdd_ctx->hHal,
10091 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010092 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10093 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010094
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010095 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10096 hdd_rssi_threshold_breached);
10097
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010098 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10099
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010100 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10101 wlan_hdd_cfg80211_link_layer_stats_callback);
10102
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010103 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10104
Zhang Qianca38fb12016-12-23 11:10:48 +080010105 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10106 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10107
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010108 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10109 hdd_lost_link_info_cb);
10110 /* print error and not block the startup process */
10111 if (!QDF_IS_STATUS_SUCCESS(status))
10112 hdd_err("set lost link info callback failed");
10113
Poddar, Siddarth34872782017-08-10 14:08:51 +053010114 ret = hdd_register_data_stall_detect_cb();
10115 if (ret) {
10116 hdd_err("Register data stall detect detect callback failed.");
10117 return ret;
10118 }
10119
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010120 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10121
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010122 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010123 hdd_set_connection_in_progress,
10124 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010125
10126 status = sme_congestion_register_callback(hdd_ctx->hHal,
10127 hdd_update_cca_info_cb);
10128 if (!QDF_IS_STATUS_SUCCESS(status))
10129 hdd_err("set congestion callback failed");
10130
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010131 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10132 hdd_bt_activity_cb);
10133 if (!QDF_IS_STATUS_SUCCESS(status))
10134 hdd_err("set bt activity info callback failed");
10135
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010136 EXIT();
10137
10138 return ret;
10139}
10140
10141/**
10142 * hdd_deregister_cb() - De-Register HDD callbacks.
10143 * @hdd_ctx: HDD context
10144 *
10145 * De-Register the HDD callbacks to CDS/SME.
10146 *
10147 * Return: void
10148 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010149void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010150{
10151 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010152 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010153
10154 ENTER();
10155
10156 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10157 if (!QDF_IS_STATUS_SUCCESS(status))
10158 hdd_err("De-register of dcc stats callback failed: %d",
10159 status);
10160
10161 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010162 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10163
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010164 sme_stats_ext_register_callback(hdd_ctx->hHal,
10165 wlan_hdd_cfg80211_stats_ext_callback);
10166
10167 sme_nan_deregister_callback(hdd_ctx->hHal);
10168 status = sme_reset_tsfcb(hdd_ctx->hHal);
10169 if (!QDF_IS_STATUS_SUCCESS(status))
10170 hdd_err("Failed to de-register tsfcb the callback:%d",
10171 status);
10172 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10173 if (!QDF_IS_STATUS_SUCCESS(status))
10174 hdd_err("Failed to de-register the fw mem dump callback: %d",
10175 status);
10176
Poddar, Siddarth34872782017-08-10 14:08:51 +053010177 ret = hdd_deregister_data_stall_detect_cb();
10178 if (ret)
10179 hdd_err("Failed to de-register data stall detect event callback");
10180
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010181 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10182 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10183
10184 EXIT();
10185}
10186
10187/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010188 * hdd_softap_sta_deauth() - handle deauth req from HDD
10189 * @adapter: Pointer to the HDD
10190 * @enable: bool value
10191 *
10192 * This to take counter measure to handle deauth req from HDD
10193 *
10194 * Return: None
10195 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010196QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010197 struct tagCsrDelStaParams *pDelStaParams)
10198{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010199 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010200
10201 ENTER();
10202
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010203 /* Ignore request to deauth bcmc station */
10204 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010205 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010206
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010207 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010208 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10209 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010210
10211 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010212 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010213}
10214
10215/**
10216 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10217 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010218 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010219 *
10220 * This to take counter measure to handle deauth req from HDD
10221 *
10222 * Return: None
10223 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010224void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010225 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010226{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010227 ENTER();
10228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010229 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010230 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010231 return;
10232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010233 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010234 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010235}
10236
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010237/**
10238 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10239 * @hdd_ctx: HDD Context
10240 *
10241 * API to find if there is any STA or P2P-Client is connected
10242 *
10243 * Return: true if connected; false otherwise
10244 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010245QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010246{
10247 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10248}
10249
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010250/**
10251 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10252 * @adapter: HDD adapter pointer
10253 *
10254 * This function loop through each adapter and disable roaming on each STA
10255 * device mode except the input adapter.
10256 *
10257 * Note: On the input adapter roaming is not enabled yet hence no need to
10258 * disable.
10259 *
10260 * Return: None
10261 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010262void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010263{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010264 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010265 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010266 hdd_adapter_list_node_t *adapterNode = NULL;
10267 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010268 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010269
10270 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010271 hdd_ctx->config->isRoamOffloadScanEnabled &&
10272 QDF_STA_MODE == adapter->device_mode &&
10273 policy_mgr_is_sta_active_connection_exists(
10274 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010275 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010276 adapter->sessionId);
10277 /*
10278 * Loop through adapter and disable roaming for each STA device
10279 * mode except the input adapter.
10280 */
10281 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10282
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010283 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010284 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010285
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010286 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010287 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010288 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010289 adapterIdx->sessionId);
10290 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10291 (adapterIdx),
10292 adapterIdx->sessionId, 0);
10293 }
10294
10295 status = hdd_get_next_adapter(hdd_ctx,
10296 adapterNode,
10297 &pNext);
10298 adapterNode = pNext;
10299 }
10300 }
10301}
10302
10303/**
10304 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10305 * @adapter: HDD adapter pointer
10306 *
10307 * This function loop through each adapter and enable roaming on each STA
10308 * device mode except the input adapter.
10309 * Note: On the input adapter no need to enable roaming because link got
10310 * disconnected on this.
10311 *
10312 * Return: None
10313 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010314void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010315{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010316 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010317 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010318 hdd_adapter_list_node_t *adapterNode = NULL;
10319 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010320 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010321
10322 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010323 hdd_ctx->config->isRoamOffloadScanEnabled &&
10324 QDF_STA_MODE == adapter->device_mode &&
10325 policy_mgr_is_sta_active_connection_exists(
10326 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010327 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010328 adapter->sessionId);
10329 /*
10330 * Loop through adapter and enable roaming for each STA device
10331 * mode except the input adapter.
10332 */
10333 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10334
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010335 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010336 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010337
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010338 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010339 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010340 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010341 adapterIdx->sessionId);
10342 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10343 (adapterIdx),
10344 adapterIdx->sessionId,
10345 REASON_CONNECT);
10346 }
10347
10348 status = hdd_get_next_adapter(hdd_ctx,
10349 adapterNode,
10350 &pNext);
10351 adapterNode = pNext;
10352 }
10353 }
10354}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010355
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010356/**
10357 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10358 * @skb: sk buffer pointer
10359 *
10360 * Sends the bcast message to SVC multicast group with generic nl socket
10361 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10362 *
10363 * Return: None
10364 */
10365static void nl_srv_bcast_svc(struct sk_buff *skb)
10366{
10367#ifdef CNSS_GENL
10368 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10369#else
10370 nl_srv_bcast(skb);
10371#endif
10372}
10373
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010374void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010375{
10376 struct sk_buff *skb;
10377 struct nlmsghdr *nlh;
10378 tAniMsgHdr *ani_hdr;
10379 void *nl_data = NULL;
10380 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010381 struct radio_index_tlv *radio_info;
10382 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010383
10384 if (in_interrupt() || irqs_disabled() || in_atomic())
10385 flags = GFP_ATOMIC;
10386
10387 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10388
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010389 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010390 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010391
10392 nlh = (struct nlmsghdr *)skb->data;
10393 nlh->nlmsg_pid = 0; /* from kernel */
10394 nlh->nlmsg_flags = 0;
10395 nlh->nlmsg_seq = 0;
10396 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10397
10398 ani_hdr = NLMSG_DATA(nlh);
10399 ani_hdr->type = type;
10400
10401 switch (type) {
10402 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010403 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010404 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010405 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010406 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010407 ani_hdr->length = 0;
10408 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010409 break;
10410 case WLAN_SVC_WLAN_STATUS_IND:
10411 case WLAN_SVC_WLAN_VERSION_IND:
10412 case WLAN_SVC_DFS_CAC_START_IND:
10413 case WLAN_SVC_DFS_CAC_END_IND:
10414 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10415 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10416 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010417 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010418 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010419 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010420 ani_hdr->length = len;
10421 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10422 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10423 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010424 break;
10425
10426 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010427 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010428 type);
10429 kfree_skb(skb);
10430 return;
10431 }
10432
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010433 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010434 * Add radio index at the end of the svc event in TLV format
10435 * to maintain the backward compatibility with userspace
10436 * applications.
10437 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010438
10439 tlv_len = 0;
10440
10441 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10442 < WLAN_NL_MAX_PAYLOAD) {
10443 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10444 sizeof(*ani_hdr) + len);
10445 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10446 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10447 radio_info->radio = radio;
10448 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010449 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010450 "Added radio index tlv - radio index %d",
10451 radio_info->radio);
10452 }
10453
10454 nlh->nlmsg_len += tlv_len;
10455 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10456
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010457 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010458}
10459
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010460#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10461void wlan_hdd_auto_shutdown_cb(void)
10462{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010463 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010464
10465 if (!hdd_ctx)
10466 return;
10467
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010468 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010469 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10470 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010471}
10472
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010473void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010474{
10475 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010476 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010477 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010478 bool ap_connected = false, sta_connected = false;
10479 tHalHandle hal_handle;
10480
10481 hal_handle = hdd_ctx->hHal;
10482 if (hal_handle == NULL)
10483 return;
10484
10485 if (hdd_ctx->config->WlanAutoShutdown == 0)
10486 return;
10487
10488 if (enable == false) {
10489 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010490 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010491 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010492 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010493 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010494 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010495 return;
10496 }
10497
10498 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010499 if (policy_mgr_concurrent_open_sessions_running(
10500 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010501 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10502
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010503 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010504 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010505 if (adapter
10506 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010507 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010508 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10509 conn_info.connState ==
10510 eConnectionState_Associated) {
10511 sta_connected = true;
10512 break;
10513 }
10514 }
10515 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010516 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010517 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070010518 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010519 ap_connected = true;
10520 break;
10521 }
10522 }
10523 status = hdd_get_next_adapter(hdd_ctx,
10524 adapterNode,
10525 &pNext);
10526 adapterNode = pNext;
10527 }
10528 }
10529
10530 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010531 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010532 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010533 }
Jeff Johnson68755312017-02-10 11:46:55 -080010534
10535 if (sme_set_auto_shutdown_timer(hal_handle,
10536 hdd_ctx->config->WlanAutoShutdown)
10537 != QDF_STATUS_SUCCESS)
10538 hdd_err("Failed to start wlan auto shutdown timer");
10539 else
10540 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10541 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010542}
10543#endif
10544
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010545struct hdd_adapter *
10546hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10547 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010548{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010549 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010550 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010551 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010552 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10553
10554 con_sap_adapter = NULL;
10555
10556 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010557 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010558 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010559 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10560 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010561 adapter != this_sap_adapter) {
10562 if (check_start_bss) {
10563 if (test_bit(SOFTAP_BSS_STARTED,
10564 &adapter->event_flags)) {
10565 con_sap_adapter = adapter;
10566 break;
10567 }
10568 } else {
10569 con_sap_adapter = adapter;
10570 break;
10571 }
10572 }
10573 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10574 adapterNode = pNext;
10575 }
10576
10577 return con_sap_adapter;
10578}
10579
10580#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010581static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010582{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010583 return adapter->device_mode == QDF_STA_MODE ||
10584 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010585}
10586
Jeff Johnson9d295242017-08-29 14:39:48 -070010587static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010588{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010589 return adapter->device_mode == QDF_SAP_MODE ||
10590 adapter->device_mode == QDF_P2P_GO_MODE;
10591}
10592
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010593static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010594{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010595 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010596 hdd_adapter_list_node_t *node;
10597
10598 status = hdd_get_front_adapter(hdd_ctx, &node);
10599 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010600 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010601
10602 if (adapter &&
10603 hdd_adapter_is_sta(adapter) &&
10604 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10605 conn_info.connState == eConnectionState_Associated) {
10606 return true;
10607 }
10608
10609 if (adapter &&
10610 hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070010611 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070010612 return true;
10613 }
10614
10615 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10616 }
10617
10618 return false;
10619}
10620
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010621static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010622{
10623 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010624
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010625 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010626 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010627 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010628
Dustin Brown5ec6b552017-03-31 12:11:40 -070010629 return is_running;
10630}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010631
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010632static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010633{
10634 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10635 hdd_ctx->bus_bw_timer_running = true;
10636 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10637 hdd_ctx->config->busBandwidthComputeInterval);
10638 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10639}
10640
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010641void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010642{
10643 ENTER();
10644
10645 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10646 hdd_debug("Bandwidth compute timer already started");
10647 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010648 }
10649
Dustin Brown5ec6b552017-03-31 12:11:40 -070010650 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10651
10652 EXIT();
10653}
10654
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010655void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010656{
10657 ENTER();
10658
10659 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10660 hdd_debug("Bandwidth compute timer already started");
10661 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010662 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010663
10664 if (hdd_any_adapter_is_assoc(hdd_ctx))
10665 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10666
10667 EXIT();
10668}
10669
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010670static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010671{
10672 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10673
10674 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10675 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10676 hdd_ctx->bus_bw_timer_running = false;
10677 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10678
10679 hdd_reset_tcp_delack(hdd_ctx);
10680}
10681
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010682void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010683{
10684 ENTER();
10685
10686 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10687 hdd_debug("Bandwidth compute timer already stopped");
10688 return;
10689 }
10690
10691 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10692
10693 EXIT();
10694}
10695
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010696void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010697{
10698 ENTER();
10699
10700 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10701 hdd_debug("Bandwidth compute timer already stopped");
10702 return;
10703 }
10704
10705 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10706 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10707
10708 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010709}
10710#endif
10711
10712/**
10713 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10714 * and sta's operating channel.
10715 * @sta_adapter: Describe the first argument to foobar.
10716 * @ap_adapter: Describe the second argument to foobar.
10717 * @roam_profile: Roam profile of AP to which STA wants to connect.
10718 * @concurrent_chnl_same: If both SAP and STA channels are same then
10719 * set this flag to true else false.
10720 *
10721 * This function checks the sap's operating channel and sta's operating channel.
10722 * if both are same then it will return false else it will restart the sap in
10723 * sta's channel and return true.
10724 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010725 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010726 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010727QDF_STATUS
10728wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10729 struct hdd_adapter *ap_adapter,
10730 tCsrRoamProfile *roam_profile,
10731 tScanResultHandle *scan_cache,
10732 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010733{
Jeff Johnson87251032017-08-29 13:31:11 -070010734 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010735 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010736 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010737 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010738 *concurrent_chnl_same = true;
10739
10740 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10741 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010742 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010743 scan_cache,
10744 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010745 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010746 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010747 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070010748 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010749 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010750 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010751 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010752 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010753 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070010754 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010755 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010756 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010757 }
10758 }
10759 } else {
10760 /*
10761 * Lets handle worst case scenario here, Scan cache lookup is
10762 * failed so we have to stop the SAP to avoid any channel
10763 * discrepancy between SAP's channel and STA's channel.
10764 * Return the status as failure so caller function could know
10765 * that scan look up is failed.
10766 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010767 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010768 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010769 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010770 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010771}
10772
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010773/**
10774 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10775 * @ap_adapter: SAP adapter
10776 *
10777 * This function will process the stopping of sap adapter.
10778 *
10779 * Return: None
10780 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010781void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010782{
Jeff Johnson87251032017-08-29 13:31:11 -070010783 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010784 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010785 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010786 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010787
10788 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010789 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010790 return;
10791 }
10792
10793 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10794 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010795 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010796 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010797
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010798 mutex_lock(&hdd_ctx->sap_lock);
10799 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010800 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010801 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010802 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010803 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010804 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070010805 sap_context)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010806 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010807 qdf_stop_bss_event,
10808 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010809 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010810 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010811 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010812 return;
10813 }
10814 }
10815 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010816 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10817 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010818 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010819 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010820 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010821 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010822 }
10823 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010824}
10825
10826/**
10827 * wlan_hdd_start_sap() - this function starts bss of SAP.
10828 * @ap_adapter: SAP adapter
10829 *
10830 * This function will process the starting of sap adapter.
10831 *
10832 * Return: None
10833 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010834void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010835{
Jeff Johnson87251032017-08-29 13:31:11 -070010836 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010837 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010838 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010839 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010840 tsap_Config_t *sap_config;
10841
10842 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010843 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010844 return;
10845 }
10846
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010847 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010848 hdd_err("SoftAp role has not been enabled");
10849 return;
10850 }
10851
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010852 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10853 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10854 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070010855 sap_config = &ap_adapter->sessionCtx.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010856
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010857 mutex_lock(&hdd_ctx->sap_lock);
10858 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10859 goto end;
10860
10861 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010862 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010863 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10864 goto end;
10865 }
10866
Wei Song2f76f642016-11-18 16:32:53 +080010867 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070010868 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070010869 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010870 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010871 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010872 goto end;
10873
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010874 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010875 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010876 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010877 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010878 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010879 goto end;
10880 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010881 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010882 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070010883 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010884 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10885 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010886 ap_adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010887end:
10888 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010889 /* SAP context and beacon cleanup will happen during driver unload
10890 * in hdd_stop_adapter
10891 */
10892 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10893
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010894}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010895
10896/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010897 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10898 * mac scan config
10899 * @status: Status of set antenna mode
10900 *
10901 * Callback on setting the dual mac configuration
10902 *
10903 * Return: None
10904 */
10905void wlan_hdd_soc_set_antenna_mode_cb(
10906 enum set_antenna_mode_status status)
10907{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010908 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010909
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010910 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010911
10912 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10913 if (0 != wlan_hdd_validate_context(hdd_ctx))
10914 return;
10915
10916 /* Signal the completion of set dual mac config */
10917 complete(&hdd_ctx->set_antenna_mode_cmpl);
10918}
10919
10920/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010921 * hdd_get_fw_version() - Get FW version
10922 * @hdd_ctx: pointer to HDD context.
10923 * @major_spid: FW version - major spid.
10924 * @minor_spid: FW version - minor spid
10925 * @ssid: FW version - ssid
10926 * @crmid: FW version - crmid
10927 *
10928 * This function is called to get the firmware build version stored
10929 * as part of the HDD context
10930 *
10931 * Return: None
10932 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010933void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010934 uint32_t *major_spid, uint32_t *minor_spid,
10935 uint32_t *siid, uint32_t *crmid)
10936{
10937 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10938 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10939 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10940 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10941}
10942
10943#ifdef QCA_CONFIG_SMP
10944/**
10945 * wlan_hdd_get_cpu() - get cpu_index
10946 *
10947 * Return: cpu_index
10948 */
10949int wlan_hdd_get_cpu(void)
10950{
10951 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010952
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010953 put_cpu();
10954 return cpu_index;
10955}
10956#endif
10957
10958/**
10959 * hdd_get_fwpath() - get framework path
10960 *
10961 * This function is used to get the string written by
10962 * userspace to start the wlan driver
10963 *
10964 * Return: string
10965 */
10966const char *hdd_get_fwpath(void)
10967{
10968 return fwpath.string;
10969}
10970
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010971static int hdd_qdf_print_init(void)
10972{
10973 int qdf_print_idx;
10974 QDF_STATUS status;
10975
10976 status = qdf_print_setup();
10977 if (status != QDF_STATUS_SUCCESS) {
10978 pr_err("qdf_print_setup failed\n");
10979 return -EINVAL;
10980 }
10981
10982 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10983
10984 if (qdf_print_idx < 0) {
10985 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10986 qdf_print_idx);
10987 return -EINVAL;
10988 }
10989
10990 qdf_set_pidx(qdf_print_idx);
10991
10992 return 0;
10993}
10994
10995static void hdd_qdf_print_deinit(void)
10996{
10997 int qdf_print_idx;
10998
10999 qdf_print_idx = qdf_get_pidx();
11000 qdf_print_ctrl_cleanup(qdf_print_idx);
11001}
11002
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011003/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011004 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011005 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011006 * This function initilizes CDS global context with the help of cds_init. This
11007 * has to be the first function called after probe to get a valid global
11008 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011009 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011010 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011011 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011012int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011013{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011014 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011015 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011016
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011017 status = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011018
11019 wlan_init_bug_report_lock();
11020
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011021#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11022 wlan_logging_sock_init_svc();
11023#endif
11024
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011025 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011026 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011027 ret = -ENOMEM;
11028 goto err_out;
11029 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011030
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011031 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11032 (void *)hdd_drv_ops_inactivity_handler, NULL,
11033 QDF_TIMER_TYPE_SW);
11034
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011035 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011036 hdd_qdf_print_init();
11037
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011038 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011039
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011040err_out:
11041 return ret;
11042}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011043
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011044/**
11045 * hdd_deinit() - Deinitialize Driver
11046 *
11047 * This function frees CDS global context with the help of cds_deinit. This
11048 * has to be the last function call in remove callback to free the global
11049 * context.
11050 */
11051void hdd_deinit(void)
11052{
Dustin Brownedce4a52017-05-10 11:59:15 -070011053 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011054 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011055
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011056 wlan_destroy_bug_report_lock();
11057 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011058
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011059 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011060#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11061 wlan_logging_sock_deinit_svc();
11062#endif
11063}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011064
Yue Ma6e7b1a02017-04-03 14:17:46 -070011065#ifdef QCA_WIFI_NAPIER_EMULATION
11066#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11067#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011068#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011069#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011070
Sachin Ahujadddd2632017-03-07 19:07:24 +053011071static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11072 struct file *file)
11073{
11074 return 0;
11075}
11076
11077static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11078 const char __user *user_buf,
11079 size_t count,
11080 loff_t *f_pos)
11081{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011082 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011083 static const char wlan_off_str[] = "OFF";
11084 static const char wlan_on_str[] = "ON";
11085 int ret;
11086 unsigned long rc;
11087
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011088 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011089 pr_err("Failed to read buffer\n");
11090 return -EINVAL;
11091 }
11092
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011093 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011094 pr_debug("Wifi turning off from UI\n");
11095 goto exit;
11096 }
11097
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011098 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011099 pr_err("Invalid value received from framework");
11100 goto exit;
11101 }
11102
11103 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011104 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011105 rc = wait_for_completion_timeout(&wlan_start_comp,
11106 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11107 if (!rc) {
11108 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11109 ret = -EINVAL;
11110 hdd_start_complete(ret);
11111 return ret;
11112 }
11113
11114 hdd_start_complete(0);
11115 }
11116
11117exit:
11118 return count;
11119}
11120
11121
11122const struct file_operations wlan_hdd_state_fops = {
11123 .owner = THIS_MODULE,
11124 .open = wlan_hdd_state_ctrl_param_open,
11125 .write = wlan_hdd_state_ctrl_param_write,
11126};
11127
11128static int wlan_hdd_state_ctrl_param_create(void)
11129{
11130 unsigned int wlan_hdd_state_major = 0;
11131 int ret;
11132 struct device *dev;
11133
11134 device = MKDEV(wlan_hdd_state_major, 0);
11135
11136 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11137 if (ret) {
11138 pr_err("Failed to register qcwlanstate");
11139 goto dev_alloc_err;
11140 }
11141 wlan_hdd_state_major = MAJOR(device);
11142
11143 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11144 if (IS_ERR(class)) {
11145 pr_err("wlan_hdd_state class_create error");
11146 goto class_err;
11147 }
11148
11149 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11150 if (IS_ERR(dev)) {
11151 pr_err("wlan_hdd_statedevice_create error");
11152 goto err_class_destroy;
11153 }
11154
11155 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11156 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11157 if (ret) {
11158 pr_err("Failed to add cdev error");
11159 goto cdev_add_err;
11160 }
11161
11162 pr_info("wlan_hdd_state %s major(%d) initialized",
11163 WLAN_MODULE_NAME, wlan_hdd_state_major);
11164
11165 return 0;
11166
11167cdev_add_err:
11168 device_destroy(class, device);
11169err_class_destroy:
11170 class_destroy(class);
11171class_err:
11172 unregister_chrdev_region(device, dev_num);
11173dev_alloc_err:
11174 return -ENODEV;
11175}
11176
11177static void wlan_hdd_state_ctrl_param_destroy(void)
11178{
11179 cdev_del(&wlan_hdd_state_cdev);
11180 device_destroy(class, device);
11181 class_destroy(class);
11182 unregister_chrdev_region(device, dev_num);
11183
11184 pr_info("Device node unregistered");
11185}
11186
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011187/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011188 * component_init - API to init cld component's
11189 *
11190 * Return: None
11191 */
11192static void component_init(void)
11193{
11194 pmo_init();
11195}
11196
11197/**
11198 * component_deinit - API to deinit cld component's
11199 *
11200 * Return: None
11201 */
11202static void component_deinit(void)
11203{
11204 pmo_deinit();
11205}
11206
11207/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011208 * __hdd_module_init - Module init helper
11209 *
11210 * Module init helper function used by both module and static driver.
11211 *
11212 * Return: 0 for success, errno on failure
11213 */
11214static int __hdd_module_init(void)
11215{
11216 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011217
Dustin Brownab482ac2017-06-09 17:00:44 -070011218 pr_err("%s: Loading driver v%s (%s)%s\n",
11219 WLAN_MODULE_NAME,
11220 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011221 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011222 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011223
Sachin Ahujadddd2632017-03-07 19:07:24 +053011224 ret = wlan_hdd_state_ctrl_param_create();
11225 if (ret) {
11226 pr_err("wlan_hdd_state_create:%x\n", ret);
11227 goto err_dev_state;
11228 }
11229
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011230 pld_init();
11231
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011232 ret = hdd_init();
11233 if (ret) {
11234 pr_err("hdd_init failed %x\n", ret);
11235 goto err_hdd_init;
11236 }
11237
Rajeev Kumar97767a02016-11-30 11:20:40 -080011238 dispatcher_init();
11239
Mukul Sharmad75a6672017-06-22 15:40:53 +053011240 /* Ensure to call post objmgr init */
11241 component_init();
11242
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011243 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011244
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011245 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011246
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011247 ret = wlan_hdd_register_driver();
11248 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011249 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11250 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011251 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011252 }
11253
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011254 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011255
11256 return 0;
11257out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011258 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011259 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011260 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011261 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011262
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011263err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011264 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011265 wlan_hdd_state_ctrl_param_destroy();
11266err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011267 return ret;
11268}
11269
11270/**
11271 * __hdd_module_exit - Module exit helper
11272 *
11273 * Module exit helper function used by both module and static driver.
11274 */
11275static void __hdd_module_exit(void)
11276{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011277
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011278 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11279 QWLAN_VERSIONSTR);
11280
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011281 hdd_wait_for_recovery_completion();
11282
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011283 wlan_hdd_unregister_driver();
11284
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011285 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011286
Mukul Sharmad75a6672017-06-22 15:40:53 +053011287 /* Ensure to call prior to objmgr deinit */
11288 component_deinit();
11289
Rajeev Kumar97767a02016-11-30 11:20:40 -080011290 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011291 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011292 pld_deinit();
11293
Sachin Ahujadddd2632017-03-07 19:07:24 +053011294 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011295}
11296
Arun Khandavallifae92942016-08-01 13:31:08 +053011297#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011298/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011299 * wlan_boot_cb() - Wlan boot callback
11300 * @kobj: object whose directory we're creating the link in.
11301 * @attr: attribute the user is interacting with
11302 * @buff: the buffer containing the user data
11303 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011304 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011305 * This callback is invoked when the fs is ready to start the
11306 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011307 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011308 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011309 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011310static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011311 struct kobj_attribute *attr,
11312 const char *buf,
11313 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011314{
Arun Khandavallifae92942016-08-01 13:31:08 +053011315
Arun Khandavallifae92942016-08-01 13:31:08 +053011316 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011317 pr_err("%s: wlan driver already initialized\n", __func__);
11318 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011319 }
11320
Arun Khandavallifae92942016-08-01 13:31:08 +053011321 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011322 pr_err("%s: wlan driver initialization failed\n", __func__);
11323 return -EIO;
11324 }
11325
11326 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011327
11328 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011329}
Arun Khandavallifae92942016-08-01 13:31:08 +053011330
11331/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011332 * hdd_sysfs_cleanup() - cleanup sysfs
11333 *
11334 * Return: None
11335 *
11336 */
11337static void hdd_sysfs_cleanup(void)
11338{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011339 /* remove from group */
11340 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11341 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11342 wlan_loader->attr_group);
11343
11344 /* unlink the object from parent */
11345 kobject_del(wlan_loader->boot_wlan_obj);
11346
11347 /* free the object */
11348 kobject_put(wlan_loader->boot_wlan_obj);
11349
11350 kfree(wlan_loader->attr_group);
11351 kfree(wlan_loader);
11352
11353 wlan_loader = NULL;
11354}
11355
11356/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011357 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11358 * ready
11359 *
11360 * This is creates the syfs entry boot_wlan. Which shall be invoked
11361 * when the filesystem is ready.
11362 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011363 * QDF API cannot be used here since this function is called even before
11364 * initializing WLAN driver.
11365 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011366 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011367 */
11368static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011369{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011370 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011371
11372 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011373 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011374 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011375
11376 wlan_loader->boot_wlan_obj = NULL;
11377 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11378 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011379 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011380 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011381
11382 wlan_loader->loaded_state = 0;
11383 wlan_loader->attr_group->attrs = attrs;
11384
11385 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11386 kernel_kobj);
11387 if (!wlan_loader->boot_wlan_obj) {
11388 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011389 goto error_return;
11390 }
11391
11392 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11393 wlan_loader->attr_group);
11394 if (ret) {
11395 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11396 goto error_return;
11397 }
11398
11399 return 0;
11400
11401error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011402 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011403
11404 return ret;
11405}
11406
11407/**
11408 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11409 *
11410 * Return: 0 on success or errno on failure
11411 */
11412static int wlan_deinit_sysfs(void)
11413{
Arun Khandavallifae92942016-08-01 13:31:08 +053011414 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011415 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011416 return -EINVAL;
11417 }
11418
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011419 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011420 return 0;
11421}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011422
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011423#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011424
11425#ifdef MODULE
11426/**
11427 * __hdd_module_init - Module init helper
11428 *
11429 * Module init helper function used by both module and static driver.
11430 *
11431 * Return: 0 for success, errno on failure
11432 */
11433static int hdd_module_init(void)
11434{
Arun Khandavallifae92942016-08-01 13:31:08 +053011435 if (__hdd_module_init()) {
11436 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011437 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011438 }
11439
Dustin Brownab482ac2017-06-09 17:00:44 -070011440 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011441}
11442#else
11443static int __init hdd_module_init(void)
11444{
11445 int ret = -EINVAL;
11446
11447 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011448 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011449 pr_err("Failed to create sysfs entry for loading wlan");
11450
11451 return ret;
11452}
11453#endif
11454
11455
11456#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011457/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011458 * hdd_module_exit() - Exit function
11459 *
11460 * This is the driver exit point (invoked when module is unloaded using rmmod)
11461 *
11462 * Return: None
11463 */
11464static void __exit hdd_module_exit(void)
11465{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011466 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011467}
Arun Khandavallifae92942016-08-01 13:31:08 +053011468#else
11469static void __exit hdd_module_exit(void)
11470{
11471 __hdd_module_exit();
11472 wlan_deinit_sysfs();
11473}
11474#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011475
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011476static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11477{
11478 return param_set_copystring(kmessage, kp);
11479}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011480
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011481/**
11482 * is_con_mode_valid() check con mode is valid or not
11483 * @mode: global con mode
11484 *
11485 * Return: TRUE on success FALSE on failure
11486 */
11487static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11488{
11489 switch (mode) {
11490 case QDF_GLOBAL_MONITOR_MODE:
11491 case QDF_GLOBAL_FTM_MODE:
11492 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011493 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011494 return true;
11495 default:
11496 return false;
11497 }
11498}
11499
11500/**
11501 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11502 * @mode: global con mode
11503 *
11504 * Return: adapter mode
11505 */
11506static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11507 enum tQDF_GLOBAL_CON_MODE mode)
11508{
11509
11510 switch (mode) {
11511 case QDF_GLOBAL_MISSION_MODE:
11512 return QDF_STA_MODE;
11513 case QDF_GLOBAL_MONITOR_MODE:
11514 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011515 case QDF_GLOBAL_EPPING_MODE:
11516 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011517 case QDF_GLOBAL_FTM_MODE:
11518 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011519 case QDF_GLOBAL_QVIT_MODE:
11520 return QDF_QVIT_MODE;
11521 default:
11522 return QDF_MAX_NO_OF_MODE;
11523 }
11524}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011525
Dustin Brown27cd9942017-09-27 16:11:44 -070011526static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11527 enum tQDF_GLOBAL_CON_MODE curr_mode)
11528{
11529 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11530 return;
11531
11532 switch (curr_mode) {
11533 case QDF_GLOBAL_MISSION_MODE:
11534 case QDF_GLOBAL_MONITOR_MODE:
11535 case QDF_GLOBAL_FTM_MODE:
11536 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11537 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11538
11539 /* re-use the existing session */
11540 hdd_stop_all_adapters(hdd_ctx, false);
11541 break;
11542 default:
11543 break;
11544 }
11545}
11546
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011547static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011548 enum tQDF_GLOBAL_CON_MODE curr_mode)
11549{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011550 int driver_status;
11551
11552 driver_status = hdd_ctx->driver_status;
11553
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011554 switch (curr_mode) {
11555 case QDF_GLOBAL_MISSION_MODE:
11556 case QDF_GLOBAL_MONITOR_MODE:
11557 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011558 hdd_deinit_all_adapters(hdd_ctx, false);
11559 hdd_close_all_adapters(hdd_ctx, false);
11560 break;
11561 case QDF_GLOBAL_EPPING_MODE:
11562 epping_disable();
11563 epping_close();
11564 break;
11565 default:
11566 return;
11567 }
11568}
11569
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011570static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011571 enum tQDF_GLOBAL_CON_MODE mode)
11572{
Jeff Johnson9d295242017-08-29 14:39:48 -070011573 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011574 int ret = 0;
11575 bool rtnl_held;
11576 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11577 QDF_STATUS status;
11578
11579 if (!qdf_dev) {
11580 hdd_err("qdf device context is Null return!");
11581 return -EINVAL;
11582 }
11583
11584 rtnl_held = hdd_hold_rtnl_lock();
11585 switch (mode) {
11586 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011587 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11588 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011589 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011590 break;
11591 case QDF_GLOBAL_FTM_MODE:
11592 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11593 wlan_hdd_get_intf_addr(hdd_ctx),
11594 NET_NAME_UNKNOWN, rtnl_held);
11595 if (adapter == NULL)
11596 ret = -EINVAL;
11597 break;
11598 case QDF_GLOBAL_MONITOR_MODE:
11599 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11600 wlan_hdd_get_intf_addr(hdd_ctx),
11601 NET_NAME_UNKNOWN, rtnl_held);
11602 if (adapter == NULL)
11603 ret = -EINVAL;
11604 break;
11605 case QDF_GLOBAL_EPPING_MODE:
11606 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011607 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011608 hdd_err("Failed to open in eeping mode: %d", status);
11609 ret = -EINVAL;
11610 break;
11611 }
11612 ret = epping_enable(qdf_dev->dev);
11613 if (ret) {
11614 hdd_err("Failed to enable in epping mode : %d", ret);
11615 epping_close();
11616 }
11617 break;
11618 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011619 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011620 ret = -ENOTSUPP;
11621 break;
11622 }
11623 hdd_release_rtnl_lock();
11624 rtnl_held = false;
11625 return ret;
11626}
11627
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011628/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011629 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011630 * @kmessage: con mode name on which driver to be bring up
11631 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011632 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011633 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011634 * This function is invoked when user updates con mode using sys entry,
11635 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011636 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011637 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011638 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011639static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011640 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011641{
11642 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011643 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011644 enum tQDF_GLOBAL_CON_MODE curr_mode;
11645 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011646
Dustin Brownab6029b2017-05-24 13:04:19 -070011647 hdd_info("con_mode handler: %s", kmessage);
11648
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011649 ret = wlan_hdd_validate_context(hdd_ctx);
11650 if (ret)
11651 return ret;
11652
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011653 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011654
11655 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011656
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011657 if (!(is_con_mode_valid(con_mode))) {
11658 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011659 ret = -EINVAL;
11660 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011661 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011662
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011663 curr_mode = hdd_get_conparam();
11664 if (curr_mode == con_mode) {
11665 hdd_err("curr mode: %d is same as user triggered mode %d",
11666 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011667 ret = 0;
11668 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011669 }
11670
Dustin Brown27cd9942017-09-27 16:11:44 -070011671 /* ensure adapters are stopped */
11672 hdd_stop_present_mode(hdd_ctx, curr_mode);
11673
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011674 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011675 if (ret) {
11676 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011677 goto reset_flags;
11678 }
11679
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011680 /* Cleanup present mode before switching to new mode */
11681 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11682
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011683 hdd_set_conparam(con_mode);
11684
11685 /* Register for new con_mode & then kick_start modules again */
11686 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11687 if (ret) {
11688 hdd_err("Failed to register for new mode");
11689 goto reset_flags;
11690 }
11691
11692 adapter_mode = hdd_get_adpter_mode(con_mode);
11693 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11694 hdd_err("invalid adapter");
11695 ret = -EINVAL;
11696 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011697 }
11698
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011699 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011700 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011701 hdd_err("Failed to get adapter:%d", adapter_mode);
11702 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011703 }
11704
11705 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11706 if (ret) {
11707 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011708 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011709 }
11710
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011711 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011712 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011713 if (hdd_start_adapter(adapter)) {
11714 hdd_err("Failed to start %s adapter", kmessage);
11715 ret = -EINVAL;
11716 goto reset_flags;
11717 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011718 }
11719
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011720 hdd_info("Mode successfully changed to %s", kmessage);
11721 ret = 0;
11722
11723reset_flags:
11724 cds_set_load_in_progress(false);
11725 return ret;
11726}
11727
11728
11729static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11730{
11731 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011732 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011733
11734 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11735 ret = wlan_hdd_validate_context(hdd_ctx);
11736 if (ret)
11737 return ret;
11738
11739 cds_ssr_protect(__func__);
11740 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11741 cds_ssr_unprotect(__func__);
11742
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011743 return ret;
11744}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011745
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011746static int con_mode_handler_ftm(const char *kmessage,
11747 struct kernel_param *kp)
11748{
11749 int ret;
11750
11751 ret = param_set_int(kmessage, kp);
11752
11753 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11754 pr_err("Only FTM mode supported!");
11755 return -ENOTSUPP;
11756 }
11757
11758 hdd_set_conparam(con_mode_ftm);
11759 con_mode = con_mode_ftm;
11760
11761 return ret;
11762}
11763
Ravi Joshia307f632017-07-17 23:41:41 -070011764static int con_mode_handler_monitor(const char *kmessage,
11765 struct kernel_param *kp)
11766{
11767 int ret;
11768
11769 ret = param_set_int(kmessage, kp);
11770
11771 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11772 pr_err("Only Monitor mode supported!");
11773 return -ENOTSUPP;
11774 }
11775
11776 hdd_set_conparam(con_mode_monitor);
11777 con_mode = con_mode_monitor;
11778
11779 return ret;
11780}
11781
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011782/**
11783 * hdd_get_conparam() - driver exit point
11784 *
11785 * This is the driver exit point (invoked when module is unloaded using rmmod)
11786 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011787 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011788 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011789enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011790{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011791 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011792}
11793
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011794void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011795{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011796 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011797}
11798
Komal Seelamc11bb222016-01-27 18:57:10 +053011799/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011800 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11801 * @hdd_ctx: HDD context
11802 *
11803 * Cleans up the pre cac interface, if it exists
11804 *
11805 * Return: None
11806 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011807void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011808{
11809 uint8_t session_id;
11810 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011811 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011812
11813 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11814 if (QDF_IS_STATUS_ERROR(status)) {
11815 hdd_err("failed to get pre cac vdev id");
11816 return;
11817 }
11818
11819 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11820 if (!precac_adapter) {
11821 hdd_err("invalid pre cac adapater");
11822 return;
11823 }
11824
11825 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11826 wlan_hdd_sap_pre_cac_failure,
11827 (void *)precac_adapter);
11828 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11829
11830}
11831
11832/**
Komal Seelamec702b02016-02-24 18:42:16 +053011833 * hdd_update_ol_config - API to update ol configuration parameters
11834 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011835 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011836 * Return: void
11837 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011838static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011839{
Komal Seelamec702b02016-02-24 18:42:16 +053011840 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011841 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011842
Komal Seelamec702b02016-02-24 18:42:16 +053011843 if (!ol_ctx)
11844 return;
11845
11846 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11847 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11848 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11849 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011850 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011851
11852 ol_init_ini_config(ol_ctx, &cfg);
11853}
11854
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011855#ifdef FEATURE_RUNTIME_PM
11856/**
11857 * hdd_populate_runtime_cfg() - populate runtime configuration
11858 * @hdd_ctx: hdd context
11859 * @cfg: pointer to the configuration memory being populated
11860 *
11861 * Return: void
11862 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011863static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011864 struct hif_config_info *cfg)
11865{
11866 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11867 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11868}
11869#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011870static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011871 struct hif_config_info *cfg)
11872{
11873}
11874#endif
11875
Komal Seelamec702b02016-02-24 18:42:16 +053011876/**
11877 * hdd_update_hif_config - API to update HIF configuration parameters
11878 * @hdd_ctx: HDD Context
11879 *
11880 * Return: void
11881 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011882static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011883{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011884 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011885 struct hif_config_info cfg;
11886
11887 if (!scn)
11888 return;
11889
11890 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011891 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011892 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011893
11894 if (hdd_ctx->config->prevent_link_down)
11895 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011896}
11897
11898/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011899 * hdd_update_dp_config() - Propagate config parameters to Lithium
11900 * datapath
11901 * @hdd_ctx: HDD Context
11902 *
11903 * Return: 0 for success/errno for failure
11904 */
11905static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
11906{
11907 struct cdp_config_params params;
11908 QDF_STATUS status;
11909
11910 params.tso_enable = hdd_ctx->config->tso_enable;
11911 params.lro_enable = hdd_ctx->config->lro_enable;
11912#ifdef QCA_LL_TX_FLOW_CONTROL_V2
11913 params.tx_flow_stop_queue_threshold =
11914 hdd_ctx->config->TxFlowStopQueueThreshold;
11915 params.tx_flow_start_queue_offset =
11916 hdd_ctx->config->TxFlowStartQueueOffset;
11917#endif
11918 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
11919 params.napi_enable = hdd_ctx->napi_enable;
11920 params.tcp_udp_checksumoffload =
11921 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
11922
11923 status = cdp_update_config_parameters(
11924 cds_get_context(QDF_MODULE_ID_SOC),
11925 &params);
11926 if (status) {
11927 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
11928 "%s: Failed to attach config parameters", __func__);
11929 return status;
11930 }
11931
11932 return 0;
11933}
11934
11935/**
Komal Seelamec702b02016-02-24 18:42:16 +053011936 * hdd_update_config() - Initialize driver per module ini parameters
11937 * @hdd_ctx: HDD Context
11938 *
11939 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011940 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011941 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011942int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011943{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011944 int ret;
11945
Komal Seelamec702b02016-02-24 18:42:16 +053011946 hdd_update_ol_config(hdd_ctx);
11947 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011948 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11949 ret = hdd_update_cds_config_ftm(hdd_ctx);
11950 else
11951 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011952 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011953
11954 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011955}
11956
Mukul Sharma9d797a02017-01-05 20:26:03 +053011957#ifdef FEATURE_WLAN_RA_FILTERING
11958/**
11959 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11960 * @psoc_cfg: pmo psoc Configuration
11961 * @hdd_ctx: Pointer to hdd context
11962 *
11963 * Return: none
11964 */
11965static inline void hdd_ra_populate_pmo_config(
11966 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011967 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011968{
11969 psoc_cfg->ra_ratelimit_interval =
11970 hdd_ctx->config->RArateLimitInterval;
11971 psoc_cfg->ra_ratelimit_enable =
11972 hdd_ctx->config->IsRArateLimitEnabled;
11973}
11974#else
11975static inline void hdd_ra_populate_pmo_config(
11976 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011977 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011978{
11979}
11980#endif
11981/**
11982 * hdd_update_pmo_config - API to update pmo configuration parameters
11983 * @hdd_ctx: HDD context
11984 *
11985 * Return: void
11986 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011987static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011988{
11989 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11990 struct pmo_psoc_cfg psoc_cfg;
11991 QDF_STATUS status;
11992
11993 /*
11994 * Value of hdd_ctx->wowEnable can be,
11995 * 0 - Disable both magic pattern match and pattern byte match.
11996 * 1 - Enable magic pattern match on all interfaces.
11997 * 2 - Enable pattern byte match on all interfaces.
11998 * 3 - Enable both magic patter and pattern byte match on
11999 * all interfaces.
12000 */
12001 psoc_cfg.magic_ptrn_enable =
12002 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12003 psoc_cfg.ptrn_match_enable_all_vdev =
12004 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012005 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12006 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012007 psoc_cfg.bpf_enable =
12008 hdd_ctx->config->bpf_packet_filter_enable;
12009 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012010 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012011 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12012 if (hdd_ctx->config->fhostNSOffload)
12013 psoc_cfg.ns_offload_enable_dynamic = true;
12014 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12015 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12016 psoc_cfg.active_mode_offload =
12017 hdd_ctx->config->active_mode_offload;
12018 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
12019 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012020 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12021 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12022 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12023 psoc_cfg.power_save_mode =
12024 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012025 psoc_cfg.auto_power_save_fail_mode =
12026 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012027
12028 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012029 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12030 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012031 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
12032 if (status != QDF_STATUS_SUCCESS) {
12033 hdd_err("failed pmo psoc configuration");
12034 return -EINVAL;
12035 }
12036
12037 return 0;
12038}
12039
Abhishek Singhb20db962017-03-03 21:28:46 +053012040#ifdef FEATURE_WLAN_SCAN_PNO
12041static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12042 struct hdd_config *cfg)
12043{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012044 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12045
Abhishek Singhb20db962017-03-03 21:28:46 +053012046 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12047 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12048 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12049 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12050 pno_cfg->channel_prediction_full_scan =
12051 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012052 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12053 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12054 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12055 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012056}
12057#else
12058static inline void
12059hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012060 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012061{
Abhishek Singhb20db962017-03-03 21:28:46 +053012062}
12063#endif
12064
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012065void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12066 struct hdd_config *cfg)
12067{
12068 uint8_t i = 0;
12069
12070 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12071 if (!ie_whitelist->white_list)
12072 return;
12073
12074 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12075 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12076 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12077 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12078 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12079 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12080 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12081 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12082
12083 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12084 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12085 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12086}
12087
Abhishek Singh257a9482017-03-06 16:52:39 +053012088/**
12089 * hdd_update_scan_config - API to update scan configuration parameters
12090 * @hdd_ctx: HDD context
12091 *
12092 * Return: 0 if success else err
12093 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012094static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012095{
12096 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12097 struct scan_user_cfg scan_cfg;
12098 struct hdd_config *cfg = hdd_ctx->config;
12099 QDF_STATUS status;
12100
12101 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12102 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12103 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12104 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12105 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12106 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12107 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012108 /* convert to ms */
12109 scan_cfg.scan_cache_aging_time =
12110 cfg->scanAgingTimeout * 1000;
12111 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12112 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12113 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12114 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012115 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012116 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Kiran Kumar Lokerea2dfefe2017-06-29 19:01:24 -070012117 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time ;
12118 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes ;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012119 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012120 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singh257a9482017-03-06 16:52:39 +053012121
Abhishek Singhb20db962017-03-03 21:28:46 +053012122 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012123 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012124
Abhishek Singh257a9482017-03-06 16:52:39 +053012125 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12126 if (status != QDF_STATUS_SUCCESS) {
12127 hdd_err("failed pmo psoc configuration");
12128 return -EINVAL;
12129 }
12130
12131 return 0;
12132}
Abhishek Singh257a9482017-03-06 16:52:39 +053012133
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012134static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012135{
12136 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12137 struct tdls_start_params tdls_cfg;
12138 struct tdls_user_config *config = &tdls_cfg.config;
12139 struct hdd_config *cfg = hdd_ctx->config;
12140 QDF_STATUS status;
12141
12142 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12143 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12144 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12145 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12146 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12147 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12148 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12149 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12150 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12151 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12152 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12153 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12154 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12155 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12156 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12157 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12158 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12159 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12160 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12161 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12162 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12163 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12164 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12165 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12166 (cfg->fEnableTDLSImplicitTrigger ?
12167 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12168 (cfg->fTDLSExternalControl ?
12169 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12170
12171 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12172 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12173 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12174 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012175 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012176 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012177 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12178 tdls_cfg.tdls_evt_cb_data = psoc;
12179 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12180 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12181 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012182 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12183 tdls_cfg.tdls_wmm_cb_data = psoc;
12184 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12185 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012186 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012187
12188 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12189 if (status != QDF_STATUS_SUCCESS) {
12190 hdd_err("failed pmo psoc configuration");
12191 return -EINVAL;
12192 }
12193
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012194 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012195 /* enable napier specific tdls data path */
12196 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012197
Frank Liud4b2fa02017-03-29 11:46:48 +080012198 return 0;
12199}
Frank Liud4b2fa02017-03-29 11:46:48 +080012200
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012201int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012202{
12203 int ret;
12204
12205 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012206 if (ret)
12207 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012208
Abhishek Singh257a9482017-03-06 16:52:39 +053012209 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012210 if (ret)
12211 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012212
Frank Liud4b2fa02017-03-29 11:46:48 +080012213 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012214 if (ret)
12215 return ret;
12216
12217 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012218
12219 return ret;
12220}
12221
Agrawal Ashish65634612016-08-18 13:24:32 +053012222/**
12223 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12224 * @mode : cfg80211 DFS mode
12225 *
12226 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12227 */
12228enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12229{
12230 switch (mode) {
12231 case DFS_MODE_ENABLE:
12232 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012233 case DFS_MODE_DISABLE:
12234 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012235 case DFS_MODE_DEPRIORITIZE:
12236 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012237 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012238 hdd_debug("ACS dfs mode is NONE");
12239 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012240 }
12241}
12242
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012243/**
12244 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12245 * @hddctx: pointer to hdd context
12246 * @set_value: enable/disable
12247 *
12248 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12249 * Host(even though it is duplicate). When Host send vendor command
12250 * disable,FW doesn't perform any action. Whenever any change in
12251 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12252 *
12253 * return - 0 on success, appropriate error values on failure.
12254 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012255int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012256{
12257 QDF_STATUS status;
12258
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012259 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012260 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012261
12262 if (!hddctx->config->goptimize_chan_avoid_event) {
12263 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12264 return -EINVAL;
12265 }
12266
12267 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12268 if (!QDF_IS_STATUS_SUCCESS(status)) {
12269 hdd_err("Failed to send chan avoid command to SME");
12270 return -EINVAL;
12271 }
12272 return 0;
12273}
Agrawal Ashish65634612016-08-18 13:24:32 +053012274
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012275/**
12276 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12277 * @value: value to set
12278 *
12279 * This function will set the passed value to roaming in progress flag.
12280 *
12281 * Return: None
12282 */
12283void hdd_set_roaming_in_progress(bool value)
12284{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012285 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012286
12287 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12288 if (!hdd_ctx) {
12289 hdd_err("HDD context is NULL");
12290 return;
12291 }
12292
12293 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012294 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012295}
12296
12297/**
12298 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012299 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012300 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012301 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012302 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012303bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012304{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012305 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012306 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012307
12308 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12309 if (!hdd_ctx) {
12310 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012311 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012312 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012313 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12314 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012315 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12316 hdd_ctx->roaming_in_progress);
12317
12318 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012319}
12320
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012321/**
12322 * hdd_is_connection_in_progress() - check if connection is in
12323 * progress
12324 * @session_id: session id
12325 * @reason: scan reject reason
12326 *
12327 * Go through each adapter and check if Connection is in progress
12328 *
12329 * Return: true if connection is in progress else false
12330 */
12331bool hdd_is_connection_in_progress(uint8_t *session_id,
12332 enum scan_reject_states *reason)
12333{
12334 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012335 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012336 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012337 QDF_STATUS status = 0;
12338 uint8_t sta_id = 0;
12339 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012340 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012341
12342 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12343 if (!hdd_ctx) {
12344 hdd_err("HDD context is NULL");
12345 return false;
12346 }
12347
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012348 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12349 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012350 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012351 if (!adapter)
12352 goto end;
12353
12354 hdd_info("Adapter with device mode %s(%d) exists",
12355 hdd_device_mode_to_string(adapter->device_mode),
12356 adapter->device_mode);
12357 if (((QDF_STA_MODE == adapter->device_mode)
12358 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12359 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12360 && (eConnectionState_Connecting ==
12361 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12362 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012363 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012364 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12365 adapter->sessionId);
12366 if (session_id && reason) {
12367 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012368 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012369 }
12370 return true;
12371 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012372 /*
12373 * sme_neighbor_middle_of_roaming is for LFR2
12374 * hdd_is_roaming_in_progress is for LFR3
12375 */
12376 if (((QDF_STA_MODE == adapter->device_mode) &&
12377 sme_neighbor_middle_of_roaming(
12378 WLAN_HDD_GET_HAL_CTX(adapter),
12379 adapter->sessionId)) ||
12380 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012381 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012382 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12383 adapter->sessionId);
12384 if (session_id && reason) {
12385 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012386 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012387 }
12388 return true;
12389 }
12390 if ((QDF_STA_MODE == adapter->device_mode) ||
12391 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12392 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12393 hdd_sta_ctx =
12394 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12395 if ((eConnectionState_Associated ==
12396 hdd_sta_ctx->conn_info.connState)
12397 && (false ==
12398 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12399 sta_mac = (uint8_t *)
12400 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012401 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012402 " is in middle of WPS/EAPOL exchange.",
12403 MAC_ADDR_ARRAY(sta_mac));
12404 if (session_id && reason) {
12405 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012406 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012407 }
12408 return true;
12409 }
12410 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12411 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12412 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12413 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012414 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012415 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012416 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012417 continue;
12418
12419 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012420 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070012421 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012422 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012423 " of SAP/GO is in middle of WPS/EAPOL exchange",
12424 MAC_ADDR_ARRAY(sta_mac));
12425 if (session_id && reason) {
12426 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012427 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012428 }
12429 return true;
12430 }
12431 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012432 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012433 return true;
12434 }
12435 }
12436end:
12437 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12438 adapter_node = next;
12439 }
12440 return false;
12441}
12442
12443/**
12444 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012445 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012446 *
12447 * Return: None
12448 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012449void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012450{
Jeff Johnson87251032017-08-29 13:31:11 -070012451 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012452 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012453 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012454 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012455 tsap_Config_t *sap_config;
12456 void *sap_ctx;
12457
12458 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070012459 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012460 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012461
12462 mutex_lock(&hdd_ctx->sap_lock);
12463 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12464 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012465 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12466 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12467 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12468 qdf_status =
12469 qdf_wait_single_event(&hostapd_state->
12470 qdf_stop_bss_event,
12471 SME_CMD_TIMEOUT_VALUE);
12472
12473 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012474 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012475 goto end;
12476 }
12477 }
12478 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012479 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012480 ap_adapter->device_mode, ap_adapter->sessionId);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012481 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012482
12483 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012484 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012485 wlansap_reset_sap_config_add_ie(sap_config,
12486 eUPDATE_IE_ALL);
12487 goto end;
12488 }
12489
12490 qdf_event_reset(&hostapd_state->qdf_event);
12491 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12492 sap_config,
12493 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012494 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012495 wlansap_reset_sap_config_add_ie(sap_config,
12496 eUPDATE_IE_ALL);
12497 goto end;
12498 }
12499
Jeff Johnson6867ec32017-09-29 20:30:20 -070012500 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012501 qdf_status =
12502 qdf_wait_single_event(&hostapd_state->qdf_event,
12503 SME_CMD_TIMEOUT_VALUE);
12504 wlansap_reset_sap_config_add_ie(sap_config,
12505 eUPDATE_IE_ALL);
12506 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012507 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012508 goto end;
12509 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012510 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012511 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070012512 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012513 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12514 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012515 ap_adapter->sessionId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012516 }
12517end:
12518 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012519}
12520
12521/**
12522 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12523 * with non dfs acs
12524 *
12525 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12526 *
12527 * Return: None
12528 */
12529void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12530{
Jeff Johnson9d295242017-08-29 14:39:48 -070012531 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012532 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012533 cds_context_type *cds_ctx;
12534
12535 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12536 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012537 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012538 return;
12539 }
12540
12541 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12542 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012543 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012544 return;
12545 }
12546
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012547 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12548 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012549 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012550 return;
12551 }
12552
12553 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012554 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12555 &ap_adapter->event_flags) &&
12556 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -070012557 ap_adapter->sessionCtx.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012558
Jeff Johnson6867ec32017-09-29 20:30:20 -070012559 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnson91df29d2017-10-27 19:29:50 -070012560 ap_adapter->sessionCtx.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012561 AUTO_CHANNEL_SELECT;
Jeff Johnson91df29d2017-10-27 19:29:50 -070012562 ap_adapter->sessionCtx.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012563 acs_cfg.acs_mode = true;
12564
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012565 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012566 }
12567}
12568
12569/**
12570 * hdd_set_connection_in_progress() - to set the connection in
12571 * progress flag
12572 * @value: value to set
12573 *
12574 * This function will set the passed value to connection in progress flag.
12575 * If value is previously being set to true then no need to set it again.
12576 *
12577 * Return: true if value is being set correctly and false otherwise.
12578 */
12579bool hdd_set_connection_in_progress(bool value)
12580{
12581 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012582 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012583
12584 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12585 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012586 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012587 return false;
12588 }
12589
12590 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12591 /*
12592 * if the value is set to true previously and if someone is
12593 * trying to make it true again then it could be some race
12594 * condition being triggered. Avoid this situation by returning
12595 * false
12596 */
12597 if (hdd_ctx->connection_in_progress && value)
12598 status = false;
12599 else
12600 hdd_ctx->connection_in_progress = value;
12601 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12602 return status;
12603}
12604
Jeff Johnson9d295242017-08-29 14:39:48 -070012605int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012606{
12607 if (!adapter) {
12608 hdd_err("Invalid adapter");
12609 return -EINVAL;
12610 }
12611 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012612 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012613 WMA_VDEV_MCC_SET_TIME_QUOTA,
12614 set_value, VDEV_CMD);
12615 return 0;
12616
12617}
12618
Jeff Johnson9d295242017-08-29 14:39:48 -070012619int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012620{
12621 if (!adapter) {
12622 hdd_err("Invalid adapter");
12623 return -EINVAL;
12624 }
12625
12626 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012627 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012628 WMA_VDEV_MCC_SET_TIME_LATENCY,
12629 set_value, VDEV_CMD);
12630 return 0;
12631}
12632
Jeff Johnson9d295242017-08-29 14:39:48 -070012633struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012634 *psoc, uint8_t vdev_id)
12635{
Jeff Johnson9d295242017-08-29 14:39:48 -070012636 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012637 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012638
12639 /*
12640 * Currently PSOC is not being used. But this logic will
12641 * change once we have the converged implementation of
12642 * HDD context per PSOC in place. This would break if
12643 * multiple vdev objects reuse the vdev id.
12644 */
12645 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12646 if (!adapter)
12647 hdd_err("Get adapter by vdev id failed");
12648
12649 return adapter;
12650}
12651
Jeff Johnson9d295242017-08-29 14:39:48 -070012652int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012653 int8_t *rssi, int8_t *snr)
12654{
12655 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012656 struct hdd_wext_state *wext_state =
12657 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012658 tCsrRoamProfile *profile = &wext_state->roamProfile;
12659
12660 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12661 profile, bssid, rssi, snr);
12662 if (QDF_STATUS_SUCCESS != status) {
12663 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12664 return -EINVAL;
12665 }
12666
12667 return 0;
12668}
12669
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012670/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012671 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12672 * @adapter - HDD adapter
12673 * @tos - type of service
12674 * @status - status of the traffic
12675 *
12676 * Return: 0 on success and non zero value on failure
12677 */
12678
12679int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12680 bool is_tos_active)
12681{
12682 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012683 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012684 uint32_t max_off_chan_time = 0;
12685 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012686 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012687 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012688
12689 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12690 ret = wlan_hdd_validate_context(hdd_ctx);
12691
12692 if (ret < 0) {
12693 hdd_err("failed to set limit off chan params");
12694 return ret;
12695 }
12696
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012697 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12698
12699 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012700 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012701 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012702 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012703
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012704 if (adapter->active_ac) {
12705 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012706 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012707 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12708 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12709 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012710 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012711 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012712 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12713 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12714 PM_LATENCY);
12715 } else {
12716 /*ignore this command if only BE/BK is active */
12717 is_tos_active = false;
12718 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12719 hdd_ctx->config->conc_system_pref);
12720 }
12721 } else {
12722 /* No active tos */
12723 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12724 hdd_ctx->config->conc_system_pref);
12725 }
12726
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012727 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12728 is_tos_active, max_off_chan_time,
12729 hdd_ctx->config->nRestTimeConc, true);
12730 if (!QDF_IS_STATUS_SUCCESS(status)) {
12731 hdd_err("failed to set limit off chan params");
12732 ret = -EINVAL;
12733 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012734
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012735 return ret;
12736}
12737
12738/**
12739 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
12740 * @adapter - HDD adapter
12741 *
12742 * Return: 0 on success and non zero value on failure
12743 */
12744int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
12745{
12746 struct hdd_context *hdd_ctx;
12747 int ret;
12748 QDF_STATUS status;
12749 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
12750
12751 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12752 ret = wlan_hdd_validate_context(hdd_ctx);
12753 if (ret < 0)
12754 return ret;
12755
12756 /* set the system preferece to default */
12757 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12758 hdd_ctx->config->conc_system_pref);
12759
12760 /* clear the bitmap */
12761 adapter->active_ac = 0;
12762
12763 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
12764 adapter->sessionId, adapter->active_ac);
12765
12766 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12767 false, 0, 0, false);
12768 if (!QDF_IS_STATUS_SUCCESS(status)) {
12769 hdd_err("failed to reset limit off chan params");
12770 ret = -EINVAL;
12771 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012772
12773 return ret;
12774}
12775
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012776/**
12777 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12778 * @drv_op: Enum indicating driver op
12779 *
12780 * Return: none
12781 */
12782void hdd_start_driver_ops_timer(int drv_op)
12783{
12784 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12785 switch (drv_op) {
12786 case eHDD_DRV_OP_PROBE:
12787 memcpy(drv_ops_string, "probe", sizeof("probe"));
12788 break;
12789 case eHDD_DRV_OP_REMOVE:
12790 memcpy(drv_ops_string, "remove", sizeof("remove"));
12791 break;
12792 case eHDD_DRV_OP_SHUTDOWN:
12793 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12794 break;
12795 case eHDD_DRV_OP_REINIT:
12796 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12797 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053012798 case eHDD_DRV_OP_IFF_UP:
12799 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
12800 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012801 }
12802
12803 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12804 HDD_OPS_INACTIVITY_TIMEOUT);
12805}
12806
12807/**
12808 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12809 *
12810 * Return: none
12811 */
12812void hdd_stop_driver_ops_timer(void)
12813{
12814 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12815}
12816
12817/**
12818 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12819 * inactivity timer
12820 *
12821 * Return: None
12822 */
12823void hdd_drv_ops_inactivity_handler(void)
12824{
12825 hdd_err("%s: %d Sec timer expired while in .%s",
12826 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12827
12828 /* Driver shutdown is stuck, no recovery possible at this point */
12829 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12830 sizeof("shutdown")))
12831 QDF_BUG(0);
12832
12833 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012834 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012835 else
12836 QDF_BUG(0);
12837}
12838
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012839void hdd_pld_ipa_uc_shutdown_pipes(void)
12840{
12841 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12842
12843 if (!hdd_ctx)
12844 return;
12845
12846 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12847}
12848
Yun Parkff6a16a2017-09-26 16:38:18 -070012849/**
12850 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
12851 * @struct hdd_context *hdd_ctx
12852 * @struct hdd_adapter *padapter
12853 * @bool enble
12854 *
12855 * Return: none
12856 */
12857void hdd_set_rx_mode_rps(bool enable)
12858{
12859 struct cds_config_info *cds_cfg = cds_get_ini_config();
12860 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12861 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
12862
12863 if (adapter && hdd_ctx &&
12864 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
12865 if (enable && !cds_cfg->rps_enabled)
12866 hdd_send_rps_ind(adapter);
12867 else if (!enable && cds_cfg->rps_enabled)
12868 hdd_send_rps_disable_ind(adapter);
12869 }
12870}
12871
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012872/* Register the module init/exit functions */
12873module_init(hdd_module_init);
12874module_exit(hdd_module_exit);
12875
12876MODULE_LICENSE("Dual BSD/GPL");
12877MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12878MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12879
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012880module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12881 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012882
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012883module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12884 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12885
Ravi Joshia307f632017-07-17 23:41:41 -070012886module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12887 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12888
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012889module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12890 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12891
12892module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12893
12894module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12895
12896module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);