blob: fa44b76f8497a8bb4626188e42d5277998d977be [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 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800342#ifdef BUILD_TAG
343uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
344#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800345uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700346#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800347
348/**
349 * hdd_device_mode_to_string() - return string conversion of device mode
350 * @device_mode: device mode
351 *
352 * This utility function helps log string conversion of device mode.
353 *
354 * Return: string conversion of device mode, if match found;
355 * "Unknown" otherwise.
356 */
357const char *hdd_device_mode_to_string(uint8_t device_mode)
358{
359 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800360 CASE_RETURN_STRING(QDF_STA_MODE);
361 CASE_RETURN_STRING(QDF_SAP_MODE);
362 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
363 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
364 CASE_RETURN_STRING(QDF_FTM_MODE);
365 CASE_RETURN_STRING(QDF_IBSS_MODE);
366 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
367 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700368 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800369 default:
370 return "Unknown";
371 }
372}
373
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530374/**
375 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
376 * @adapter: HDD adapter
377 * @chan_number: Channel number
378 * @chan_bw: Bandwidth
379 *
380 * Checks if the given bandwidth is valid for the given channel number.
381 *
382 * Return: 0 for success, non-zero for failure
383 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700384int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530385 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800386 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530387{
388 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
389 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
390 bool found = false;
391 tHalHandle hal;
392
393 hal = WLAN_HDD_GET_HAL_CTX(adapter);
394 if (!hal) {
395 hdd_err("Invalid HAL context");
396 return -EINVAL;
397 }
398
399 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
400 hdd_err("No valid channel list");
401 return -EOPNOTSUPP;
402 }
403
404 for (i = 0; i < len; i++) {
405 if (chan[i] == chan_number) {
406 found = true;
407 break;
408 }
409 }
410
411 if (found == false) {
412 hdd_err("Channel not in driver's valid channel list");
413 return -EOPNOTSUPP;
414 }
415
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700416 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
417 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530418 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
419 return -EINVAL;
420 }
421
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700422 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530423 if (chan_bw == CH_WIDTH_80MHZ) {
424 hdd_err("BW80 not possible in 2.4GHz band");
425 return -EINVAL;
426 }
427 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
428 (chan_bw != CH_WIDTH_MAX)) {
429 hdd_err("Only BW20 possible on channel 14");
430 return -EINVAL;
431 }
432 }
433
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700434 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530435 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
436 (chan_bw != CH_WIDTH_MAX)) {
437 hdd_err("Only BW20 possible on channel 165");
438 return -EINVAL;
439 }
440 }
441
442 return 0;
443}
444
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530445/**
446 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
447 *
448 * Block the unloading of the driver (or) interface up until the
449 * cds recovery is completed
450 *
451 * Return: true for recovery completion else false
452 */
453static bool hdd_wait_for_recovery_completion(void)
454{
455 int retry = 0;
456
457 /* Wait for recovery to complete */
458 while (cds_is_driver_recovering()) {
459 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
460 hdd_err("Recovery in progress; wait here!!!");
461 msleep(1000);
462 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
463 hdd_err("SSR never completed, error");
464 /*
465 * Trigger the bug_on in the internal builds, in the
466 * customer builds self-recovery will be enabled
467 * in those cases just return error.
468 */
469 if (cds_is_self_recovery_enabled())
470 return false;
471 QDF_BUG(0);
472 }
473 }
474
475 hdd_info("Recovery completed successfully!");
476 return true;
477}
478
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800479static int __hdd_netdev_notifier_call(struct notifier_block *nb,
480 unsigned long state, void *data)
481{
482#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
483 struct netdev_notifier_info *dev_notif_info = data;
484 struct net_device *dev = dev_notif_info->dev;
485#else
486 struct net_device *dev = data;
487#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700488 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700489 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800490
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800491 ENTER_DEV(dev);
492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800493 /* Make sure that this callback corresponds to our device. */
494 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
495 return NOTIFY_DONE;
496
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530497 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700499 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800500 return NOTIFY_DONE;
501 }
502
503 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700504 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800505 return NOTIFY_DONE;
506 }
507
508 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
509 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800510 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530511 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800512 return NOTIFY_DONE;
513 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800514
515 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
516 hdd_err("%s: Driver module is closed", __func__);
517 return NOTIFY_DONE;
518 }
519
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530520 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800521 return NOTIFY_DONE;
522
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800523 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800524 dev->name, state);
525
526 switch (state) {
527 case NETDEV_REGISTER:
528 break;
529
530 case NETDEV_UNREGISTER:
531 break;
532
533 case NETDEV_UP:
534 sme_ch_avoid_update_req(hdd_ctx->hHal);
535 break;
536
537 case NETDEV_DOWN:
538 break;
539
540 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700541 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800542 complete(&adapter->linkup_event_var);
543 break;
544
545 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700546 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
547 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530548 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700549 adapter->session_id, 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
Jeff Johnson1b780e42017-10-31 14:11:45 -0700801 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700802 hdd_info("adapter session is not open");
803 return -EAGAIN;
804 }
805
Jeff Johnson1b780e42017-10-31 14:11:45 -0700806 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
807 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700808 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
Jeff Johnson1b780e42017-10-31 14:11:45 -0700857 ret = sme_cli_set_command(adapter->session_id,
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
Jeff Johnson1b780e42017-10-31 14:11:45 -0700866 ret = sme_cli_set_command(adapter->session_id,
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
Jeff Johnson1b780e42017-10-31 14:11:45 -0700876 ret = sme_cli_set_command(adapter->session_id,
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
Jeff Johnson1b780e42017-10-31 14:11:45 -0700886 ret = sme_cli_set_command(adapter->session_id,
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
Jeff Johnson1b780e42017-10-31 14:11:45 -0700895 ret = sme_cli_set_command(adapter->session_id,
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
Jeff Johnson1b780e42017-10-31 14:11:45 -0700904 ret = sme_cli_set_command(adapter->session_id,
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
Jeff Johnson1b780e42017-10-31 14:11:45 -0700914 ret = sme_cli_set_command(adapter->session_id,
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
Jeff Johnson1b780e42017-10-31 14:11:45 -0700924 ret = sme_cli_set_command(adapter->session_id,
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
Yue Ma9e89e832017-11-14 11:40:23 -0800975static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter)
Yue Macd359b72017-10-03 15:21:00 -0700976{
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) {}
Yue Ma9e89e832017-11-14 11:40:23 -0800985static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter) {}
Yue Macd359b72017-10-03 15:21:00 -0700986#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",
Jeff Johnson1b780e42017-10-31 14:11:45 -07001869 adapter->session_id);
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;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002017 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302018
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
Dustin Brown6f427922017-09-19 12:19:00 -07002319 hdd_set_idle_ps_config(hdd_ctx, false);
2320 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302321
Dustin Brown1fe30a82017-10-03 16:13:36 -07002322 mutex_lock(&hdd_ctx->iface_change_lock);
2323 hdd_ctx->start_modules_in_progress = true;
2324
Arun Khandavallifae92942016-08-01 13:31:08 +05302325 switch (hdd_ctx->driver_status) {
2326 case DRIVER_MODULES_UNINITIALIZED:
2327 unint = true;
2328 /* Fall through dont add break here */
2329 case DRIVER_MODULES_CLOSED:
2330 if (!reinit && !unint) {
2331 ret = pld_power_on(qdf_dev->dev);
2332 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002333 hdd_err("Failed to Powerup the device; errno: %d",
2334 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302335 goto release_lock;
2336 }
2337 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002338
2339 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2340 hdd_ctx->config->enable_fw_log);
2341
Arun Khandavallifae92942016-08-01 13:31:08 +05302342 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2343 qdf_dev->bus_type,
2344 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2345 HIF_ENABLE_TYPE_PROBE);
2346 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002347 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302348 goto power_down;
2349 }
2350
2351 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302352 if (!hif_ctx) {
2353 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002354 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302355 goto power_down;
2356 }
2357
Arun Khandavallifae92942016-08-01 13:31:08 +05302358 status = ol_cds_init(qdf_dev, hif_ctx);
2359 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002360 hdd_err("No Memory to Create BMI Context; status: %d",
2361 status);
2362 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302363 goto hif_close;
2364 }
2365
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002366 ret = hdd_update_config(hdd_ctx);
2367 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002368 hdd_err("Failed to update configuration; errno: %d",
2369 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)) {
Dustin Browndca39692017-11-09 15:30:25 -08002377 hdd_err("Failed to Open CDS; status: %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) {
Dustin Browndca39692017-11-09 15:30:25 -08002385 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302386 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)) {
Dustin Browndca39692017-11-09 15:30:25 -08002391 hdd_err("Failed to Open cds post open; status: %d",
2392 status);
2393 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002394 goto close;
2395 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302396
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002397 /*
2398 * NAN compoenet requires certian operations like, open adapter,
2399 * close adapter, etc. to be initiated by HDD, for those
2400 * register HDD callbacks with UMAC's NAN componenet.
2401 */
2402 hdd_nan_register_callbacks(hdd_ctx);
2403
Arun Khandavallifae92942016-08-01 13:31:08 +05302404 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2405
Jeff Johnson3a280122017-09-13 07:42:00 -07002406 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302407 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002408 hdd_err("Failed to pre-enable CDS; status: %d", status);
2409 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002410 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302411 }
2412
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002413 hdd_register_policy_manager_callback(
2414 hdd_ctx->hdd_psoc);
2415
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302416 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302417 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302418
Arun Khandavallifae92942016-08-01 13:31:08 +05302419 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2420 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2421 hdd_ftm_mc_process_msg);
2422 break;
2423 }
2424 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002425 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302426 break;
2427 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302428
2429 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002430 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2431 if (ret) {
2432 hdd_err("HDD IPA UC reinit failed; errno: %d",
2433 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002434 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002435 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302436 }
2437
Arun Khandavallifae92942016-08-01 13:31:08 +05302438 /* Fall through dont add break here */
2439 case DRIVER_MODULES_OPENED:
2440 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002441 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002442 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002443 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302444 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302445 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2446 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002447 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302448 break;
2449 }
Dustin Browndca39692017-11-09 15:30:25 -08002450
2451 ret = hdd_configure_cds(hdd_ctx, adapter);
2452 if (ret) {
2453 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002454 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302455 }
Dustin Browndca39692017-11-09 15:30:25 -08002456
Komal Seelamf2136bb2016-09-28 18:30:44 +05302457 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302458 hdd_info("Driver Modules Successfully Enabled");
2459 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2460 break;
2461 case DRIVER_MODULES_ENABLED:
2462 hdd_info("Driver modules already Enabled");
2463 break;
2464 default:
2465 hdd_err("WLAN start invoked in wrong state! :%d\n",
2466 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002467 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302468 goto release_lock;
2469 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302470 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302471 mutex_unlock(&hdd_ctx->iface_change_lock);
2472 EXIT();
2473 return 0;
2474
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002475post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002476 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002477
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002478cds_txrx_free:
2479 cds_dp_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302480close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002481 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002482 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302483
Dustin Brown28b17892017-10-10 13:29:38 -07002484deinit_config:
2485 cds_deinit_ini_config();
2486
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002487cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302488 ol_cds_free();
2489
2490hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002491 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2492 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302493power_down:
2494 if (!reinit && !unint)
2495 pld_power_off(qdf_dev->dev);
2496release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302497 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302498 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302499 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002500
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002501 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302502}
2503
Naveen Rawat910726a2017-03-06 11:42:51 -08002504#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002505static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002506{
2507 int ret = os_if_wifi_pos_register_nl();
2508
2509 if (ret)
2510 hdd_err("os_if_wifi_pos_register_nl failed");
2511
2512 return ret;
2513}
2514
2515static int hdd_deactivate_wifi_pos(void)
2516{
2517 int ret = os_if_wifi_pos_deregister_nl();
2518
2519 if (ret)
2520 hdd_err("os_if_wifi_pos_deregister_nl failed");
2521
2522 return ret;
2523}
2524
2525/**
2526 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2527 * @hdd_ctx: hdd context
2528 *
2529 * Return: status of operation
2530 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002531static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002532{
2533 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2534 struct hdd_config *cfg = hdd_ctx->config;
2535
2536 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2537 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2538 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2539 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2540 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2541 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2542 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2543 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2544}
2545#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002546static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002547{
2548 return oem_activate_service(hdd_ctx);
2549}
2550
2551static int hdd_deactivate_wifi_pos(void)
2552{
2553 return 0;
2554}
2555
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002556static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002557{
2558}
2559#endif
2560
Arun Khandavallifae92942016-08-01 13:31:08 +05302561/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002562 * __hdd_open() - HDD Open function
2563 * @dev: Pointer to net_device structure
2564 *
2565 * This is called in response to ifconfig up
2566 *
2567 * Return: 0 for success; non-zero for failure
2568 */
2569static int __hdd_open(struct net_device *dev)
2570{
Jeff Johnson9d295242017-08-29 14:39:48 -07002571 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002572 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002573 int ret;
2574
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002575 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302576 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002577 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002578
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302579 /* Nothing to be done if device is unloading */
2580 if (cds_is_driver_unloading()) {
2581 hdd_err("Driver is unloading can not open the hdd");
2582 return -EBUSY;
2583 }
2584
Dustin Brown01847752017-10-25 13:56:27 -07002585 if (cds_is_driver_recovering()) {
2586 hdd_err("WLAN is currently recovering; Please try again.");
2587 return -EBUSY;
2588 }
2589
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302590 mutex_lock(&hdd_init_deinit_lock);
2591
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302592 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2593
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302594 /*
2595 * This scenario can be hit in cases where in the wlan driver after
2596 * registering the netdevices and there is a failure in driver
2597 * initialization. So return error gracefully because the netdevices
2598 * will be de-registered as part of the load failure.
2599 */
2600
2601 if (!cds_is_driver_loaded()) {
2602 hdd_err("Failed to start the wlan driver!!");
2603 ret = -EIO;
2604 goto err_hdd_hdd_init_deinit_lock;
2605 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302606
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002607
Arun Khandavallifae92942016-08-01 13:31:08 +05302608 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2609 if (ret) {
2610 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302611 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302612 }
2613
2614
2615 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2616 ret = hdd_start_adapter(adapter);
2617 if (ret) {
2618 hdd_err("Failed to start adapter :%d",
2619 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302620 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302621 }
2622 }
2623
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002624 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2625 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002626 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002627 /* Enable TX queues only when we are connected */
2628 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302629 WLAN_START_ALL_NETIF_QUEUE,
2630 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002631 }
2632
Naveen Rawat286def52016-09-23 15:38:02 -07002633 /* Enable carrier and transmit queues for NDI */
2634 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002635 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002636 wlan_hdd_netif_queue_control(adapter,
2637 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2638 WLAN_CONTROL_PATH);
2639 }
2640
Naveen Rawat910726a2017-03-06 11:42:51 -08002641 hdd_populate_wifi_pos_cfg(hdd_ctx);
2642
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302643err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302644 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302645 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002646 return ret;
2647}
2648
Arun Khandavallifae92942016-08-01 13:31:08 +05302649
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002650/**
2651 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2652 * @dev: Pointer to net_device structure
2653 *
2654 * This is called in response to ifconfig up
2655 *
2656 * Return: 0 for success; non-zero for failure
2657 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002658static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002659{
2660 int ret;
2661
2662 cds_ssr_protect(__func__);
2663 ret = __hdd_open(dev);
2664 cds_ssr_unprotect(__func__);
2665
2666 return ret;
2667}
2668
2669/**
2670 * __hdd_stop() - HDD stop function
2671 * @dev: Pointer to net_device structure
2672 *
2673 * This is called in response to ifconfig down
2674 *
2675 * Return: 0 for success; non-zero for failure
2676 */
2677static int __hdd_stop(struct net_device *dev)
2678{
Jeff Johnson9d295242017-08-29 14:39:48 -07002679 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002680 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002681 int ret;
2682
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002683 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002684
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302685 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002686 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002687
2688 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302689 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002690 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002691
2692 /* Nothing to be done if the interface is not opened */
2693 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002694 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002695 return -ENODEV;
2696 }
2697
2698 /* Make sure the interface is marked as closed */
2699 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302700
2701 hdd_debug("Disabling Auto Power save timer");
2702 sme_ps_disable_auto_ps_timer(
2703 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002704 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302705
2706 /*
2707 * Disable TX on the interface, after this hard_start_xmit() will not
2708 * be called on that interface
2709 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002710 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2711 hdd_device_mode_to_string(adapter->device_mode),
2712 adapter->device_mode);
2713
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302714 wlan_hdd_netif_queue_control(adapter,
2715 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2716 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002717
2718 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002719 * NAN data interface is different in some sense. The traffic on NDI is
2720 * bursty in nature and depends on the need to transfer. The service
2721 * layer may down the interface after the usage and up again when
2722 * required. In some sense, the NDI is expected to be available
2723 * (like SAP) iface until NDI delete request is issued by the service
2724 * layer. Skip BSS termination and adapter deletion for NAN Data
2725 * interface (NDI).
2726 */
2727 if (WLAN_HDD_IS_NDI(adapter))
2728 return 0;
2729
Tushnim Bhattacharyya86294892017-10-25 16:29:11 -07002730 policy_mgr_check_and_stop_opportunistic_timer(hdd_ctx->hdd_psoc);
2731
Naveen Rawat286def52016-09-23 15:38:02 -07002732 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002733 * The interface is marked as down for outside world (aka kernel)
2734 * But the driver is pretty much alive inside. The driver needs to
2735 * tear down the existing connection on the netdev (session)
2736 * cleanup the data pipes and wait until the control plane is stabilized
2737 * for this interface. The call also needs to wait until the above
2738 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002739 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740 * That is intentional to be able to scan if it is a STA/P2P interface
2741 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302742 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743
2744 /* DeInit the adapter. This ensures datapath cleanup as well */
2745 hdd_deinit_adapter(hdd_ctx, adapter, true);
2746
Arun Khandavallifae92942016-08-01 13:31:08 +05302747
2748 /*
2749 * Find if any iface is up. If any iface is up then can't put device to
2750 * sleep/power save mode
2751 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302752 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002753 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07002754 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
2755 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302756 hdd_prevent_suspend_timeout(
2757 hdd_ctx->config->iface_change_wait_time,
2758 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302759 }
2760
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002761 EXIT();
2762 return 0;
2763}
2764
2765/**
2766 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2767 * @dev: pointer to net_device structure
2768 *
2769 * This is called in response to ifconfig down
2770 *
2771 * Return: 0 for success and error number for failure
2772 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002773static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002774{
2775 int ret;
2776
2777 cds_ssr_protect(__func__);
2778 ret = __hdd_stop(dev);
2779 cds_ssr_unprotect(__func__);
2780
2781 return ret;
2782}
2783
2784/**
2785 * __hdd_uninit() - HDD uninit function
2786 * @dev: Pointer to net_device structure
2787 *
2788 * This is called during the netdev unregister to uninitialize all data
2789 * associated with the device
2790 *
2791 * Return: None
2792 */
2793static void __hdd_uninit(struct net_device *dev)
2794{
Jeff Johnson9d295242017-08-29 14:39:48 -07002795 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002796 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002797
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002798 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002799
2800 do {
2801 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002802 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002803 break;
2804 }
2805
Jeff Johnson399c6272017-08-30 10:51:00 -07002806 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2807 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002808 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002809 break;
2810 }
2811
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002812 if (dev != adapter->dev)
2813 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814
Jeff Johnson399c6272017-08-30 10:51:00 -07002815 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002816
2817 /* after uninit our adapter structure will no longer be valid */
2818 adapter->dev = NULL;
2819 adapter->magic = 0;
2820 } while (0);
2821
2822 EXIT();
2823}
2824
2825/**
2826 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2827 * @dev: pointer to net_device structure
2828 *
2829 * This is called during the netdev unregister to uninitialize all data
2830 * associated with the device
2831 *
2832 * Return: none
2833 */
2834static void hdd_uninit(struct net_device *dev)
2835{
2836 cds_ssr_protect(__func__);
2837 __hdd_uninit(dev);
2838 cds_ssr_unprotect(__func__);
2839}
2840
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002841static int hdd_open_cesium_nl_sock(void)
2842{
2843#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2844 struct netlink_kernel_cfg cfg = {
2845 .groups = WLAN_NLINK_MCAST_GRP_ID,
2846 .input = NULL
2847 };
2848#endif
2849 int ret = 0;
2850
2851#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2852 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2853#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2854 THIS_MODULE,
2855#endif
2856 &cfg);
2857#else
2858 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2859 WLAN_NLINK_MCAST_GRP_ID,
2860 NULL, NULL, THIS_MODULE);
2861#endif
2862
2863 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002864 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002865 ret = -ECONNREFUSED;
2866 }
2867
2868 return ret;
2869}
2870
2871static void hdd_close_cesium_nl_sock(void)
2872{
2873 if (NULL != cesium_nl_srv_sock) {
2874 netlink_kernel_release(cesium_nl_srv_sock);
2875 cesium_nl_srv_sock = NULL;
2876 }
2877}
2878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002879/**
2880 * __hdd_set_mac_address() - set the user specified mac address
2881 * @dev: Pointer to the net device.
2882 * @addr: Pointer to the sockaddr.
2883 *
2884 * This function sets the user specified mac address using
2885 * the command ifconfig wlanX hw ether <mac adress>.
2886 *
2887 * Return: 0 for success, non zero for failure
2888 */
2889static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2890{
Jeff Johnson9d295242017-08-29 14:39:48 -07002891 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002892 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002893 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302894 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002895 int ret;
2896
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002897 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002898
2899 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2900 ret = wlan_hdd_validate_context(hdd_ctx);
2901 if (0 != ret)
2902 return ret;
2903
Jeff Johnson1e851a12017-10-28 14:36:12 -07002904 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002905 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2906
2907 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302908 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002909}
2910
2911/**
2912 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2913 * function from SSR
2914 * @dev: pointer to net_device structure
2915 * @addr: Pointer to the sockaddr
2916 *
2917 * This function sets the user specified mac address using
2918 * the command ifconfig wlanX hw ether <mac adress>.
2919 *
2920 * Return: 0 for success.
2921 */
2922static int hdd_set_mac_address(struct net_device *dev, void *addr)
2923{
2924 int ret;
2925
2926 cds_ssr_protect(__func__);
2927 ret = __hdd_set_mac_address(dev, addr);
2928 cds_ssr_unprotect(__func__);
2929
2930 return ret;
2931}
2932
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002933uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002934{
2935 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002936
Anurag Chouhan6d760662016-02-20 16:05:43 +05302937 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002938 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2939 break;
2940 }
2941
Anurag Chouhan6d760662016-02-20 16:05:43 +05302942 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002943 return NULL;
2944
2945 hdd_ctx->config->intfAddrMask |= (1 << i);
2946 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2947}
2948
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07002949void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
2950 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002951{
2952 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002953
Anurag Chouhan6d760662016-02-20 16:05:43 +05302954 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002955 if (!memcmp(releaseAddr,
2956 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2957 6)) {
2958 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2959 break;
2960 }
2961 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002962}
2963
2964#ifdef WLAN_FEATURE_PACKET_FILTERING
2965/**
2966 * __hdd_set_multicast_list() - set the multicast address list
2967 * @dev: Pointer to the WLAN device.
2968 * @skb: Pointer to OS packet (sk_buff).
2969 *
2970 * This funciton sets the multicast address list.
2971 *
2972 * Return: None
2973 */
2974static void __hdd_set_multicast_list(struct net_device *dev)
2975{
Jeff Johnson9d295242017-08-29 14:39:48 -07002976 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002977 int i = 0, status;
2978 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002979 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302980 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2981 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2982 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002983
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002984 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302985 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302986 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002988 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302989 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302990 goto out;
2991
Dustin Brownc788acb2017-08-01 17:43:51 -07002992 status = hdd_validate_adapter(adapter);
2993 if (status)
2994 goto out;
2995
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302996 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2997 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002998 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302999 goto out;
3000 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003001
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303002 /* Delete already configured multicast address list */
3003 if (adapter->mc_addr_list.mc_cnt > 0) {
3004 hdd_info("clear previously configured MC address list");
3005 hdd_disable_and_flush_mc_addr_list(adapter,
3006 pmo_mc_list_change_notify);
3007 }
3008
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003009 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003010 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303011 hdd_disable_and_flush_mc_addr_list(adapter,
3012 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003013 } else {
3014 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303015 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003016 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303017 pmo_ucfg_max_mc_addr_supported(psoc));
3018 hdd_disable_and_flush_mc_addr_list(adapter,
3019 pmo_mc_list_change_notify);
3020 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003021 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003022 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003023 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303024 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003025 if (i == mc_count)
3026 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303027 memset(&(mc_list_request->mc_addr[i].bytes),
3028 0, ETH_ALEN);
3029 memcpy(&(mc_list_request->mc_addr[i].bytes),
3030 ha->addr, ETH_ALEN);
3031 hdd_info("mlist[%d] = %pM", i,
3032 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003033 i++;
3034 }
3035 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303036
3037 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003038 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303039 mc_list_request->count = mc_count;
3040 status = hdd_cache_mc_addr_list(mc_list_request);
3041 if (status == 0) {
3042 hdd_enable_mc_addr_filtering(adapter,
3043 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003044 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303045 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003046 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303047out:
3048 if (mc_list_request)
3049 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303050 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003051}
3052
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303053
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003054/**
3055 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3056 * @dev: pointer to net_device
3057 *
3058 * Return: none
3059 */
3060static void hdd_set_multicast_list(struct net_device *dev)
3061{
3062 cds_ssr_protect(__func__);
3063 __hdd_set_multicast_list(dev);
3064 cds_ssr_unprotect(__func__);
3065}
3066#endif
3067
3068/**
3069 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3070 * @dev: Pointer to the WLAN device.
3071 * @skb: Pointer to OS packet (sk_buff).
3072 *
3073 * This function is registered with the Linux OS for network
3074 * core to decide which queue to use first.
3075 *
3076 * Return: ac, Queue Index/access category corresponding to UP in IP header
3077 */
3078static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3079#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3080 , void *accel_priv
3081#endif
3082#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3083 , select_queue_fallback_t fallback
3084#endif
3085)
3086{
3087 return hdd_wmm_select_queue(dev, skb);
3088}
3089
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003090static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003091 .ndo_open = hdd_open,
3092 .ndo_stop = hdd_stop,
3093 .ndo_uninit = hdd_uninit,
3094 .ndo_start_xmit = hdd_hard_start_xmit,
3095 .ndo_tx_timeout = hdd_tx_timeout,
3096 .ndo_get_stats = hdd_get_stats,
3097 .ndo_do_ioctl = hdd_ioctl,
3098 .ndo_set_mac_address = hdd_set_mac_address,
3099 .ndo_select_queue = hdd_select_queue,
3100#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003101 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003102#endif
3103};
3104
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003105/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003106static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003107 .ndo_open = hdd_mon_open,
3108 .ndo_stop = hdd_stop,
3109 .ndo_get_stats = hdd_get_stats,
3110};
3111
3112/**
3113 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003114 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003115 * Return: None
3116 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003117void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003118{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003119 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003120 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003121 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003122 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003123}
3124
3125/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003126 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3127 * @hdd_ctx: global hdd context
3128 * @macAddr: mac address to assign to the interface
3129 * @name: User-visible name of the interface
3130 *
3131 * hdd adapter pointer would point to the netdev->priv space, this function
3132 * would retrive the pointer, and setup the hdd adapter configuration.
3133 *
3134 * Return: the pointer to hdd adapter, otherwise NULL
3135 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003136static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003138 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003139 const char *name)
3140{
Jeff Johnson5505db82017-11-02 21:19:23 -07003141 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003142 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003143 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003144 /*
3145 * cfg80211 initialization and registration....
3146 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003147 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003148#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3149 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003151 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3152 hdd_mon_mode_ether_setup : ether_setup),
3153 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154
Jeff Johnson5505db82017-11-02 21:19:23 -07003155 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003156
3157 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003158 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003159
Jeff Johnson9d295242017-08-29 14:39:48 -07003160 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003161 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303162 qdf_mem_set(sta_ctx->conn_info.staId,
3163 sizeof(sta_ctx->conn_info.staId),
3164 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003165 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003166 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003167 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003168 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169
3170 init_completion(&adapter->session_open_comp_var);
3171 init_completion(&adapter->session_close_comp_var);
3172 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303173 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003174 init_completion(&adapter->linkup_event_var);
3175 init_completion(&adapter->cancel_rem_on_chan_var);
3176 init_completion(&adapter->rem_on_chan_ready_event);
3177 init_completion(&adapter->sta_authorized_event);
3178 init_completion(&adapter->offchannel_tx_event);
3179 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003180 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303182 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003183
3184 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003185 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003187 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188
Jeff Johnson5505db82017-11-02 21:19:23 -07003189 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003191 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003193 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194
3195 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003196 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003197 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003198 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199
Jeff Johnson5505db82017-11-02 21:19:23 -07003200 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202 hdd_set_station_ops(adapter->dev);
3203
Jeff Johnson5505db82017-11-02 21:19:23 -07003204 hdd_dev_setup_destructor(dev);
3205 dev->ieee80211_ptr = &adapter->wdev;
3206 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003207 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003208 adapter->wdev.netdev = dev;
3209 /* set dev's parent to underlying device */
3210 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303212 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003213 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303214 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215 }
3216
3217 return adapter;
3218}
3219
Jeff Johnson9d295242017-08-29 14:39:48 -07003220static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003221{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003222 struct net_device *dev = adapter->dev;
3223 int ret;
3224
3225 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003226
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003227 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003228 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3229
3230 ret = dev_alloc_name(dev, dev->name);
3231 if (ret < 0) {
3232 hdd_err(
3233 "unable to get dev name: %s, err = 0x%x",
3234 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303235 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003236 }
3237 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003238
3239 ret = register_netdevice(dev);
3240 if (ret) {
3241 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3242 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303243 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244 }
3245 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003246 ret = register_netdev(dev);
3247 if (ret) {
3248 hdd_err("register_netdev(%s) failed, err = 0x%x",
3249 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303250 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003251 }
3252 }
3253 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3254
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003255 EXIT();
3256
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303257 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003258}
3259
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003260QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261{
Jeff Johnson9d295242017-08-29 14:39:48 -07003262 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263
3264 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003265 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303266 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267 }
3268
3269 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003270 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303271 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272 }
3273
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003274 /*
3275 * For NAN Data interface, the close session results in the final
3276 * indication to the userspace
3277 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003278 if (adapter->device_mode == QDF_NDI_MODE)
3279 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003280
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003281 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3282
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283 /*
3284 * We can be blocked while waiting for scheduled work to be
3285 * flushed, and the adapter structure can potentially be freed, in
3286 * which case the magic will have been reset. So make sure the
3287 * magic is still good, and hence the adapter structure is still
3288 * valid, before signaling completion
3289 */
3290 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3291 complete(&adapter->session_close_comp_var);
3292
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303293 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003294}
3295
Jeff Johnson9d295242017-08-29 14:39:48 -07003296int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003297{
Dustin Brownd28772b2017-03-17 14:16:07 -07003298 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003299
Dustin Brownd28772b2017-03-17 14:16:07 -07003300 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003301 if (QDF_IS_STATUS_ERROR(status))
3302 return qdf_status_to_os_return(status);
3303
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003304 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003305 if (QDF_IS_STATUS_ERROR(status))
3306 return qdf_status_to_os_return(status);
3307
3308 if (wma_capability_enhanced_mcast_filter())
3309 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3310 else
3311 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003312
3313 return qdf_status_to_os_return(status);
3314}
3315
Jeff Johnson9d295242017-08-29 14:39:48 -07003316int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003317{
3318 QDF_STATUS status;
3319 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003320 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003321 unsigned long rc;
3322
Jeff Johnson1b780e42017-10-31 14:11:45 -07003323 hdd_info("destroying vdev %d", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003324
3325 /* vdev created sanity check */
3326 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003327 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003328 return -EINVAL;
3329 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003330 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003331 /*
3332 * In SSR case, there is no need to destroy vdev in firmware since
3333 * it has already asserted. vdev can be released directly.
3334 */
3335 if (cds_is_driver_recovering())
3336 goto release_vdev;
3337
Dustin Brownd28772b2017-03-17 14:16:07 -07003338 /* close sme session (destroy vdev in firmware via legacy API) */
3339 INIT_COMPLETION(adapter->session_close_comp_var);
3340 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003341 status = sme_close_session(hdd_ctx->hHal, adapter->session_id,
Dustin Brownd28772b2017-03-17 14:16:07 -07003342 hdd_sme_close_session_callback, adapter);
3343 if (QDF_IS_STATUS_ERROR(status)) {
3344 hdd_err("failed to close sme session: %d", status);
3345 return qdf_status_to_os_return(status);
3346 }
3347
3348 /* block on a completion variable until sme session is closed */
3349 rc = wait_for_completion_timeout(
3350 &adapter->session_close_comp_var,
3351 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3352 if (!rc) {
3353 hdd_err("timed out waiting for close sme session: %ld", rc);
3354 if (adapter->device_mode == QDF_NDI_MODE)
3355 hdd_ndp_session_end_handler(adapter);
3356 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3357 return -ETIMEDOUT;
3358 }
Yue Maf9782842017-05-08 12:49:49 -07003359release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003360 /* do vdev logical destroy via objmgr */
3361 errno = hdd_objmgr_destroy_vdev(adapter);
3362 if (errno) {
3363 hdd_err("failed to destroy objmgr vdev: %d", errno);
3364 return errno;
3365 }
3366
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003367 /* now that sme session is closed, allow physical vdev destroy */
3368 errno = hdd_objmgr_release_vdev(adapter);
3369 if (errno) {
3370 hdd_err("failed to release objmgr vdev: %d", errno);
3371 return errno;
3372 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003373 hdd_info("vdev destroyed successfully");
3374
3375 return 0;
3376}
3377
Jeff Johnson9d295242017-08-29 14:39:48 -07003378int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003379{
3380 QDF_STATUS status;
3381 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003382 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003383 uint32_t type;
3384 uint32_t sub_type;
3385 unsigned long rc;
3386
3387 hdd_info("creating new vdev");
3388
3389 /* determine vdev (sub)type */
3390 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303391 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003392 hdd_err("failed to get vdev type: %d", status);
3393 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003394 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003395
3396 /* do vdev create via objmgr */
3397 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003398 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003399 if (errno) {
3400 hdd_err("failed to create objmgr vdev: %d", errno);
3401 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003402 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003403
3404 /* Open a SME session (prepare vdev in firmware via legacy API) */
3405 INIT_COMPLETION(adapter->session_open_comp_var);
3406 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
Jeff Johnson1e851a12017-10-28 14:36:12 -07003407 (uint8_t *)&adapter->mac_addr,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003408 adapter->session_id, type, sub_type);
Dustin Brownd28772b2017-03-17 14:16:07 -07003409 if (QDF_IS_STATUS_ERROR(status)) {
3410 hdd_err("failed to open sme session: %d", status);
3411 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003412 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003413 }
3414
3415 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 rc = wait_for_completion_timeout(
3417 &adapter->session_open_comp_var,
3418 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3419 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003420 hdd_err("timed out waiting for open sme session: %ld", rc);
3421 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303422 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Krunal Soni4a020c72017-10-30 20:58:40 -07003423 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003424 }
3425
3426 /* firmware ready for component communication, raise vdev_ready event */
3427 errno = hdd_vdev_ready(adapter);
3428 if (errno) {
3429 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003430 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003431 }
3432
Jeff Johnson1b780e42017-10-31 14:11:45 -07003433 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003434
3435 return 0;
3436
3437 /*
3438 * Due to legacy constraints, we need to destroy in the same order as
3439 * create. So, split error handling into 2 cases to accommodate.
3440 */
3441
Krunal Soni4a020c72017-10-30 20:58:40 -07003442objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003443 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003444
3445 return errno;
3446
Krunal Soni4a020c72017-10-30 20:58:40 -07003447hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003448 QDF_BUG(!hdd_vdev_destroy(adapter));
3449
3450 return errno;
3451}
3452
Jeff Johnson9d295242017-08-29 14:39:48 -07003453QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003454{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003455 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003456 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003457 QDF_STATUS status;
3458 int ret_val;
3459
3460 ret_val = hdd_vdev_create(adapter);
3461 if (ret_val) {
3462 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303463 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003464 }
3465
Dustin Brownd28772b2017-03-17 14:16:07 -07003466 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3467 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3468 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003469 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003470
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003472 status = hdd_register_wext(adapter->dev);
3473 if (QDF_IS_STATUS_ERROR(status)) {
3474 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475 goto error_register_wext;
3476 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003477 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478
Jeff Johnsond377dce2017-10-04 10:32:42 -07003479 qdf_mem_set(sta_ctx->conn_info.staId,
3480 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303481
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003482 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003483 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003484 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003485 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003486 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487 hdd_ctx->config->OperatingChannel;
3488
3489 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003490 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003491
3492 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303493 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003494 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003495 status, status);
3496 goto error_init_txrx;
3497 }
3498
3499 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3500
3501 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303502 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003503 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504 status, status);
3505 goto error_wmm_init;
3506 }
3507
3508 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3509
Jeff Johnson1b780e42017-10-31 14:11:45 -07003510 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003511 WMI_PDEV_PARAM_BURST_ENABLE,
3512 hdd_ctx->config->enableSifsBurst,
3513 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003514 if (ret_val)
3515 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303517 /*
3518 * In case of USB tethering, LRO is disabled. If SSR happened
3519 * during that time, then as part of SSR init, do not enable
3520 * the LRO again. Keep the LRO state same as before SSR.
3521 */
3522 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003523 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303524
3525 /* rcpi info initialization */
3526 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3527
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303528 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003529
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530error_wmm_init:
3531 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3532 hdd_deinit_tx_rx(adapter);
3533error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003534 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003535error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003536 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003537
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538 return status;
3539}
3540
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303541/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003542 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303543 * @hdd_ctx: global hdd context
3544 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003545 * @rtnl_held: Used to indicate whether or not the caller is holding
3546 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303547 *
3548 * This function De-initializes the STA/P2P/OCB adapter.
3549 *
3550 * Return: None.
3551 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003552static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003553 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003554 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303555{
3556 ENTER_DEV(adapter->dev);
3557
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303558 if (adapter->dev) {
3559 if (rtnl_held)
3560 adapter->dev->wireless_handlers = NULL;
3561 else {
3562 rtnl_lock();
3563 adapter->dev->wireless_handlers = NULL;
3564 rtnl_unlock();
3565 }
3566 }
3567
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303568 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3569 hdd_deinit_tx_rx(adapter);
3570 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3571 }
3572
3573 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3574 hdd_wmm_adapter_close(adapter);
3575 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3576 }
3577
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303578 EXIT();
3579}
3580
Jeff Johnson9d295242017-08-29 14:39:48 -07003581void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003582 bool rtnl_held)
3583{
3584 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303585
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003586 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003587 case QDF_STA_MODE:
3588 case QDF_P2P_CLIENT_MODE:
3589 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003591 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592 break;
3593 }
3594
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003595 case QDF_SAP_MODE:
3596 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003597 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003598 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599 break;
3600 }
3601
3602 default:
3603 break;
3604 }
3605
3606 EXIT();
3607}
3608
Jeff Johnson9d295242017-08-29 14:39:48 -07003609static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003610 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003611{
Jeff Johnson5505db82017-11-02 21:19:23 -07003612 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003613
3614 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003615 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003617 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618 return;
3619 }
3620
Rajeev Kumardca5f812016-02-04 17:28:06 -08003621 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303622
3623 if (adapter->scan_info.default_scan_ies) {
3624 qdf_mem_free(adapter->scan_info.default_scan_ies);
3625 adapter->scan_info.default_scan_ies = NULL;
3626 }
3627
Yue Ma9e89e832017-11-14 11:40:23 -08003628 hdd_adapter_runtime_suspend_deinit(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303629
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003630 /*
3631 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3632 * the driver is almost closed and cannot handle either control
3633 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003634 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3635 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003636 * is not right. Setting this flag helps hdd_stop() to recognize that
3637 * the interface is closed and restricts any operations on that
3638 */
3639 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3640
3641 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003642 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003643 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003644 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003645 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003646 /*
3647 * Note that the adapter is no longer valid at this point
3648 * since the memory has been reclaimed
3649 */
3650 }
3651}
3652
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003653static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003654 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655{
3656 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003657 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303658 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003659
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303661 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003662 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003663 if (adapter
Jeff Johnson1e851a12017-10-28 14:36:12 -07003664 && !qdf_mem_cmp(adapter->mac_addr.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303666 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 }
3668 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3669 adapterNode = pNext;
3670 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303671 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003672}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003673
Arun Khandavalli2358d522016-05-16 18:05:37 +05303674#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3675/**
3676 * hdd_set_fw_log_params() - Set log parameters to FW
3677 * @hdd_ctx: HDD Context
3678 * @adapter: HDD Adapter
3679 *
3680 * This function set the FW Debug log level based on the INI.
3681 *
3682 * Return: None
3683 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003684static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003685 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303686{
3687 uint8_t count = 0, numentries = 0,
3688 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3689 uint32_t value = 0;
3690 int ret;
3691
Arun Khandavallifae92942016-08-01 13:31:08 +05303692 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3693 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003694 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303695 return;
3696 }
3697
Arun Khandavallifae92942016-08-01 13:31:08 +05303698 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303699 hdd_ctx->fw_log_settings.dl_type =
3700 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003701 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303702 WMI_DBGLOG_TYPE,
3703 hdd_ctx->config->enableFwLogType,
3704 DBG_CMD);
3705 if (ret != 0)
3706 hdd_err("Failed to enable FW log type ret %d",
3707 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303708
3709 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303710 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003711 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303712 WMI_DBGLOG_LOG_LEVEL,
3713 hdd_ctx->config->enableFwLogLevel,
3714 DBG_CMD);
3715 if (ret != 0)
3716 hdd_err("Failed to enable FW log level ret %d",
3717 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303718
3719 hdd_string_to_u8_array(
3720 hdd_ctx->config->enableFwModuleLogLevel,
3721 moduleloglevel,
3722 &numentries,
3723 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3724
3725 while (count < numentries) {
3726 /*
3727 * FW module log level input string looks like
3728 * below:
3729 * gFwDebugModuleLoglevel=<FW Module ID>,
3730 * <Log Level>,...
3731 * For example:
3732 * gFwDebugModuleLoglevel=
3733 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3734 * Above input string means :
3735 * For FW module ID 1 enable log level 0
3736 * For FW module ID 2 enable log level 1
3737 * For FW module ID 3 enable log level 2
3738 * For FW module ID 4 enable log level 3
3739 * For FW module ID 5 enable log level 4
3740 * For FW module ID 6 enable log level 5
3741 * For FW module ID 7 enable log level 6
3742 */
3743
Nishank Aggarwale239d962017-03-03 12:26:02 +05303744 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3745 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3746 hdd_err("Module id %d and dbglog level %d input length is more than max",
3747 moduleloglevel[count],
3748 moduleloglevel[count + 1]);
3749 return;
3750 }
3751
3752 value = moduleloglevel[count] << 16;
3753 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07003754 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303755 WMI_DBGLOG_MOD_LOG_LEVEL,
3756 value, DBG_CMD);
3757 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303758 hdd_err("Failed to enable FW module log level %d ret %d",
3759 value, ret);
3760
3761 count += 2;
3762 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303763
Arun Khandavalli2358d522016-05-16 18:05:37 +05303764}
3765#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003766static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003767 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303768{
3769}
3770
3771#endif
3772
3773/**
3774 * hdd_set_fw_params() - Set parameters to firmware
3775 * @adapter: HDD adapter
3776 *
3777 * This function Sets various parameters to fw once the
3778 * adapter is started.
3779 *
3780 * Return: 0 on success or errno on failure
3781 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003782int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303783{
3784 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003785 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303786
3787 ENTER_DEV(adapter->dev);
3788
3789 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3790 if (!hdd_ctx)
3791 return -EINVAL;
3792
Dustin Brown732ab9c2017-06-15 13:24:09 -07003793 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3794 hdd_debug("FTM Mode is active; nothing to do");
3795 return 0;
3796 }
3797
Jeff Johnson1b780e42017-10-31 14:11:45 -07003798 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303799 WMI_PDEV_PARAM_DTIM_SYNTH,
3800 hdd_ctx->config->enable_lprx, PDEV_CMD);
3801 if (ret) {
3802 hdd_err("Failed to set LPRx");
3803 goto error;
3804 }
3805
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303806 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003807 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303808 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3809 hdd_ctx->config->upper_brssi_thresh);
3810
Jeff Johnson1b780e42017-10-31 14:11:45 -07003811 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303812 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3813 hdd_ctx->config->lower_brssi_thresh);
3814
Jeff Johnson1b780e42017-10-31 14:11:45 -07003815 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303816 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3817 hdd_ctx->config->enable_dtim_1chrx);
3818 }
3819
Dustin Brown732ab9c2017-06-15 13:24:09 -07003820 if (hdd_ctx->config->enable2x2) {
3821 hdd_debug("configuring 2x2 mode fw params");
3822
Jeff Johnson1b780e42017-10-31 14:11:45 -07003823 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003824 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3825 hdd_ctx->config->enable_cck_tx_fir_override,
3826 PDEV_CMD);
3827 if (ret) {
3828 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3829 ret);
3830 goto error;
3831 }
3832 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303833#define HDD_DTIM_1CHAIN_RX_ID 0x5
3834#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003835 hdd_debug("configuring 1x1 mode fw params");
3836
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003837 /*
3838 * Disable DTIM 1 chain Rx when in 1x1,
3839 * we are passing two value
3840 * as param_id << 29 | param_value.
3841 * Below param_value = 0(disable)
3842 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003843 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003844 WMI_STA_SMPS_PARAM_CMDID,
3845 HDD_DTIM_1CHAIN_RX_ID <<
3846 HDD_SMPS_PARAM_VALUE_S,
3847 VDEV_CMD);
3848 if (ret) {
3849 hdd_err("DTIM 1 chain set failed %d", ret);
3850 goto error;
3851 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303852
Jeff Johnson1b780e42017-10-31 14:11:45 -07003853 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003854 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3855 hdd_ctx->config->txchainmask1x1,
3856 PDEV_CMD);
3857 if (ret) {
3858 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3859 ret);
3860 goto error;
3861 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303862
Jeff Johnson1b780e42017-10-31 14:11:45 -07003863 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003864 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3865 hdd_ctx->config->rxchainmask1x1,
3866 PDEV_CMD);
3867 if (ret) {
3868 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3869 ret);
3870 goto error;
3871 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303872#undef HDD_DTIM_1CHAIN_RX_ID
3873#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003874 }
3875
Jeff Johnson1b780e42017-10-31 14:11:45 -07003876 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003877 WMI_PDEV_PARAM_HYST_EN,
3878 hdd_ctx->config->enableMemDeepSleep,
3879 PDEV_CMD);
3880 if (ret) {
3881 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3882 goto error;
3883 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303884
Jeff Johnson1b780e42017-10-31 14:11:45 -07003885 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003886 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3887 hdd_ctx->config->rts_profile,
3888 VDEV_CMD);
3889 if (ret) {
3890 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3891 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303892 }
3893
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003894 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3895
Jeff Johnson1b780e42017-10-31 14:11:45 -07003896 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003897 GEN_VDEV_PARAM_AMSDU,
3898 hdd_ctx->config->max_amsdu_num,
3899 GEN_CMD);
3900 if (ret != 0) {
3901 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3902 goto error;
3903 }
3904
Arun Khandavalli2358d522016-05-16 18:05:37 +05303905 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303906 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003907
Arun Khandavalli2358d522016-05-16 18:05:37 +05303908 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303909
Arun Khandavalli2358d522016-05-16 18:05:37 +05303910error:
3911 return -EINVAL;
3912}
3913
Ryan Hsu07495ea2016-01-21 15:25:39 -08003914/**
3915 * hdd_open_adapter() - open and setup the hdd adatper
3916 * @hdd_ctx: global hdd context
3917 * @session_type: type of the interface to be created
3918 * @iface_name: User-visible name of the interface
3919 * @macAddr: MAC address to assign to the interface
3920 * @name_assign_type: the name of assign type of the netdev
3921 * @rtnl_held: the rtnl lock hold flag
3922 *
3923 * This function open and setup the hdd adpater according to the device
3924 * type request, assign the name, the mac address assigned, and then prepared
3925 * the hdd related parameters, queue, lock and ready to start.
3926 *
3927 * Return: the pointer of hdd adapter, otherwise NULL.
3928 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003929struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003931 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003932 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933{
Jeff Johnson9d295242017-08-29 14:39:48 -07003934 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303936 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937
3938 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3939 /*
3940 * Max limit reached on the number of vdevs configured by the
3941 * host. Return error
3942 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303943 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3944 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945 return NULL;
3946 }
3947
3948 if (macAddr == NULL) {
3949 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303950 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003951 return NULL;
3952 }
3953 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303954 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303955 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3956 " already exists",
3957 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 return NULL;
3959 }
3960
3961 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003962 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003963 /* Reset locally administered bit if the device mode is STA */
3964 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303965 hdd_info("locally administered bit reset in sta mode: "
3966 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003968 case QDF_P2P_CLIENT_MODE:
3969 case QDF_P2P_DEVICE_MODE:
3970 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003971 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303972 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003973 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3974 name_assign_type,
3975 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976
3977 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303978 hdd_err("failed to allocate adapter for session %d",
3979 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 return NULL;
3981 }
3982
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003983 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003985 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303987 else if (QDF_MONITOR_MODE == session_type)
3988 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989 else
3990 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3991
3992 adapter->device_mode = session_type;
3993
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003995 /*
3996 * Workqueue which gets scheduled in IPv4 notification
3997 * callback
3998 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07003999 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001
4002#ifdef WLAN_NS_OFFLOAD
4003 /*
4004 * Workqueue which gets scheduled in IPv6
4005 * notification callback.
4006 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004007 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 hdd_ipv6_notifier_work_queue);
4009#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304011 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Yue Ma9e89e832017-11-14 11:40:23 -08004013 goto err_deinit_adapter_runtime_pm;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004014 }
4015
4016 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004017 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304019 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4020 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304021
Ravi Joshi1a292562017-05-18 16:28:54 -07004022 /* Initialize NAN Data Interface */
4023 if (QDF_NDI_MODE == session_type) {
4024 status = hdd_init_nan_data_mode(adapter);
4025 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004026 goto err_deinit_adapter_runtime_pm;
Ravi Joshi1a292562017-05-18 16:28:54 -07004027 }
4028
4029 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004031 case QDF_P2P_GO_MODE:
4032 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004033 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4034 name_assign_type,
4035 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004036 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004037 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304038 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 return NULL;
4040 }
4041
4042 adapter->wdev.iftype =
4043 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004044 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004045 NL80211_IFTYPE_P2P_GO;
4046 adapter->device_mode = session_type;
4047
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004048 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304049 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4051 goto err_free_netdev;
4052 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004053 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304055 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4056 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304057
4058 /*
4059 * Workqueue which gets scheduled in IPv4 notification
4060 * callback
4061 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004062 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304063 hdd_ipv4_notifier_work_queue);
4064
4065#ifdef WLAN_NS_OFFLOAD
4066 /*
4067 * Workqueue which gets scheduled in IPv6
4068 * notification callback.
4069 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004070 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304071 hdd_ipv6_notifier_work_queue);
4072#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304074 case QDF_FTM_MODE:
4075 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4076 name_assign_type,
4077 "wlan0");
4078 if (NULL == adapter) {
4079 hdd_err("Failed to allocate adapter for FTM mode");
4080 return NULL;
4081 }
4082 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4083 adapter->device_mode = session_type;
4084 status = hdd_register_interface(adapter, rtnl_held);
4085 if (QDF_STATUS_SUCCESS != status) {
4086 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Yue Ma9e89e832017-11-14 11:40:23 -08004087 goto err_deinit_adapter_runtime_pm;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304088 }
4089 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004090 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304091 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304092 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4093 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304094 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004096 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304097 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098 return NULL;
4099 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100
hqueaa33ee2017-05-04 17:56:35 +08004101 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4102
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304103 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104 /* Add it to the hdd's session list. */
4105 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304106 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004107 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304108 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004110 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004111 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4112 }
4113 }
4114
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304115 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 if (NULL != adapter) {
4117 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4118 adapter = NULL;
4119 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004120 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304121 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004122
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123 return NULL;
4124 }
4125
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304126 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004127 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4128 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004129
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130 /* Adapter successfully added. Increment the vdev count */
4131 hdd_ctx->current_intf_count++;
4132
Jeff Johnson5880d792016-08-15 13:32:30 -07004133 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004134 hdd_ctx->current_intf_count);
4135
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004136 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004137 }
4138
Rajeev Kumardca5f812016-02-04 17:28:06 -08004139 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004140 hdd_err("Interface %s wow debug_fs init failed",
4141 netdev_name(adapter->dev));
4142
4143 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4144 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145
4146 return adapter;
4147
Yue Ma9e89e832017-11-14 11:40:23 -08004148err_deinit_adapter_runtime_pm:
4149 /*
4150 * For certain error cases that hdd_alloc_station_adapter()
4151 * is used to allocate the adapter.
4152 */
4153 hdd_adapter_runtime_suspend_deinit(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004154err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004155 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304156 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004157
4158 return NULL;
4159}
4160
Jeff Johnson9d295242017-08-29 14:39:48 -07004161QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004162 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163{
4164 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304165 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004166
4167 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304168 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004169 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004170 status);
4171 return status;
4172 }
4173
Jeff Johnson57eb2732017-10-02 11:40:20 -07004174 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304176 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177 break;
4178
4179 pCurrent = pNext;
4180 }
4181 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304182 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004183 /*
4184 * Here we are stopping global bus_bw timer & work per adapter.
4185 *
4186 * The reason is to fix one race condition between
4187 * bus bandwidth work and cleaning up an adapter.
4188 * Under some conditions, it is possible for the bus bandwidth
4189 * work to access a particularly destroyed adapter, leading to
4190 * use-after-free.
4191 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004192 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004193 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004194 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004195
4196 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004197 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4198 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004199 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004200 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304201 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004202 adapterNode = NULL;
4203
Dustin Brown5ec6b552017-03-31 12:11:40 -07004204 /* conditionally restart the bw timer */
4205 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004207 /* Adapter removed. Decrement vdev count */
4208 if (hdd_ctx->current_intf_count != 0)
4209 hdd_ctx->current_intf_count--;
4210
4211 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304212 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004213 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304214
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304215 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004216}
4217
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004218/**
4219 * hdd_close_all_adapters - Close all open adapters
4220 * @hdd_ctx: Hdd context
4221 * rtnl_held: True if RTNL lock held
4222 *
4223 * Close all open adapters.
4224 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304225 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004226 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004227QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004228{
4229 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304230 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004231
4232 ENTER();
4233
4234 do {
4235 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304236 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304237 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004238 pHddAdapterNode->adapter->mac_addr.bytes);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004239 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004240 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304241 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304242 /* Adapter removed. Decrement vdev count */
4243 if (hdd_ctx->current_intf_count != 0)
4244 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004245 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304246 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004247
4248 EXIT();
4249
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304250 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004251}
4252
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004253void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004254{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304255 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004256 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004257
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004258 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004259 case QDF_STA_MODE:
4260 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004261 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004262 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004263 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004264 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004265 break;
4266 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004267 case QDF_SAP_MODE:
4268 case QDF_P2P_GO_MODE:
4269 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004270 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004271 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004272 break;
4273 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004274 case QDF_FTM_MODE:
4275 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004276 default:
4277 /*
4278 * wlan_hdd_reset_prob_rspies should not have been called
4279 * for these kind of devices
4280 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004281 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004282 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 return;
4284 }
4285
Anurag Chouhanc5548422016-02-24 18:33:27 +05304286 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004287 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288 updateIE.ieBufferlength = 0;
4289 updateIE.pAdditionIEBuffer = NULL;
4290 updateIE.append = true;
4291 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004292 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004293 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304294 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004295 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004296 }
4297}
4298
Jeff Johnson9d295242017-08-29 14:39:48 -07004299QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004300 const bool bCloseSession)
4301{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304302 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004303 struct hdd_wext_state *pWextState =
4304 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305 union iwreq_data wrqu;
4306 tSirUpdateIE updateIE;
4307 unsigned long rc;
4308
4309 ENTER();
4310
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004311 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304312 wlan_hdd_netif_queue_control(adapter,
4313 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4314 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004315 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004316 case QDF_STA_MODE:
4317 case QDF_P2P_CLIENT_MODE:
4318 case QDF_IBSS_MODE:
4319 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004320 case QDF_NDI_MODE:
4321 if ((QDF_NDI_MODE == adapter->device_mode) ||
4322 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004323 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4324 hdd_is_connecting(
4325 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004326 INIT_COMPLETION(adapter->disconnect_comp_var);
4327 /*
4328 * For NDI do not use pWextState from sta_ctx, if needed
4329 * extract from ndi_ctx.
4330 */
4331 if (QDF_NDI_MODE == adapter->device_mode)
4332 qdf_ret_status = sme_roam_disconnect(
4333 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004334 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004335 eCSR_DISCONNECT_REASON_NDI_DELETE);
4336 else if (pWextState->roamProfile.BSSType ==
4337 eCSR_BSS_TYPE_START_IBSS)
4338 qdf_ret_status = sme_roam_disconnect(
4339 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004340 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004341 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004342 else if (QDF_STA_MODE == adapter->device_mode)
4343 qdf_ret_status =
4344 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004345 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004346 qdf_ret_status = sme_roam_disconnect(
4347 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004348 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004349 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004350 /* success implies disconnect command got
4351 * queued up successfully
4352 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004353 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4354 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004355 rc = wait_for_completion_timeout(
4356 &adapter->disconnect_comp_var,
4357 msecs_to_jiffies
4358 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004359 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004360 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004361 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004362 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4363 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364 memset(&wrqu, '\0', sizeof(wrqu));
4365 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4366 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4367 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4368 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304369 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004370 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004371
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304372 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304373 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004374
4375#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004376 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377#endif
4378
4379 hdd_deregister_tx_flow_control(adapter);
4380
4381#ifdef WLAN_NS_OFFLOAD
4382#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004383 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004384#endif
4385#endif
4386
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304387 if (adapter->device_mode == QDF_STA_MODE)
4388 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4389 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004390 /*
4391 * It is possible that the caller of this function does not
4392 * wish to close the session
4393 */
Krunal Soni985b8132017-02-10 18:49:08 -08004394 if (true == bCloseSession) {
4395 if (0 != wlan_hdd_try_disconnect(adapter)) {
4396 hdd_err("Error: Can't disconnect adapter");
4397 return QDF_STATUS_E_FAILURE;
4398 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004399 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004400 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004401 break;
4402
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004403 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304404 /* Flush IPA exception path packets */
4405 hdd_ipa_flush(hdd_ctx);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004406
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004407 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004408 if (QDF_SAP_MODE == adapter->device_mode) {
4409 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4410 cds_flush_delayed_work(
4411 &adapter->acs_pending_work);
4412 clear_bit(ACS_PENDING, &adapter->event_flags);
4413 }
4414 }
Krunal Soni22208392017-09-29 18:10:34 -07004415 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004417 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004418 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004419 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004420 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4421
4422 hdd_deregister_tx_flow_control(adapter);
4423
Kapil Guptac1224bf2017-06-22 21:22:40 +05304424 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004425 mutex_lock(&hdd_ctx->sap_lock);
4426 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304427 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304428 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429
4430 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004431 status = wlansap_stop_bss(
4432 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004433
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304434 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004435 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304437 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304438 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304439 qdf_status =
4440 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004441 qdf_stop_bss_event,
4442 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443
Anurag Chouhance0dc992016-02-16 18:18:03 +05304444 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004445 hdd_err("failure waiting for wlansap_stop_bss %d",
4446 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004447 }
4448 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004449 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004450 }
4451 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004452 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4453 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004454 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004455
Anurag Chouhanc5548422016-02-24 18:33:27 +05304456 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004457 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004458 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004459 updateIE.ieBufferlength = 0;
4460 updateIE.pAdditionIEBuffer = NULL;
4461 updateIE.append = false;
4462 updateIE.notify = false;
4463 /* Probe bcn reset */
4464 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4465 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304466 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004467 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004468 }
4469 /* Assoc resp reset */
4470 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4471 &updateIE,
4472 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304473 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004474 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004475 }
4476 /* Reset WNI_CFG_PROBE_RSP Flags */
4477 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004478 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004479 qdf_mem_free(adapter->session.ap.beacon);
4480 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304481 /*
4482 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4483 */
4484 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4485 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4486
Peng Xu66162de2016-02-11 17:01:20 -08004487 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004488 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004489 mutex_unlock(&hdd_ctx->sap_lock);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304490
4491#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004492 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304493#endif
4494
4495#ifdef WLAN_NS_OFFLOAD
4496#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004497 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304498#endif
4499#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004501 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004502 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004503 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004504 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004505 break;
4506 default:
4507 break;
4508 }
4509
4510 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304511 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004512}
4513
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304514/**
4515 * hdd_deinit_all_adapters - deinit all adapters
4516 * @hdd_ctx: HDD context
4517 * @rtnl_held: True if RTNL lock held
4518 *
4519 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004520void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304521{
4522 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4523 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004524 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304525
4526 ENTER();
4527
4528 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4529
4530 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004531 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304532 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4533 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4534 adapter_node = next;
4535 }
4536
4537 EXIT();
4538}
4539
Dustin Brown27cd9942017-09-27 16:11:44 -07004540QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4541 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004542{
4543 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304544 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004545 struct hdd_adapter *adapter;
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;
Dustin Brown27cd9942017-09-27 16:11:44 -07004555 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004556 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4557 adapterNode = pNext;
4558 }
4559
4560 EXIT();
4561
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304562 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004563}
4564
Paul Zhang84fa9382017-11-10 21:18:21 +08004565static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4566 struct hdd_adapter *adapter)
4567{
4568 switch (adapter->device_mode) {
4569 case QDF_STA_MODE:
4570 case QDF_P2P_CLIENT_MODE:
4571 case QDF_IBSS_MODE:
4572 case QDF_P2P_DEVICE_MODE:
4573 case QDF_NDI_MODE:
4574 wlan_hdd_scan_abort(adapter);
4575 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4576 if (adapter->device_mode == QDF_STA_MODE)
4577 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4578 adapter->dev);
4579 break;
4580 case QDF_P2P_GO_MODE:
4581 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4582 break;
4583 case QDF_SAP_MODE:
4584 wlan_hdd_undo_acs(adapter);
4585 break;
4586 default:
4587 break;
4588 }
4589}
4590
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004591QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004592{
4593 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304594 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004595 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004596 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004597 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004598
4599 ENTER();
4600
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304601 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4602
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004603 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4604
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304605 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004606 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004607 hdd_notice("Disabling queues for adapter type: %d",
4608 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304609
4610 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004611 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304612 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004613 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304614
Arun Khandavallicc544b32017-01-30 19:52:16 +05304615 if (hdd_ctx->config->sap_internal_restart &&
4616 adapter->device_mode == QDF_SAP_MODE) {
4617 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304618 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304619 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004620 if (test_bit(SOFTAP_BSS_STARTED,
4621 &adapter->event_flags)) {
4622 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004623 hdd_sap_destroy_events(adapter);
4624 }
4625 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4626 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304627 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304628 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004629 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004630 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004631
Paul Zhang84fa9382017-11-10 21:18:21 +08004632 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07004633 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004634
4635 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004636 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004637 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004638 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4639 hdd_wmm_adapter_close(adapter);
4640 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4641 }
4642
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304643 if (adapter->device_mode == QDF_STA_MODE)
4644 hdd_clear_fils_connection_info(adapter);
4645
Wu Gao3545e642017-07-14 19:24:41 +08004646 if (adapter->device_mode == QDF_SAP_MODE) {
4647 /*
4648 * If adapter is SAP, set session ID to invalid
4649 * since SAP session will be cleanup during SSR.
4650 */
Wu Gao36717432016-11-21 15:09:48 +08004651 wlansap_set_invalid_session(
4652 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4653
Wu Gao3545e642017-07-14 19:24:41 +08004654 wlansap_cleanup_cac_timer(
4655 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4656 }
4657
Yue Mad5b4b9f2017-05-26 16:23:40 -07004658 /* Delete peers if any for STA and P2P client modes */
4659 if (adapter->device_mode == QDF_STA_MODE ||
4660 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004661 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004662 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004663 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004664
4665 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4666 peerMacAddr.bytes);
4667 }
4668
Yue Maf9782842017-05-08 12:49:49 -07004669 /* Destroy vdev which will be recreated during reinit. */
4670 hdd_vdev_destroy(adapter);
4671
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004672 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4673 adapterNode = pNext;
4674 }
4675
4676 EXIT();
4677
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304678 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004679}
4680
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004681bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304682{
4683 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4684 QDF_STATUS status;
4685 bool close_modules = true;
4686
Arun Khandavalliba479c42017-07-26 21:29:40 +05304687 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4688 hdd_info("FTM mode, don't close the module");
4689 return false;
4690 }
4691
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304692 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4693 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4694 if (test_bit(DEVICE_IFACE_OPENED,
Yeshwanth Sriram Guntuka4ce0a1b2017-10-17 17:55:45 +05304695 &adapter_node->adapter->event_flags) ||
4696 test_bit(SME_SESSION_OPENED,
4697 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004698 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304699 close_modules = false;
4700 break;
4701 }
4702 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4703 adapter_node = next;
4704 }
4705
4706 return close_modules;
4707}
4708
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304709bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304710{
4711 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4712 return true;
4713 else
4714 return false;
4715}
4716
Anurag Chouhanc4092922016-09-08 15:56:11 +05304717#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004718 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304719struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4720 struct ieee80211_channel *channel,
4721 const u8 *bssid, const u8 *ssid,
4722 size_t ssid_len)
4723{
4724 return cfg80211_get_bss(wiphy, channel, bssid,
4725 ssid, ssid_len,
4726 WLAN_CAPABILITY_ESS,
4727 WLAN_CAPABILITY_ESS);
4728}
4729#else
4730struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4731 struct ieee80211_channel *channel,
4732 const u8 *bssid, const u8 *ssid,
4733 size_t ssid_len)
4734{
4735 return cfg80211_get_bss(wiphy, channel, bssid,
4736 ssid, ssid_len,
4737 IEEE80211_BSS_TYPE_ESS,
4738 IEEE80211_PRIVACY_ANY);
4739}
4740#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304741
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304742#if defined CFG80211_CONNECT_BSS || \
4743 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304744#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304745 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304746/**
4747 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4748 * @timeout_reason: reason for connect timeout
4749 *
4750 * This function is used to convert host timeout
4751 * reason enum to kernel specific enum.
4752 *
4753 * Return: nl timeout enum
4754 */
4755static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4756 tSirResultCodes timeout_reason)
4757{
4758 switch (timeout_reason) {
4759 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4760 return NL80211_TIMEOUT_SCAN;
4761 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4762 return NL80211_TIMEOUT_AUTH;
4763 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4764 return NL80211_TIMEOUT_ASSOC;
4765 default:
4766 return NL80211_TIMEOUT_UNSPECIFIED;
4767 }
4768}
4769
4770/**
4771 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4772 * @dev: network device
4773 * @bssid: bssid to which we want to associate
4774 * @timeout_reason: reason for connect timeout
4775 *
4776 * This API is used to send connection timeout reason to supplicant
4777 *
4778 * Return: void
4779 */
4780static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4781 const u8 *bssid,
4782 tSirResultCodes timeout_reason)
4783{
4784 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004785
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304786 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4787
4788 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4789 nl_timeout_reason);
4790}
4791
4792/**
4793 * __hdd_connect_bss() - API to send connection status to supplicant
4794 * @dev: network device
4795 * @bssid: bssid to which we want to associate
4796 * @req_ie: Request Information Element
4797 * @req_ie_len: len of the req IE
4798 * @resp_ie: Response IE
4799 * @resp_ie_len: len of ht response IE
4800 * @status: status
4801 * @gfp: Kernel Flag
4802 * @timeout_reason: reason for connect timeout
4803 *
4804 * Return: void
4805 */
4806static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4807 struct cfg80211_bss *bss, const u8 *req_ie,
4808 size_t req_ie_len, const u8 *resp_ie,
4809 size_t resp_ie_len, int status, gfp_t gfp,
4810 tSirResultCodes timeout_reason)
4811{
4812 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004813
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304814 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4815
4816 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4817 resp_ie, resp_ie_len, status, gfp,
4818 nl_timeout_reason);
4819}
4820#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304821#if defined CFG80211_CONNECT_TIMEOUT || \
4822 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304823static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4824 const u8 *bssid,
4825 tSirResultCodes timeout_reason)
4826{
4827 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4828}
4829#endif
4830
4831static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4832 struct cfg80211_bss *bss, const u8 *req_ie,
4833 size_t req_ie_len, const u8 *resp_ie,
4834 size_t resp_ie_len, int status, gfp_t gfp,
4835 tSirResultCodes timeout_reason)
4836{
4837 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4838 resp_ie, resp_ie_len, status, gfp);
4839}
4840#endif
4841
Abhishek Singha84d3952016-09-13 13:45:05 +05304842/**
4843 * hdd_connect_bss() - API to send connection status to supplicant
4844 * @dev: network device
4845 * @bssid: bssid to which we want to associate
4846 * @req_ie: Request Information Element
4847 * @req_ie_len: len of the req IE
4848 * @resp_ie: Response IE
4849 * @resp_ie_len: len of ht response IE
4850 * @status: status
4851 * @gfp: Kernel Flag
4852 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304853 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304854 *
4855 * The API is a wrapper to send connection status to supplicant
4856 *
4857 * Return: Void
4858 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304859#if defined CFG80211_CONNECT_TIMEOUT || \
4860 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05304861static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4862 struct cfg80211_bss *bss, const u8 *req_ie,
4863 size_t req_ie_len, const u8 *resp_ie,
4864 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304865 bool connect_timeout,
4866 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304867{
4868 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304869 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304870 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304871 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4872 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304873}
4874#else
4875static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4876 struct cfg80211_bss *bss, const u8 *req_ie,
4877 size_t req_ie_len, const u8 *resp_ie,
4878 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304879 bool connect_timeout,
4880 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304881{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304882 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4883 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304884}
4885#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304886
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304887#if defined(WLAN_FEATURE_FILS_SK)
4888#if defined(CFG80211_CONNECT_DONE) || \
4889 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
4890#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
4891 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304892/**
4893 * hdd_populate_fils_params() - Populate FILS keys to connect response
4894 * @fils_params: connect response to supplicant
4895 * @fils_kek: FILS kek
4896 * @fils_kek_len: FILS kek length
4897 * @pmk: FILS PMK
4898 * @pmk_len: FILS PMK length
4899 * @pmkid: PMKID
4900 * @fils_seq_num: FILS Seq number
4901 *
4902 * Return: None
4903 */
4904static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4905 *fils_params, const uint8_t *fils_kek,
4906 size_t fils_kek_len, const uint8_t *pmk,
4907 size_t pmk_len, const uint8_t *pmkid,
4908 uint16_t fils_seq_num)
4909{
4910 /* Increament seq number to be used for next FILS */
4911 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4912 fils_params->update_erp_next_seq_num = true;
4913 fils_params->fils_kek = fils_kek;
4914 fils_params->fils_kek_len = fils_kek_len;
4915 fils_params->pmk = pmk;
4916 fils_params->pmk_len = pmk_len;
4917 fils_params->pmkid = pmkid;
4918}
4919#else
4920static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4921 *fils_params, const uint8_t
4922 *fils_kek, size_t fils_kek_len,
4923 const uint8_t *pmk, size_t pmk_len,
4924 const uint8_t *pmkid,
4925 uint16_t fils_seq_num)
4926{ }
4927#endif
4928
Jeff Johnson172237b2017-11-07 15:32:59 -08004929void hdd_update_hlp_info(struct net_device *dev,
4930 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304931{
4932 struct sk_buff *skb;
4933 uint16_t skb_len;
4934 struct llc_snap_hdr_t *llc_hdr;
4935 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304936 uint8_t *hlp_data;
4937 uint16_t hlp_data_len;
4938 struct fils_join_rsp_params *roam_fils_params
4939 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304940 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
4941
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304942 if (!roam_fils_params) {
4943 hdd_err("FILS Roam Param NULL");
4944 return;
4945 }
4946
4947 if (!roam_fils_params->hlp_data_len || !roam_fils_params->hlp_data) {
4948 hdd_err("FILS HLP Data NULL, len %d",
4949 roam_fils_params->hlp_data_len);
4950 return;
4951 }
4952
4953 hlp_data = roam_fils_params->hlp_data;
4954 hlp_data_len = roam_fils_params->hlp_data_len;
4955
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304956 /* Calculate skb length */
4957 skb_len = (2 * ETH_ALEN) + hlp_data_len;
4958 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
4959 if (skb == NULL) {
4960 hdd_err("HLP packet nbuf alloc fails");
4961 return;
4962 }
4963
4964 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
4965 QDF_MAC_ADDR_SIZE);
4966 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
4967 QDF_MAC_ADDR_SIZE);
4968
4969 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
4970 if (IS_SNAP(llc_hdr)) {
4971 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4972 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4973 }
4974
4975 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
4976
4977 /*
4978 * This HLP packet is formed from HLP info encapsulated
4979 * in assoc response frame which is AEAD encrypted.
4980 * Hence, this checksum validation can be set unnecessary.
4981 * i.e. network layer need not worry about checksum.
4982 */
4983 skb->ip_summed = CHECKSUM_UNNECESSARY;
4984
4985 status = hdd_rx_packet_cbk(padapter, skb);
4986 if (QDF_IS_STATUS_ERROR(status)) {
4987 hdd_err("Sending HLP packet fails");
4988 return;
4989 }
4990 hdd_debug("send HLP packet to netif successfully");
4991}
4992
4993/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304994 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4995 * @dev: network device
4996 * @bssid: bssid to which we want to associate
4997 * @bss: cfg80211 bss info
4998 * @roam_info: information about connected bss
4999 * @req_ie: Request Information Element
5000 * @req_ie_len: len of the req IE
5001 * @resp_ie: Response IE
5002 * @resp_ie_len: len of ht response IE
5003 * @status: status
5004 * @gfp: allocation flags
5005 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5006 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305007 *
5008 * This API is used as wrapper to send FILS key/sequence number
5009 * params etc. to supplicant in case of FILS connection
5010 *
5011 * Return: None
5012 */
5013static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005014 struct cfg80211_bss *bss,
5015 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305016 const u8 *req_ie, size_t req_ie_len,
5017 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005018 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305019 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305020{
5021 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305022 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5023 struct fils_join_rsp_params *roam_fils_params =
5024 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005025
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305026 qdf_mem_zero(&fils_params, sizeof(fils_params));
5027
5028 if (!roam_fils_params) {
5029 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5030 } else {
5031 fils_params.status = status;
5032 fils_params.bssid = bssid;
5033 fils_params.timeout_reason = timeout_reason;
5034 fils_params.req_ie = req_ie;
5035 fils_params.req_ie_len = req_ie_len;
5036 fils_params.resp_ie = resp_ie;
5037 fils_params.resp_ie_len = resp_ie_len;
5038 fils_params.bss = bss;
5039 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5040 roam_fils_params->kek_len,
5041 roam_fils_params->fils_pmk,
5042 roam_fils_params->fils_pmk_len,
5043 roam_fils_params->fils_pmkid,
5044 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305045 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305046 }
5047 hdd_debug("FILS indicate connect status %d seq no %d",
5048 fils_params.status,
5049 fils_params.fils_erp_next_seq_num);
5050
5051 cfg80211_connect_done(dev, &fils_params, gfp);
5052
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305053 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305054 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305055
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305056 /* Clear all the FILS key info */
5057 if (roam_fils_params && roam_fils_params->fils_pmk)
5058 qdf_mem_free(roam_fils_params->fils_pmk);
5059 if (roam_fils_params)
5060 qdf_mem_free(roam_fils_params);
5061 roam_info->fils_join_rsp = NULL;
5062}
5063#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005064static inline void
5065hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005066 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005067 const u8 *req_ie, size_t req_ie_len,
5068 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5069 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305070 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305071{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305072#endif
5073#endif
5074
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305075#if defined(WLAN_FEATURE_FILS_SK) && \
5076 (defined(CFG80211_CONNECT_DONE) || \
5077 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305078/**
5079 * hdd_fils_update_connect_results() - API to send fils connection status to
5080 * supplicant.
5081 * @dev: network device
5082 * @bssid: bssid to which we want to associate
5083 * @bss: cfg80211 bss info
5084 * @roam_info: information about connected bss
5085 * @req_ie: Request Information Element
5086 * @req_ie_len: len of the req IE
5087 * @resp_ie: Response IE
5088 * @resp_ie_len: len of ht response IE
5089 * @status: status
5090 * @gfp: allocation flags
5091 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5092 * @timeout_reason: reason for connect timeout
5093 *
5094 * The API is a wrapper to send connection status to supplicant
5095 *
5096 * Return: 0 if success else failure
5097 */
5098static int hdd_fils_update_connect_results(struct net_device *dev,
5099 const u8 *bssid,
5100 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005101 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305102 size_t req_ie_len, const u8 *resp_ie,
5103 size_t resp_ie_len, u16 status, gfp_t gfp,
5104 bool connect_timeout,
5105 tSirResultCodes timeout_reason)
5106{
5107 ENTER();
5108 if (!roam_info || !roam_info->is_fils_connection)
5109 return -EINVAL;
5110
5111 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5112 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305113 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305114 return 0;
5115}
5116#else
5117static inline int hdd_fils_update_connect_results(struct net_device *dev,
5118 const u8 *bssid,
5119 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005120 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305121 size_t req_ie_len, const u8 *resp_ie,
5122 size_t resp_ie_len, u16 status, gfp_t gfp,
5123 bool connect_timeout,
5124 tSirResultCodes timeout_reason)
5125{
5126 return -EINVAL;
5127}
5128#endif
5129
Anurag Chouhanc4092922016-09-08 15:56:11 +05305130/**
5131 * hdd_connect_result() - API to send connection status to supplicant
5132 * @dev: network device
5133 * @bssid: bssid to which we want to associate
5134 * @roam_info: information about connected bss
5135 * @req_ie: Request Information Element
5136 * @req_ie_len: len of the req IE
5137 * @resp_ie: Response IE
5138 * @resp_ie_len: len of ht response IE
5139 * @status: status
5140 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305141 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305142 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305143 *
5144 * The API is a wrapper to send connection status to supplicant
5145 * and allow runtime suspend
5146 *
5147 * Return: Void
5148 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305149void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005150 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305151 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305152 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305153 bool connect_timeout,
5154 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305155{
Jeff Johnson9d295242017-08-29 14:39:48 -07005156 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305157 struct cfg80211_bss *bss = NULL;
5158
5159 if (WLAN_STATUS_SUCCESS == status) {
5160 struct ieee80211_channel *chan;
5161 int freq;
5162 int chan_no = roam_info->pBssDesc->channelId;
5163
5164 if (chan_no <= 14)
5165 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005166 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305167 else
5168 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005169 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305170
5171 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5172 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5173 roam_info->u.pConnectedProfile->SSID.ssId,
5174 roam_info->u.pConnectedProfile->SSID.length);
5175 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305176
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305177 if (hdd_fils_update_connect_results(dev, bssid, bss,
5178 roam_info, req_ie, req_ie_len, resp_ie,
5179 resp_ie_len, status, gfp, connect_timeout,
5180 timeout_reason) != 0) {
5181 hdd_connect_bss(dev, bssid, bss, req_ie,
5182 req_ie_len, resp_ie, resp_ie_len,
5183 status, gfp, connect_timeout, timeout_reason);
5184 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305185
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005186 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005187 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305188}
5189#else
5190void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005191 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305192 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305193 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305194 bool connect_timeout,
5195 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305196{
Jeff Johnson9d295242017-08-29 14:39:48 -07005197 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305198
Anurag Chouhanc4092922016-09-08 15:56:11 +05305199 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5200 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005201
5202 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005203 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305204}
5205#endif
5206
5207
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005208QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209{
5210 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305211 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005212 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005213#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305214 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005215#endif
5216 eConnectionState connState;
5217
5218 ENTER();
5219
5220 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305221 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005222 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223
Arun Khandavallifae92942016-08-01 13:31:08 +05305224 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305225 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005227 hdd_wmm_init(adapter);
5228
5229 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005230 case QDF_STA_MODE:
5231 case QDF_P2P_CLIENT_MODE:
5232 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233
5234 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5235 ->conn_info.connState;
5236
5237 hdd_init_station_mode(adapter);
5238 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005239 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005241 /* Indicate disconnect event to supplicant
5242 * if associated previously
5243 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005245 eConnectionState_IbssConnected == connState ||
5246 eConnectionState_NotConnected == connState ||
5247 eConnectionState_IbssDisconnected == connState ||
5248 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005250
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005251 memset(&wrqu, '\0', sizeof(wrqu));
5252 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5253 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5254 wireless_send_event(adapter->dev, SIOCGIWAP,
5255 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005256 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005257 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005258
5259 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305260 wlan_hdd_cfg80211_indicate_disconnect(
5261 adapter->dev, false,
5262 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005263 } else if (eConnectionState_Connecting == connState) {
5264 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005265 * Indicate connect failure to supplicant if we
5266 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005267 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305268 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305269 NULL, 0, NULL, 0,
5270 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005271 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005272 }
5273
5274 hdd_register_tx_flow_control(adapter,
5275 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005276 hdd_tx_resume_cb,
5277 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005278
5279 break;
5280
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005281 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005282 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305283 hdd_init_ap_mode(adapter, true);
5284
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005285 break;
5286
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005287 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005288#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005289 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005290 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5291#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005292 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005293 /* event supplicant to restart */
5294 cfg80211_del_sta(adapter->dev,
5295 (const u8 *)&bcastMac.bytes[0],
5296 GFP_KERNEL);
5297#endif
5298 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305299 case QDF_MONITOR_MODE:
5300 hdd_init_station_mode(adapter);
5301 hdd_set_mon_rx_cb(adapter->dev);
5302 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5303 adapter->mon_bandwidth);
5304 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305 default:
5306 break;
5307 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005308 /*
5309 * Action frame registered in one adapter which will
5310 * applicable to all interfaces
5311 */
5312 wlan_hdd_cfg80211_register_frames(adapter);
5313
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305314get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005315 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5316 adapterNode = pNext;
5317 }
5318
5319 EXIT();
5320
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305321 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322}
5323
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005324QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005325 hdd_adapter_list_node_t **padapterNode)
5326{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305327 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005328
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005329 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005330 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305331 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005332 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005333 return status;
5334}
5335
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005336QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005337 hdd_adapter_list_node_t *adapterNode,
5338 hdd_adapter_list_node_t **pNextAdapterNode)
5339{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305340 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005341
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005342 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005343 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305344 (qdf_list_node_t *) adapterNode,
5345 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005346
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005347 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005348 return status;
5349}
5350
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005351QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005352 hdd_adapter_list_node_t *adapterNode)
5353{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305354 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005355
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005356 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005357 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005358 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005359 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005360 return status;
5361}
5362
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005363QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005364 hdd_adapter_list_node_t **padapterNode)
5365{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305366 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005367
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005368 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005369 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305370 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005371 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005372 return status;
5373}
5374
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005375QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005376 hdd_adapter_list_node_t *adapterNode)
5377{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305378 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005379
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005380 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005381 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305382 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005383 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005384 return status;
5385}
5386
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005387QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005388 hdd_adapter_list_node_t *adapterNode)
5389{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305390 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005391
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005392 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005393 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305394 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005395 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005396 return status;
5397}
5398
Jeff Johnson9d295242017-08-29 14:39:48 -07005399struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005400 tSirMacAddr macAddr)
5401{
5402 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005403 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305404 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005405
5406 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5407
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305408 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005409 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005410
5411 if (adapter
Jeff Johnson1e851a12017-10-28 14:36:12 -07005412 && !qdf_mem_cmp(adapter->mac_addr.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005413 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005414 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005416 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5417 adapterNode = pNext;
5418 }
5419
5420 return NULL;
5421
5422}
5423
Jeff Johnson9d295242017-08-29 14:39:48 -07005424struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005425 uint32_t vdev_id)
5426{
5427 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005428 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305429 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005430
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305431 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305433 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005434 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005435
Jeff Johnson1b780e42017-10-31 14:11:45 -07005436 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005437 return adapter;
5438
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305439 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005440 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5441 adapterNode = pNext;
5442 }
5443
Jeff Johnson5880d792016-08-15 13:32:30 -07005444 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005445
5446 return NULL;
5447}
5448
Abhishek Singh7996eb72015-12-30 17:24:02 +05305449/**
5450 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5451 * the sessionid
5452 * @hdd_ctx: hdd context.
5453 * @sme_session_id: sme session is for the adapter to get.
5454 *
5455 * This function is used to get the adapter with provided session id
5456 *
5457 * Return: adapter pointer if found
5458 *
5459 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005460struct hdd_adapter *
5461hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5462 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305463{
5464 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005465 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305466 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305467
5468
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305469 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305470
5471 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305472 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005473 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305474
5475 if (adapter &&
Jeff Johnson1b780e42017-10-31 14:11:45 -07005476 adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305477 return adapter;
5478
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305479 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305480 hdd_get_next_adapter(hdd_ctx,
5481 adapter_node, &next);
5482 adapter_node = next;
5483 }
5484 return NULL;
5485}
5486
Jeff Johnson9d295242017-08-29 14:39:48 -07005487struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005488 const char *iface_name)
5489{
5490 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005491 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005492 QDF_STATUS qdf_status;
5493
5494 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5495
5496 while ((NULL != adapter_node) &&
5497 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005498 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005499
5500 if (adapter &&
5501 !qdf_str_cmp(adapter->dev->name, iface_name))
5502 return adapter;
5503
5504 qdf_status =
5505 hdd_get_next_adapter(hdd_ctx,
5506 adapter_node, &next);
5507 adapter_node = next;
5508 }
5509 return NULL;
5510}
5511
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005512/**
5513 * hdd_get_adapter() - to get adapter matching the mode
5514 * @hdd_ctx: hdd context
5515 * @mode: adapter mode
5516 *
5517 * This routine will return the pointer to adapter matching
5518 * with the passed mode.
5519 *
5520 * Return: pointer to adapter or null
5521 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005522struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005523 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005524{
5525 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005526 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305527 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005528
5529 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5530
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305531 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005532 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005533
5534 if (adapter && (mode == adapter->device_mode))
5535 return adapter;
5536
5537 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5538 adapterNode = pNext;
5539 }
5540
5541 return NULL;
5542
5543}
5544
5545/**
5546 * hdd_get_operating_channel() - return operating channel of the device mode
5547 * @hdd_ctx: Pointer to the HDD context.
5548 * @mode: Device mode for which operating channel is required.
5549 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005550 * QDF_STA_MODE,
5551 * QDF_P2P_CLIENT_MODE,
5552 * QDF_SAP_MODE,
5553 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005554 *
5555 * This API returns the operating channel of the requested device mode
5556 *
5557 * Return: channel number. "0" id the requested device is not found OR it is
5558 * not connected.
5559 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005560uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005561 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005562{
5563 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305564 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005565 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005566 uint8_t operatingChannel = 0;
5567
5568 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5569
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305570 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005571 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005572
5573 if (mode == adapter->device_mode) {
5574 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005575 case QDF_STA_MODE:
5576 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005577 if (hdd_conn_is_connected
5578 (WLAN_HDD_GET_STATION_CTX_PTR
5579 (adapter))) {
5580 operatingChannel =
5581 (WLAN_HDD_GET_STATION_CTX_PTR
5582 (adapter))->conn_info.
5583 operationChannel;
5584 }
5585 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005586 case QDF_SAP_MODE:
5587 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005588 /* softap connection info */
5589 if (test_bit
5590 (SOFTAP_BSS_STARTED,
5591 &adapter->event_flags))
5592 operatingChannel =
5593 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005594 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005595 break;
5596 default:
5597 break;
5598 }
5599
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005600 /* Found the device of interest. break the loop */
5601 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005602 }
5603
5604 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5605 adapterNode = pNext;
5606 }
5607 return operatingChannel;
5608}
5609
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005610static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005611 hdd_ctx)
5612{
5613 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305614 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005615 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005616
5617 ENTER();
5618
5619 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5620
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305621 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005622 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005623 if ((adapter->device_mode == QDF_STA_MODE) ||
5624 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5625 (adapter->device_mode == QDF_IBSS_MODE) ||
5626 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5627 (adapter->device_mode == QDF_SAP_MODE) ||
5628 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005629 wlan_hdd_cfg80211_deregister_frames(adapter);
5630 hdd_unregister_wext(adapter->dev);
5631 }
5632 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5633 adapterNode = pNext;
5634 }
5635
5636 EXIT();
5637
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305638 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005639}
5640
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005641QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005642{
5643 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305644 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005645 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005646
5647 ENTER();
5648
5649 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5650
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305651 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005652 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005653 if ((adapter->device_mode == QDF_STA_MODE) ||
5654 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5655 (adapter->device_mode == QDF_IBSS_MODE) ||
5656 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5657 (adapter->device_mode == QDF_SAP_MODE) ||
5658 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005659 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005660 adapter->session_id, INVALID_SCAN_ID,
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005661 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005662 }
5663 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5664 adapterNode = pNext;
5665 }
5666
5667 EXIT();
5668
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305669 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005670}
5671
Dustin Brownf27bce82016-11-03 12:52:27 -07005672/**
5673 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5674 * adapters
5675 * @hdd_ctx: The HDD context containing the adapters to operate on
5676 *
5677 * return: QDF_STATUS_SUCCESS
5678 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005679static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005680{
5681 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5682 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005683 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005684 int err;
5685
5686 ENTER();
5687
5688 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5689
5690 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005691 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005692 if ((adapter->device_mode == QDF_STA_MODE) ||
5693 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5694 (adapter->device_mode == QDF_IBSS_MODE) ||
5695 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5696 (adapter->device_mode == QDF_SAP_MODE) ||
5697 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5698 err = wlan_hdd_sched_scan_stop(adapter->dev);
5699 if (err)
5700 hdd_err("Unable to stop scheduled scan");
5701 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005702 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5703 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005704 adapter_node = next_node;
5705 }
5706
5707 EXIT();
5708
5709 return QDF_STATUS_SUCCESS;
5710}
5711
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005712#ifdef WLAN_NS_OFFLOAD
5713/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005714 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715 * @hdd_ctx: Pointer to hdd context
5716 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005717 * Unregister for IPv6 address change notifications.
5718 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005719 * Return: None
5720 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005721static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005722{
5723 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005724}
5725
5726/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005727 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005728 * @hdd_ctx: Pointer to hdd context
5729 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005730 * Register for IPv6 address change notifications.
5731 *
5732 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005733 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005734static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005735{
5736 int ret;
5737
5738 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5739 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005740 if (ret) {
5741 hdd_err("Failed to register IPv6 notifier: %d", ret);
5742 goto out;
5743 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005744
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005745 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005746out:
5747 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005748}
5749#else
5750/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005751 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005752 * @hdd_ctx: Pointer to hdd context
5753 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005754 * Unregister for IPv6 address change notifications.
5755 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005756 * Return: None
5757 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005758static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005759{
5760}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005761
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005762/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005763 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005764 * @hdd_ctx: Pointer to hdd context
5765 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005766 * Register for IPv6 address change notifications.
5767 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005768 * Return: None
5769 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005770static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005771{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005772 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005773}
5774#endif
5775
5776/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005777 * hdd_register_notifiers - Register netdev notifiers.
5778 * @hdd_ctx: HDD context
5779 *
5780 * Register netdev notifiers like IPv4 and IPv6.
5781 *
5782 * Return: 0 on success and errno on failure
5783 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005784static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005785{
5786 int ret;
5787
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005788 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5789 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305790 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005791
5792 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5793 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5794 if (ret) {
5795 hdd_err("Failed to register IPv4 notifier: %d", ret);
5796 goto unregister_ip6_notifier;
5797 }
5798
5799 return 0;
5800
5801unregister_ip6_notifier:
5802 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005803out:
5804 return ret;
5805
5806}
5807
5808/**
5809 * hdd_unregister_notifiers - Unregister netdev notifiers.
5810 * @hdd_ctx: HDD context
5811 *
5812 * Unregister netdev notifiers like IPv4 and IPv6.
5813 *
5814 * Return: None.
5815 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005816void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005817{
5818 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5819
5820 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005821}
5822
5823/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005824 * hdd_exit_netlink_services - Exit netlink services
5825 * @hdd_ctx: HDD context
5826 *
5827 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5828 * nl service.
5829 *
5830 * Return: None.
5831 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005832static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005833{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005834 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005835 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005836 ptt_sock_deactivate_svc();
5837
5838 nl_srv_exit();
5839}
5840
5841/**
5842 * hdd_init_netlink_services- Init netlink services
5843 * @hdd_ctx: HDD context
5844 *
5845 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5846 * nl service.
5847 *
5848 * Return: 0 on success and errno on failure.
5849 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005850static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005851{
5852 int ret;
5853
Ryan Hsuceddceb2016-04-28 10:20:14 -07005854 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005855 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005856 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005857 goto out;
5858 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005859 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005860
Naveen Rawat910726a2017-03-06 11:42:51 -08005861 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005862 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005863 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005864 goto err_nl_srv;
5865 }
5866
5867 ret = ptt_sock_activate_svc();
5868 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005869 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005870 goto err_nl_srv;
5871 }
5872
5873 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005874 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005875 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005876
5877 ret = cnss_diag_activate_service();
5878 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005879 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005880 goto err_close_cesium;
5881 }
5882
5883 return 0;
5884
5885err_close_cesium:
5886 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005887 ptt_sock_deactivate_svc();
5888err_nl_srv:
5889 nl_srv_exit();
5890out:
5891 return ret;
5892}
5893
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005894/**
5895 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5896 * @hdd_ctx: HDD context.
5897 *
5898 * Destroy RX wakelock.
5899 *
5900 * Return: None.
5901 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005902static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005903{
5904 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5905}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005906
5907/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005908 * hdd_rx_wake_lock_create() - Create RX wakelock
5909 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005910 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005911 * Create RX wakelock.
5912 *
5913 * Return: None.
5914 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005915static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005916{
5917 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5918}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005919
5920/**
Houston Hoffman160db392016-10-10 17:37:51 -07005921 * hdd_context_deinit() - Deinitialize HDD context
5922 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005923 *
Houston Hoffman160db392016-10-10 17:37:51 -07005924 * Deinitialize HDD context along with all the feature specific contexts but
5925 * do not free hdd context itself. Caller of this API is supposed to free
5926 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005927 *
Houston Hoffman160db392016-10-10 17:37:51 -07005928 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005929 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005930static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005931{
Houston Hoffman160db392016-10-10 17:37:51 -07005932 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005933
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005934 hdd_sap_context_destroy(hdd_ctx);
5935
5936 hdd_rx_wake_lock_destroy(hdd_ctx);
5937
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005938 hdd_scan_context_destroy(hdd_ctx);
5939
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005940 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005941
Houston Hoffman160db392016-10-10 17:37:51 -07005942 return 0;
5943}
5944
5945/**
5946 * hdd_context_destroy() - Destroy HDD context
5947 * @hdd_ctx: HDD context to be destroyed.
5948 *
5949 * Free config and HDD context as well as destroy all the resources.
5950 *
5951 * Return: None
5952 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005953static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005954{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005955 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305956
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305957 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5958
Houston Hoffman160db392016-10-10 17:37:51 -07005959 hdd_context_deinit(hdd_ctx);
5960
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305961 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005962 hdd_ctx->config = NULL;
5963
5964 wiphy_free(hdd_ctx->wiphy);
5965}
5966
5967/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305968 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5969 *
5970 * This function is used to destroy bug report lock
5971 *
5972 * Return: None
5973 */
5974static void wlan_destroy_bug_report_lock(void)
5975{
5976 p_cds_contextType p_cds_context;
5977
5978 p_cds_context = cds_get_global_context();
5979 if (!p_cds_context) {
5980 hdd_err("cds context is NULL");
5981 return;
5982 }
5983
5984 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5985}
5986
5987/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005988 * hdd_wlan_exit() - HDD WLAN exit function
5989 * @hdd_ctx: Pointer to the HDD Context
5990 *
5991 * This is the driver exit point (invoked during rmmod)
5992 *
5993 * Return: None
5994 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005995static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005996{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005997 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305998 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005999
6000 ENTER();
6001
Dustin Brown6f427922017-09-19 12:19:00 -07006002 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306003
6004 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006005
Prashanth Bhattaab004382016-10-11 16:08:11 -07006006 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006007
6008#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306009 if (QDF_TIMER_STATE_RUNNING ==
6010 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6011 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006012 }
6013
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306014 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306015 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006016 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006017 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006018 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6019 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6020 hdd_ctx->last_acs_channel_list = NULL;
6021 hdd_ctx->num_of_channels = 0;
6022 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006023#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006024
Arun Khandavallifae92942016-08-01 13:31:08 +05306025 mutex_lock(&hdd_ctx->iface_change_lock);
6026 driver_status = hdd_ctx->driver_status;
6027 mutex_unlock(&hdd_ctx->iface_change_lock);
6028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006029 /*
6030 * Powersave Offload Case
6031 * Disable Idle Power Save Mode
6032 */
6033 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006034 /* clear the scan queue in all the scenarios */
6035 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006036
Arun Khandavallifae92942016-08-01 13:31:08 +05306037 if (driver_status != DRIVER_MODULES_CLOSED) {
6038 hdd_unregister_wext_all_adapters(hdd_ctx);
6039 /*
6040 * Cancel any outstanding scan requests. We are about to close
6041 * all of our adapters, but an adapter structure is what SME
6042 * passes back to our callback function. Hence if there
6043 * are any outstanding scan requests then there is a
6044 * race condition between when the adapter is closed and
6045 * when the callback is invoked. We try to resolve that
6046 * race condition here by canceling any outstanding scans
6047 * before we close the adapters.
6048 * Note that the scans may be cancelled in an asynchronous
6049 * manner, so ideally there needs to be some kind of
6050 * synchronization. Rather than introduce a new
6051 * synchronization here, we will utilize the fact that we are
6052 * about to Request Full Power, and since that is synchronized,
6053 * the expectation is that by the time Request Full Power has
6054 * completed, all scans will be cancelled
6055 */
6056 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006057 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006058 hdd_stop_all_adapters(hdd_ctx, true);
bings29c99862017-11-01 13:54:13 +08006059 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006060 }
6061
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306062 unregister_netdevice_notifier(&hdd_netdev_notifier);
6063
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006064 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306065
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306066 qdf_nbuf_deinit_replenish_timer();
6067
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306068 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6069 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6070 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6071
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006072 /*
6073 * Close CDS
6074 * This frees pMac(HAL) context. There should not be any call
6075 * that requires pMac access after this.
6076 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006077
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006078 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006079 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006080
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006081 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006082
6083 hdd_ipa_cleanup(hdd_ctx);
6084
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306085 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306086 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306087 /*
6088 * If there is re_init failure wiphy would have already de-registered
6089 * check the wiphy status before un-registering again
6090 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306091 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306092 wiphy_unregister(wiphy);
6093 wlan_hdd_cfg80211_deinit(wiphy);
6094 hdd_lpass_notify_stop(hdd_ctx);
6095 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006096
Arun Khandavallifae92942016-08-01 13:31:08 +05306097 hdd_exit_netlink_services(hdd_ctx);
6098 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306099#ifdef FEATURE_WLAN_CH_AVOID
6100 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6101#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306102
6103 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6104 if (driver_status)
6105 hdd_err("Pdev delete failed");
6106
6107 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6108 if (driver_status)
6109 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006110
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006111 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006112}
6113
6114void __hdd_wlan_exit(void)
6115{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006116 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006117
6118 ENTER();
6119
Anurag Chouhan6d760662016-02-20 16:05:43 +05306120 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006121 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006122 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006123 EXIT();
6124 return;
6125 }
6126
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006127 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306128 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006129
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006130 /* Do all the cleanup before deregistering the driver */
6131 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006132
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006133 EXIT();
6134}
6135
6136#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006137/**
6138 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006139 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006140 *
6141 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6142 * Then new ACS request will do a fresh scan without reusing the cached
6143 * scan information.
6144 *
6145 * Return: void
6146 */
Tang Yingying523322d2017-01-17 23:28:43 +08006147static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006148{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006149 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006150
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006151 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006152 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006153 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6154 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6155 hdd_ctx->last_acs_channel_list = NULL;
6156 hdd_ctx->num_of_channels = 0;
6157 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006158
6159 if (!hdd_ctx->hHal)
6160 return;
6161 sme_scan_flush_result(hdd_ctx->hHal);
6162}
6163#endif
6164
6165#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006166int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6167 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006168{
6169 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306170 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006171 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006172
6173 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6174
6175 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
Jeff Johnsone7672e72017-10-21 15:10:04 -07006182 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006183 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306184 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006185 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006186 return -EINVAL;
6187 }
6188
6189 return 0;
6190}
6191#endif
6192
6193/**
6194 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6195 * @state: state
6196 *
6197 * This function notifies FW with modem power status
6198 *
6199 * Return: 0 if successful, error number otherwise
6200 */
6201int hdd_wlan_notify_modem_power_state(int state)
6202{
6203 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306204 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006205 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006206
Anurag Chouhan6d760662016-02-20 16:05:43 +05306207 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006208 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306209 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006210 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306211
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006212 if (!hdd_ctx->hHal)
6213 return -EINVAL;
6214
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306215 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6216 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006217 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006218 state);
6219 return -EINVAL;
6220 }
6221 return 0;
6222}
6223
6224/**
6225 *
6226 * hdd_post_cds_enable_config() - HDD post cds start config helper
6227 * @adapter - Pointer to the HDD
6228 *
6229 * Return: None
6230 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006231QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006232{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306233 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234
6235 /*
6236 * Send ready indication to the HDD. This will kick off the MAC
6237 * into a 'running' state and should kick off an initial scan.
6238 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306239 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6240 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006241 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6242 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306243 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006244 }
6245
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306246 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006247}
6248
6249/* wake lock APIs for HDD */
6250void hdd_prevent_suspend(uint32_t reason)
6251{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306252 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006253}
6254
6255void hdd_allow_suspend(uint32_t reason)
6256{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306257 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006258}
6259
6260void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6261{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306262 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6263 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006264}
6265
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006266/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006267QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006268{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006269
Amar Singhal6f8592b2017-04-26 14:31:58 -07006270 return sme_init_chan_list(hdd_ctx->hHal,
6271 hdd_ctx->reg.alpha2,
6272 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006273}
6274
6275/**
6276 * hdd_is_5g_supported() - check if hardware supports 5GHz
6277 * @hdd_ctx: Pointer to the hdd context
6278 *
6279 * HDD function to know if hardware supports 5GHz
6280 *
6281 * Return: true if hardware supports 5GHz
6282 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006283bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006284{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006285 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006286 return true;
6287
Amar Singhal58b45ef2017-08-01 13:43:54 -07006288 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006289 return true;
6290 else
6291 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006292}
6293
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006294static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006295{
6296 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006297 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006298
6299 wiphy = hdd_ctx->wiphy;
6300
6301 /*
6302 * The channel information in
6303 * wiphy needs to be initialized before wiphy registration
6304 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006305 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6306 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006307 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006308 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006309 }
6310
6311#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6312 wiphy->wowlan = &wowlan_support_reg_init;
6313#else
6314 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6315 WIPHY_WOWLAN_MAGIC_PKT |
6316 WIPHY_WOWLAN_DISCONNECT |
6317 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6318 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6319 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6320 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6321 WIPHY_WOWLAN_RFKILL_RELEASE;
6322
6323 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6324 WOW_MAX_FILTERS_PER_LIST);
6325 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6326 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6327#endif
6328
6329 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006330 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306331 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006332 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306333 return ret_val;
6334 }
6335
Amar Singhal5cccafe2017-02-15 12:42:58 -08006336 if (!hdd_ctx->reg_offload)
6337 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006338
Amar Singhale4f28ee2015-10-21 14:36:56 -07006339 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006340}
6341
Ravi Joshie2331e82015-07-01 18:18:54 -07006342/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006343 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006344 * @hdd_ctx - handle to hdd context
6345 * @tx_packets - transmit packet count
6346 * @rx_packets - receive packet count
6347 *
6348 * The function controls the bus bandwidth and dynamic control of
6349 * tcp delayed ack configuration
6350 *
6351 * Returns: None
6352 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006353#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006354static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006355 const uint64_t tx_packets,
6356 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006357{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006358 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006359 uint64_t temp_rx = 0;
6360 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006361 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006362 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006363 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006364 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006365 uint16_t index = 0;
6366 bool vote_level_change = false;
6367 bool rx_level_change = false;
6368 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006369
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006370 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006371 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006372 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006373 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006374 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006375 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006376 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006377 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006379 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006380 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6381 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006382 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006383 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006384 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306385 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306386 if (hdd_ctx->hbw_requested) {
6387 pld_remove_pm_qos(hdd_ctx->parent_dev);
6388 hdd_ctx->hbw_requested = false;
6389 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306390 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006391 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006392 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306393 if (!hdd_ctx->hbw_requested) {
6394 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6395 hdd_ctx->hbw_requested = true;
6396 }
6397
Nirav Shah3bbfa512016-05-12 16:43:49 +05306398 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006399 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006400 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006401 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006402 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006403
Mohit Khannaf8f96822017-05-17 17:11:59 -07006404 qdf_dp_trace_throttle_live_mode(
6405 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6406
Mohit Khannae71e2262015-11-10 09:37:24 -08006407 /* fine-tuning parameters for RX Flows */
6408 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6409
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006410 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006411
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306412 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6413 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6414 else
6415 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6416
Ravi Joshifed83572016-10-07 16:20:37 -07006417 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6418 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6419 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6420 next_rx_level = WLAN_SVC_TP_HIGH;
6421 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006422 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006423 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006424 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006425 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006427 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006428 struct wlan_rx_tp_data rx_tp_data = {0};
6429
Ravi Joshie2331e82015-07-01 18:18:54 -07006430 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006431 next_rx_level, temp_rx);
6432 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006433 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006434 /* Send throughput indication only if it is enabled.
6435 * Disabling tcp_del_ack will revert the tcp stack behavior
6436 * to default delayed ack. Note that this will disable the
6437 * dynamic delayed ack mechanism across the system
6438 */
6439 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006440 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6441
6442 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6443 rx_tp_data.level = next_rx_level;
6444 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6445 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6446 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006447 }
6448
Mohit Khannae71e2262015-11-10 09:37:24 -08006449 /* fine-tuning parameters for TX Flows */
6450 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6451 hdd_ctx->prev_tx = tx_packets;
6452 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6453 next_tx_level = WLAN_SVC_TP_HIGH;
6454 else
6455 next_tx_level = WLAN_SVC_TP_LOW;
6456
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006457 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006458 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6459 next_tx_level, temp_tx);
6460 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006461 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306462 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6463 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006464 &next_tx_level,
6465 sizeof(next_tx_level));
6466 }
6467
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006468 index = hdd_ctx->hdd_txrx_hist_idx;
6469
6470 if (vote_level_change || tx_level_change || rx_level_change) {
6471 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6472 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6473 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6474 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6475 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6476 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6477 hdd_ctx->hdd_txrx_hist_idx++;
6478 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6479 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006480}
6481
6482#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306483static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006484{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006485 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306486 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006487 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306488 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306489 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6490 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006491 uint64_t total_tx = 0, total_rx = 0;
6492 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306493 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306494 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006495 bool connected = false;
6496 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6497
Prashanth Bhattaab004382016-10-11 16:08:11 -07006498 if (wlan_hdd_validate_context(hdd_ctx))
6499 return;
6500
Jeff Johnson214671b2017-10-30 19:45:23 -07006501 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006502 goto restart_timer;
6503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006504 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306505 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506 status =
6507 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6508
Jeff Johnson57eb2732017-10-02 11:40:20 -07006509 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006510 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006511 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306512 /*
6513 * Validate magic so we don't end up accessing
6514 * an invalid adapter.
6515 */
6516 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6517 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006518
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006519 if ((adapter->device_mode == QDF_STA_MODE ||
6520 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006521 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6522 != eConnectionState_Associated) {
6523
6524 continue;
6525 }
6526
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006527 if ((adapter->device_mode == QDF_SAP_MODE ||
6528 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006529 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006530
6531 continue;
6532 }
6533
6534 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6535 adapter->prev_tx_packets);
6536 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6537 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306538
6539 if (adapter->device_mode == QDF_SAP_MODE ||
6540 adapter->device_mode == QDF_P2P_GO_MODE ||
6541 adapter->device_mode == QDF_IBSS_MODE) {
6542
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006543 ret = cdp_get_intra_bss_fwd_pkts_count(
6544 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006545 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306546 &fwd_tx_packets, &fwd_rx_packets);
6547 if (ret == A_OK) {
6548 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6549 fwd_tx_packets,
6550 adapter->prev_fwd_tx_packets);
6551 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6552 fwd_tx_packets,
6553 adapter->prev_fwd_rx_packets);
6554 }
6555 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006556
6557 total_rx += adapter->stats.rx_packets;
6558 total_tx += adapter->stats.tx_packets;
6559
6560 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6561 adapter->prev_tx_packets = adapter->stats.tx_packets;
6562 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306563 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6564 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006565 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6566 connected = true;
6567 }
6568
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306569 /* add intra bss forwarded tx and rx packets */
6570 tx_packets += fwd_tx_packets_diff;
6571 rx_packets += fwd_rx_packets_diff;
6572
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006573 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6574 tx_packets += (uint64_t)ipa_tx_packets;
6575 rx_packets += (uint64_t)ipa_rx_packets;
6576
Yun Park2aa880c2017-08-22 10:58:10 -07006577 if (adapter) {
6578 adapter->stats.tx_packets += ipa_tx_packets;
6579 adapter->stats.rx_packets += ipa_rx_packets;
6580 }
6581
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006582 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006583 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006584 return;
6585 }
6586
Yuanyuan Liu13738502016-04-06 17:41:37 -07006587 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006588
6589 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6590 hdd_ipa_uc_stat_request(adapter, 2);
6591
Jingxiang Gec64e1932017-08-22 14:38:59 +08006592restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006593 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006594 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006595 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306596 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006597 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006598 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006600
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306601/**
6602 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6603 * @arg: Argument of timer function
6604 *
6605 * Schedule a workqueue in this function where all the processing is done.
6606 *
6607 * Return: None.
6608 */
6609static void __hdd_bus_bw_cbk(void *arg)
6610{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006611 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306612
6613 if (wlan_hdd_validate_context(hdd_ctx))
6614 return;
6615
6616 schedule_work(&hdd_ctx->bus_bw_work);
6617}
6618
6619/**
6620 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6621 * @arg: Argument of timer function
6622 *
6623 * Return: None.
6624 */
6625static void hdd_bus_bw_cbk(void *arg)
6626{
6627 cds_ssr_protect(__func__);
6628 __hdd_bus_bw_cbk(arg);
6629 cds_ssr_unprotect(__func__);
6630}
6631
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006632int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006633{
6634 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306635 INIT_WORK(&hdd_ctx->bus_bw_work,
6636 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006637 hdd_ctx->bus_bw_timer_running = false;
6638 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306639 qdf_timer_init(NULL,
6640 &hdd_ctx->bus_bw_timer,
6641 hdd_bus_bw_cbk, (void *)hdd_ctx,
6642 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006643
6644 return 0;
6645}
6646
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006647void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006648{
Dustin Brownfce08d12017-01-17 16:29:38 -08006649 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006650 hdd_reset_tcp_delack(hdd_ctx);
6651
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006652 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306653 cancel_work_sync(&hdd_ctx->bus_bw_work);
6654 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006655 hdd_ctx->bus_bw_timer_running = false;
6656 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006657}
Lin Baic5c06882017-09-21 13:58:43 +08006658
6659void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6660{
6661 if (hdd_ctx)
6662 cancel_work_sync(&hdd_ctx->bus_bw_work);
6663}
jiadcdaf9bd2017-10-26 12:20:21 +08006664
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006665#endif
6666
6667/**
Nirav Shahed34b212016-04-25 10:59:16 +05306668 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6669 * @hdd_ctx: hdd context
6670 *
6671 * Return: 0 for success or error code
6672 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006673static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306674{
6675 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6676 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6677 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006678 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306679 return -ENOMEM;
6680 }
6681 return 0;
6682}
6683
6684/**
6685 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6686 * @hdd_ctx: hdd context
6687 *
6688 * Return: none
6689 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006690void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306691{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306692 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6693 return;
6694
6695 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6696 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306697}
6698
Nirav Shahda008342016-05-17 18:50:40 +05306699static uint8_t *convert_level_to_string(uint32_t level)
6700{
6701 switch (level) {
6702 /* initialize the wlan sub system */
6703 case WLAN_SVC_TP_NONE:
6704 return "NONE";
6705 case WLAN_SVC_TP_LOW:
6706 return "LOW";
6707 case WLAN_SVC_TP_MEDIUM:
6708 return "MED";
6709 case WLAN_SVC_TP_HIGH:
6710 return "HIGH";
6711 default:
6712 return "INVAL";
6713 }
6714}
6715
Nirav Shahed34b212016-04-25 10:59:16 +05306716
6717/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006718 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6719 * @hdd_ctx: hdd context
6720 *
6721 * Return: none
6722 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006723void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006724{
6725 int i;
6726
6727#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006728 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306729 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006730 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006731 hdd_ctx->config->busBandwidthHighThreshold,
6732 hdd_ctx->config->busBandwidthMediumThreshold,
6733 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006734 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306735 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006736 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006737 hdd_ctx->config->tcpDelackThresholdHigh,
6738 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006739 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306740 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006741#endif
6742
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006743 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306744 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6745
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006746 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006747
6748 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006749 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006750 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006751 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006752 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6753 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006754 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006755 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6756 convert_level_to_string(
6757 hdd_ctx->hdd_txrx_hist[i].
6758 next_vote_level),
6759 convert_level_to_string(
6760 hdd_ctx->hdd_txrx_hist[i].
6761 next_rx_level),
6762 convert_level_to_string(
6763 hdd_ctx->hdd_txrx_hist[i].
6764 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006765 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766}
6767
6768/**
6769 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6770 * @hdd_ctx: hdd context
6771 *
6772 * Return: none
6773 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006774void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775{
6776 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306777 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6778 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779}
6780
6781/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006782 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006783 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006784 *
6785 * Return: none
6786 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006787void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006788{
6789
Jeff Johnson9d295242017-08-29 14:39:48 -07006790 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006791 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306792 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006793 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306794 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006795
6796 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306797 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006798 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006799
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006800 hdd_debug("Netif queue operation statistics:");
6801 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07006802 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006803 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306804 curr_time = qdf_system_ticks();
6805 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306806 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306807 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306808 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306809 unpause = adapter->total_unpause_time;
6810 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306811 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306812 pause = adapter->total_pause_time;
6813 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006814 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306815 qdf_system_ticks_to_msecs(total),
6816 qdf_system_ticks_to_msecs(pause),
6817 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006818 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006819
Nirav Shahda008342016-05-17 18:50:40 +05306820 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6821 qdf_time_t pause_delta = 0;
6822
6823 if (adapter->pause_map & (1 << i))
6824 pause_delta = delta;
6825
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006826 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006827 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006828 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006829 hdd_reason_type_to_string(i),
6830 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306831 adapter->queue_oper_stats[i].unpause_count,
6832 qdf_system_ticks_to_msecs(
6833 adapter->queue_oper_stats[i].total_pause_time +
6834 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006835 }
6836
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006837 hdd_debug("Netif queue operation history:");
6838 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306839 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6840
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006841 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006842
6843 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006844 /* using hdd_log to avoid printing function name */
6845 if (adapter->queue_oper_history[i].time == 0)
6846 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006847 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006848 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306849 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006850 adapter->queue_oper_history[i].time),
6851 hdd_action_type_to_string(
6852 adapter->queue_oper_history[i].netif_action),
6853 hdd_reason_type_to_string(
6854 adapter->queue_oper_history[i].netif_reason),
6855 adapter->queue_oper_history[i].pause_map);
6856 }
6857
6858 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6859 adapter_node = next;
6860 }
6861
6862
6863}
6864
6865/**
6866 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6867 * @hdd_ctx: hdd context
6868 *
6869 * Return: none
6870 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006871void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006872{
Jeff Johnson9d295242017-08-29 14:39:48 -07006873 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006874 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306875 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006876
6877 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306878 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006879 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006880
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306881 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306883 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006884 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306885 adapter->history_index = 0;
6886 adapter->start_time = adapter->last_time = qdf_system_ticks();
6887 adapter->total_pause_time = 0;
6888 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006889 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6890 adapter_node = next;
6891 }
6892}
6893
6894/**
6895 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6896 * @halHandle: Hal handle
6897 * @pContext: Pointer to the context
6898 * @sessionId: Session ID
6899 * @scanId: Scan ID
6900 * @status: Status
6901 *
6902 * This is the callback to be executed when 11d scan is completed to flush out
6903 * the scan results
6904 *
6905 * 11d scan is done during driver load and is a passive scan on all
6906 * channels supported by the device, 11d scans may find some APs on
6907 * frequencies which are forbidden to be used in the regulatory domain
6908 * the device is operating in. If these APs are notified to the supplicant
6909 * it may try to connect to these APs, thus flush out all the scan results
6910 * which are present in SME after 11d scan is done.
6911 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306912 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006913 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306914static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006915 uint8_t sessionId, uint32_t scanId,
6916 eCsrScanStatus status)
6917{
6918 ENTER();
6919
6920 sme_scan_flush_result(halHandle);
6921
6922 EXIT();
6923
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306924 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006925}
6926
6927#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6928/**
6929 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6930 * @hdd_ctx: hdd global context
6931 *
6932 * Return: none
6933 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006934static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006935{
6936 uint8_t i;
6937
6938 mutex_init(&hdd_ctx->op_ctx.op_lock);
6939 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6940 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6941 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6942 }
6943}
6944#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006945static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006946{
6947}
6948#endif
6949
Yingying Tang95409972016-10-20 15:16:15 +08006950#ifdef WLAN_FEATURE_WOW_PULSE
6951/**
6952 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006953 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006954 * @enable: enable or disable this behaviour
6955 *
6956 * Return: int
6957 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006958static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006959{
6960 struct hdd_config *pcfg_ini = phddctx->config;
6961 struct wow_pulse_mode wow_pulse_set_info;
6962 QDF_STATUS status;
6963
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006964 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006965
6966 if (false == phddctx->config->wow_pulse_support)
6967 return 0;
6968
6969 /* prepare the request to send to SME */
6970 if (enable == true) {
6971 wow_pulse_set_info.wow_pulse_enable = true;
6972 wow_pulse_set_info.wow_pulse_pin =
6973 pcfg_ini->wow_pulse_pin;
6974 wow_pulse_set_info.wow_pulse_interval_low =
6975 pcfg_ini->wow_pulse_interval_low;
6976 wow_pulse_set_info.wow_pulse_interval_high =
6977 pcfg_ini->wow_pulse_interval_high;
6978 } else {
6979 wow_pulse_set_info.wow_pulse_enable = false;
6980 wow_pulse_set_info.wow_pulse_pin = 0;
6981 wow_pulse_set_info.wow_pulse_interval_low = 0;
6982 wow_pulse_set_info.wow_pulse_interval_high = 0;
6983 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006984 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006985 wow_pulse_set_info.wow_pulse_enable,
6986 wow_pulse_set_info.wow_pulse_pin,
6987 wow_pulse_set_info.wow_pulse_interval_low,
6988 wow_pulse_set_info.wow_pulse_interval_high);
6989
6990 status = sme_set_wow_pulse(&wow_pulse_set_info);
6991 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006992 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006993 return -EIO;
6994 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006995 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006996 return 0;
6997}
6998#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006999static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007000{
7001 return 0;
7002}
7003#endif
7004
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007005#ifdef WLAN_FEATURE_FASTPATH
7006/**
7007 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7008 * @hdd_cfg: hdd config
7009 * @context: lower layer context
7010 *
7011 * Return: none
7012 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307013void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007014 void *context)
7015{
7016 if (hdd_cfg->fastpath_enable)
7017 hif_enable_fastpath(context);
7018}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007019#endif
7020
Yuanyuan Liu13738502016-04-06 17:41:37 -07007021#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007022/**
7023 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007024 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007025 * @level: thermal level
7026 *
7027 * Change IPA data path to SW path when the thermal throttle level greater
7028 * than 0, and restore the original data path when throttle level is 0
7029 *
7030 * Return: none
7031 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007032static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007033{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007034 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007035
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007036 /* Change IPA to SW path when throttle level greater than 0 */
7037 if (level > THROTTLE_LEVEL_0)
7038 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7039 else
7040 /* restore original concurrency mode */
7041 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7042}
7043
7044/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307045 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7046 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307047 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007048 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307049 * Get a safe channel to restart SAP. PCL already takes into account the
7050 * unsafe channels. So, the PCL is validated with the ACS range to provide
7051 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007052 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307053 * Return: Channel number to restart SAP in case of success. In case of any
7054 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007055 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307056static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007057 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007058{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307059 struct sir_pcl_list pcl;
7060 QDF_STATUS status;
7061 uint32_t i, j;
7062 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007063 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307064 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007065
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307066 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7067 if (!hdd_ctx) {
7068 hdd_err("invalid HDD context");
7069 return INVALID_CHANNEL_ID;
7070 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007071
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307072 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7073 if (!hal_handle) {
7074 hdd_err("invalid HAL handle");
7075 return INVALID_CHANNEL_ID;
7076 }
7077
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007078 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7079 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007080 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7081 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307082 if (QDF_IS_STATUS_ERROR(status)) {
7083 hdd_err("Get PCL failed");
7084 return INVALID_CHANNEL_ID;
7085 }
7086
Frank Liudc2cefb2017-06-21 15:38:18 +08007087 /*
7088 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7089 * channel is unsafe channel, the pcl may be empty, instead of return,
7090 * try to choose a safe channel from acs range.
7091 */
7092 if (!pcl.pcl_len)
7093 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307094
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007095 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007096 adapter->session.ap.sap_config.acs_cfg.start_ch,
7097 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307098
7099 /* PCL already takes unsafe channel into account */
7100 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007101 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307102 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007103 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307104 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007105 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007106 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307107 return pcl.pcl_list[i];
7108 }
7109 }
7110
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007111 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307112
7113 /* Try for safe channel from all valid channel */
7114 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007115 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307116 &pcl.pcl_len);
7117 if (QDF_IS_STATUS_ERROR(status)) {
7118 hdd_err("error in getting valid channel list");
7119 return INVALID_CHANNEL_ID;
7120 }
7121
7122 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007123 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307124 found = false;
7125 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007126 if (pcl.pcl_list[i] ==
7127 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007128 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307129 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007130 break;
7131 }
7132 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307133
7134 if (found)
7135 continue;
7136
7137 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007138 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307139 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007140 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007141 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307142 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007143 }
7144 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307145
7146 return INVALID_CHANNEL_ID;
7147}
7148
7149/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007150 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307151 * @adapter: AP adapter
7152 * @channel: Channel
7153 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007154 * Moves the SAP interface by invoking the function which
7155 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307156 *
7157 * Return: None
7158 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007159void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307160{
Jeff Johnson87251032017-08-29 13:31:11 -07007161 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307162 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007163 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307164
7165 if (!adapter) {
7166 hdd_err("invalid adapter");
7167 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007168 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307169
7170 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7171
7172 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7173 if (!hal_handle) {
7174 hdd_err("invalid HAL handle");
7175 return;
7176 }
7177
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007178 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7179
Jeff Johnson91df29d2017-10-27 19:29:50 -07007180 hdd_ap_ctx->sap_config.channel = channel;
7181 hdd_ap_ctx->sap_config.ch_params.ch_width =
7182 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307183
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007184 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007185 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307186
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007187 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007188 hdd_ap_ctx->sap_config.channel,
7189 hdd_ap_ctx->sap_config.sec_ch,
7190 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307191
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007192 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007193 adapter->session_id, channel,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007194 hdd_ap_ctx->sap_config.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007195}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307196
Jeff Johnson9d295242017-08-29 14:39:48 -07007197int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307198{
7199 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307200 int status;
7201 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307202
7203 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7204
7205 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007206 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307207 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007208 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307209 }
7210 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007211 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307212 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307213 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007214 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307215 WLAN_VENDOR_ACS_WAIT_TIME);
7216 if (qdf_status != QDF_STATUS_SUCCESS) {
7217 hdd_err("failed to start external acs timer");
7218 return -ENOSPC;
7219 }
7220 /* Update config to application */
7221 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307222 hdd_notice("Updated ACS config to nl with reason %d", reason);
7223
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307224 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307225}
7226
Agrawal Ashish467dde42016-09-08 18:44:22 +05307227/**
7228 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7229 * @hdd_ctx: hdd context pointer
7230 *
7231 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7232 * and if ACS is enabled, driver will ask userspace to restart the
7233 * sap. User space on LTE coex indication restart driver.
7234 *
7235 * Return - none
7236 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007237void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307238{
7239 QDF_STATUS status;
7240 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007241 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307242 uint32_t i;
7243 bool found = false;
7244 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007245
Agrawal Ashish467dde42016-09-08 18:44:22 +05307246 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7247 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007248 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307249
7250 if (!adapter_temp) {
7251 hdd_err("adapter is NULL, moving to next one");
7252 goto next_adapater;
7253 }
7254
7255 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
Jeff Johnsonb9424862017-10-30 08:49:35 -07007256 (adapter_temp->session.ap.sap_config.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007257 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307258 adapter_temp->device_mode,
Jeff Johnsonb9424862017-10-30 08:49:35 -07007259 adapter_temp->session.ap.sap_config.
Agrawal Ashish467dde42016-09-08 18:44:22 +05307260 acs_cfg.acs_mode);
7261 goto next_adapater;
7262 }
7263
7264 found = false;
7265 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007266 if (adapter_temp->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307267 hdd_ctxt->unsafe_channel_list[i]) {
7268 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007269 hdd_debug("operating ch:%d is unsafe",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007270 adapter_temp->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307271 break;
7272 }
7273 }
7274
7275 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007276 hdd_debug("ch:%d is safe. no need to change channel",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007277 adapter_temp->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307278 goto next_adapater;
7279 }
7280
Kapil Gupta8878ad92017-02-13 11:56:04 +05307281 if (hdd_ctxt->config->vendor_acs_support &&
7282 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7283 hdd_update_acs_timer_reason(adapter_temp,
7284 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7285 goto next_adapater;
7286 } else
7287 restart_chan =
7288 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307289 adapter_temp);
7290 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007291 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307292 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007293 /*
7294 * SAP restart due to unsafe channel. While
7295 * restarting the SAP, make sure to clear
7296 * acs_channel, channel to reset to
7297 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307298 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007299 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307300 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007301 adapter_temp->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307302 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007303 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307304 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7305 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007306 hdd_debug("driver to start sap: %d",
7307 hdd_ctxt->config->sap_internal_restart);
7308 if (hdd_ctxt->config->sap_internal_restart)
7309 hdd_switch_sap_channel(adapter_temp, restart_chan);
7310 else
7311 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307312 }
7313
7314next_adapater:
7315 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7316 adapter_node = next;
7317 }
7318}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307319
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007320/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007321 * hdd_init_channel_avoidance() - Initialize channel avoidance
7322 * @hdd_ctx: HDD global context
7323 *
7324 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007325 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007326 * down to the lower layers. Then subscribe to subsequent channel
7327 * avoidance events.
7328 *
7329 * Return: None
7330 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007331static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007332{
7333 uint16_t unsafe_channel_count;
7334 int index;
7335
Yuanyuan Liu13738502016-04-06 17:41:37 -07007336 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7337 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007338 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007339 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007340
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007341 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007342 hdd_ctx->unsafe_channel_count);
7343
Anurag Chouhan6d760662016-02-20 16:05:43 +05307344 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007345 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007346
7347 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007348 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007349 hdd_ctx->unsafe_channel_list[index]);
7350
7351 }
7352
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007353}
Dustin Brown676a2322017-08-15 13:16:13 -07007354
Jeff Johnson9d295242017-08-29 14:39:48 -07007355static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007356 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007357{
7358 uint8_t restart_chan;
7359
7360 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7361 if (!restart_chan) {
7362 hdd_alert("fail to restart SAP");
7363 return;
7364 }
7365
7366 /* SAP restart due to unsafe channel. While restarting
7367 * the SAP, make sure to clear acs_channel, channel to
7368 * reset to 0. Otherwise these settings will override
7369 * the ACS while restart.
7370 */
7371 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007372 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007373
7374 hdd_debug("sending coex indication");
7375
7376 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7377 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7378 hdd_switch_sap_channel(adapter, restart_chan);
7379}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007380
7381int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7382 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7383{
7384 uint32_t size;
7385 uint16_t *unsafe_list;
7386 uint16_t chan_count;
7387
7388 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7389 return -EINVAL;
7390
7391 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7392 NUM_CHANNELS);
7393 if (chan_count) {
7394 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7395 unsafe_list = qdf_mem_malloc(size);
7396 if (!unsafe_list) {
7397 hdd_err("No memory for unsafe chan list size%d",
7398 size);
7399 return -ENOMEM;
7400 }
7401 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7402 } else {
7403 unsafe_list = NULL;
7404 }
7405
7406 *local_unsafe_list = unsafe_list;
7407 *local_unsafe_list_count = chan_count;
7408
7409 return 0;
7410}
7411
7412bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7413 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7414{
7415 int i, j;
7416
7417 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7418 return true;
7419 if (local_unsafe_list_count == 0)
7420 return false;
7421 for (i = 0; i < local_unsafe_list_count; i++) {
7422 for (j = 0; j < local_unsafe_list_count; j++)
7423 if (local_unsafe_list[i] ==
7424 hdd_ctx->unsafe_channel_list[j])
7425 break;
7426 if (j >= local_unsafe_list_count)
7427 break;
7428 }
7429 if (i >= local_unsafe_list_count) {
7430 hdd_info("unsafe chan list same");
7431 return false;
7432 }
7433
7434 return true;
7435}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007436#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007437static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007438{
7439}
Dustin Brown676a2322017-08-15 13:16:13 -07007440
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007441static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007442{
7443}
Dustin Brown676a2322017-08-15 13:16:13 -07007444
Jeff Johnson9d295242017-08-29 14:39:48 -07007445static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007446 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007447{
7448 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7449}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007450#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007451
7452/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007453 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7454 * user space
7455 * @frame_ind: Management frame data to be informed.
7456 *
7457 * This function is used to indicate management frame to
7458 * user space
7459 *
7460 * Return: None
7461 *
7462 */
7463void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7464{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007465 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007466 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007467 int i;
7468
Rajeev Kumard004abc2016-02-17 12:09:56 -08007469 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007470 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007471
7472 if (0 != wlan_hdd_validate_context(hdd_ctx))
7473 return;
7474
7475 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7476 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7477 adapter =
7478 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7479 if (adapter)
7480 break;
7481 }
7482 } else {
7483 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7484 frame_ind->sessionId);
7485 }
7486
7487 if ((NULL != adapter) &&
7488 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7489 __hdd_indicate_mgmt_frame(adapter,
7490 frame_ind->frame_len,
7491 frame_ind->frameBuf,
7492 frame_ind->frameType,
7493 frame_ind->rxChan,
7494 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007495}
7496
Kapil Gupta8878ad92017-02-13 11:56:04 +05307497void hdd_acs_response_timeout_handler(void *context)
7498{
7499 struct hdd_external_acs_timer_context *timer_context =
7500 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007501 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007502 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307503 uint8_t reason;
7504
7505 ENTER();
7506 if (!timer_context) {
7507 hdd_err("invlaid timer context");
7508 return;
7509 }
7510 adapter = timer_context->adapter;
7511 reason = timer_context->reason;
7512
7513
7514 if ((!adapter) ||
7515 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7516 hdd_err("invalid adapter or adapter has invalid magic");
7517 return;
7518 }
7519 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7520 if (wlan_hdd_validate_context(hdd_ctx))
7521 return;
7522
7523 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7524 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7525 else
7526 return;
7527
7528 hdd_err("ACS timeout happened for %s reason %d",
7529 adapter->dev->name, reason);
7530 switch (reason) {
7531 /* SAP init case */
7532 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7533 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7534 false);
7535 wlan_hdd_cfg80211_start_acs(adapter);
7536 break;
7537 /* DFS detected on current channel */
7538 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7539 wlan_sap_update_next_channel(
7540 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7541 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007542 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307543 break;
7544 /* LTE coex event on current channel */
7545 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7546 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7547 break;
7548 default:
7549 hdd_info("invalid reason for timer invoke");
7550
7551 }
7552}
7553
Rajeev Kumard004abc2016-02-17 12:09:56 -08007554/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007555 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7556 * @hdd_ctx: HDD context
7557 *
7558 * Disables all the dual mac features like DBS, Agile DFS etc.
7559 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307560 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007561 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007562static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007563{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007564 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307565 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007566
7567 if (!hdd_ctx) {
7568 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307569 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007570 }
7571
7572 cfg.scan_config = 0;
7573 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007574 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007575
7576 hdd_debug("Disabling all dual mac features...");
7577
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007578 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307579 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007580 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7581 return status;
7582 }
7583
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307584 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007585}
7586
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007587static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007588wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007589{
7590 struct policy_mgr_dual_mac_config cfg = {0};
7591 QDF_STATUS status;
7592
7593 if (!hdd_ctx) {
7594 hdd_err("HDD context is NULL");
7595 return QDF_STATUS_E_FAILURE;
7596 }
7597
7598 cfg.scan_config = 0;
7599 cfg.fw_mode_config = 0;
7600 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7601 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7602 hdd_ctx->hdd_psoc, &cfg.scan_config,
7603 &cfg.fw_mode_config,
7604 hdd_ctx->config->dual_mac_feature_disable);
7605
7606 if (status != QDF_STATUS_SUCCESS) {
7607 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7608 status);
7609 return status;
7610 }
7611
7612 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7613 cfg.scan_config, cfg.fw_mode_config);
7614
7615 status = sme_soc_set_dual_mac_config(cfg);
7616 if (status != QDF_STATUS_SUCCESS) {
7617 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7618 return status;
7619 }
7620
7621 return QDF_STATUS_SUCCESS;
7622}
7623
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007624/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007625 * hdd_override_ini_config - Override INI config
7626 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007628 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007629 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007630 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007631 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007632static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007633{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007634
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007635 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7636 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007637 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007638 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007639 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007640 if (0 == enable_11d || 1 == enable_11d) {
7641 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007642 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007643 }
Leo Chang11545d62016-10-17 14:53:50 -07007644
7645 if (!hdd_ipa_is_present(hdd_ctx))
7646 hdd_ctx->config->IpaConfig = 0;
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05307647
7648 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
7649 !hdd_ctx->config->enable_bcast_probe_rsp) {
7650 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
7651 hdd_ctx->config->rssi_assoc_reject_enabled,
7652 hdd_ctx->config->enable_bcast_probe_rsp);
7653 hdd_ctx->config->oce_sta_enabled = 0;
7654 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007655}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007656
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007657/**
7658 * hdd_set_trace_level_for_each - Set trace level for each INI config
7659 * @hdd_ctx - HDD context
7660 *
7661 * Set trace level for each module based on INI config.
7662 *
7663 * Return: None
7664 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007665static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007666{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307667 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7668 hdd_ctx->config->qdf_trace_enable_wdi);
7669 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7670 hdd_ctx->config->qdf_trace_enable_hdd);
7671 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7672 hdd_ctx->config->qdf_trace_enable_sme);
7673 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7674 hdd_ctx->config->qdf_trace_enable_pe);
7675 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7676 hdd_ctx->config->qdf_trace_enable_wma);
7677 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7678 hdd_ctx->config->qdf_trace_enable_sys);
7679 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7680 hdd_ctx->config->qdf_trace_enable_qdf);
7681 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7682 hdd_ctx->config->qdf_trace_enable_sap);
7683 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7684 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7685 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7686 hdd_ctx->config->qdf_trace_enable_bmi);
7687 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7688 hdd_ctx->config->qdf_trace_enable_cfg);
7689 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7690 hdd_ctx->config->qdf_trace_enable_epping);
7691 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7692 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7693 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007694 hdd_ctx->config->qdf_trace_enable_txrx);
7695 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7696 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307697 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7698 hdd_ctx->config->qdf_trace_enable_htc);
7699 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7700 hdd_ctx->config->qdf_trace_enable_hif);
7701 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7702 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7703 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7704 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007705 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7706 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007707 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7708 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007709 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7710 hdd_ctx->config->qdf_trace_enable_regulatory);
7711
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007712 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007713}
7714
7715/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007716 * hdd_context_init() - Initialize HDD context
7717 * @hdd_ctx: HDD context.
7718 *
7719 * Initialize HDD context along with all the feature specific contexts.
7720 *
7721 * return: 0 on success and errno on failure.
7722 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007723static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007724{
7725 int ret;
7726
7727 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7728 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7729
7730 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307731 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007732
7733 init_completion(&hdd_ctx->mc_sus_event_var);
7734 init_completion(&hdd_ctx->ready_to_suspend);
7735
7736 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307737 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007738 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307739
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007740 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007741
7742 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7743
7744 ret = hdd_scan_context_init(hdd_ctx);
7745 if (ret)
7746 goto list_destroy;
7747
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007748 hdd_rx_wake_lock_create(hdd_ctx);
7749
7750 ret = hdd_sap_context_init(hdd_ctx);
7751 if (ret)
7752 goto scan_destroy;
7753
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007754 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7755
7756 hdd_init_offloaded_packets_ctx(hdd_ctx);
7757
7758 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7759 hdd_ctx->config);
7760 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08007761 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007762
7763 return 0;
7764
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007765sap_destroy:
7766 hdd_sap_context_destroy(hdd_ctx);
7767
7768scan_destroy:
7769 hdd_scan_context_destroy(hdd_ctx);
7770 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007771list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007772 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007773
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007774 return ret;
7775}
7776
7777/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307778 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7779 * @hdd_ctx: pointer to hdd context
7780 *
7781 * Return: status of initialization
7782 * 0 - success
7783 * negative value - failure
7784 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007785static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307786{
7787 int ret;
7788
7789 if (!hdd_ctx->config->probe_req_ie_whitelist)
7790 return 0;
7791
7792 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7793 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7794 hdd_ctx->config->probe_req_ie_whitelist = false;
7795 return -EINVAL;
7796 }
7797
7798 /* parse ini string probe req oui */
7799 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7800 if (ret) {
7801 hdd_err("parsing error: disable ie whitelisting");
7802 hdd_ctx->config->probe_req_ie_whitelist = false;
7803 }
7804
7805 return ret;
7806}
7807
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05307808
7809/**
7810 * hdd_iface_change_callback() - Function invoked when stop modules expires
7811 * @priv: pointer to hdd context
7812 *
7813 * This function is invoked when the timer waiting for the interface change
7814 * expires, it shall cut-down the power to wlan and stop all the modules.
7815 *
7816 * Return: void
7817 */
7818static void hdd_iface_change_callback(void *priv)
7819{
7820 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
7821 int ret;
7822 int status = wlan_hdd_validate_context(hdd_ctx);
7823
7824 if (status)
7825 return;
7826
7827 ENTER();
7828 hdd_debug("Interface change timer expired close the modules!");
7829 ret = hdd_wlan_stop_modules(hdd_ctx, false);
7830 if (ret)
7831 hdd_err("Failed to stop modules");
7832 EXIT();
7833}
7834
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307835/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007836 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307837 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007838 *
7839 * Allocate and initialize HDD context. HDD context is allocated as part of
7840 * wiphy allocation and then context is initialized.
7841 *
7842 * Return: HDD context on success and ERR_PTR on failure
7843 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007844static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007845{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307846 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007847 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007848 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007849
7850 ENTER();
7851
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007852 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007853 if (hdd_ctx == NULL) {
7854 ret = -ENOMEM;
7855 goto err_out;
7856 }
7857
Dustin Brown6f427922017-09-19 12:19:00 -07007858 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
7859 hdd_iface_change_callback,
7860 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05307861
7862 mutex_init(&hdd_ctx->iface_change_lock);
7863
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007864 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307865 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007866
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307867 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007868 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007869 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007870 ret = -ENOMEM;
7871 goto err_free_hdd_context;
7872 }
7873
7874 /* Read and parse the qcom_cfg.ini file */
7875 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307876 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307877 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007878 WLAN_INI_FILE);
7879 ret = -EINVAL;
7880 goto err_free_config;
7881 }
7882
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307883 ie_whitelist_attrs_init(hdd_ctx);
7884
Dustin Brown7f939932017-05-18 15:02:17 -07007885 hdd_debug("setting timer multiplier: %u",
7886 hdd_ctx->config->timer_multiplier);
7887 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7888
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007889
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307890 if (hdd_ctx->config->fhostNSOffload)
7891 hdd_ctx->ns_offload_enable = true;
7892
Abhishek Singh5ea86532016-04-27 14:10:53 +05307893 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7894
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007895 hdd_override_ini_config(hdd_ctx);
7896
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007897 ret = hdd_context_init(hdd_ctx);
7898
7899 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007900 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007901
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007902 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307903 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007904
Anurag Chouhan6d760662016-02-20 16:05:43 +05307905 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007906 goto skip_multicast_logging;
7907
7908 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7909
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007910 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7911 if (ret)
7912 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307913
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007914 ret = hdd_init_netlink_services(hdd_ctx);
7915 if (ret)
7916 goto err_deinit_txrx_histogram;
7917
Dustin Brown7b3dea22017-07-10 13:02:47 -07007918 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7919 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307920
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007921skip_multicast_logging:
7922 hdd_set_trace_level_for_each(hdd_ctx);
7923
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007924 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7925
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007926 EXIT();
7927
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007928 return hdd_ctx;
7929
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007930err_deinit_txrx_histogram:
7931 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7932
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007933err_deinit_hdd_context:
7934 hdd_context_deinit(hdd_ctx);
7935
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007936err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307937 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007938
7939err_free_hdd_context:
7940 wiphy_free(hdd_ctx->wiphy);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05307941 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007942
7943err_out:
7944 return ERR_PTR(ret);
7945}
7946
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007947#ifdef WLAN_OPEN_P2P_INTERFACE
7948/**
7949 * hdd_open_p2p_interface - Open P2P interface
7950 * @hdd_ctx: HDD context
7951 * @rtnl_held: True if RTNL lock held
7952 *
7953 * Open P2P interface during probe. This function called to open the P2P
7954 * interface at probe along with STA interface.
7955 *
7956 * Return: 0 on success and errno on failure
7957 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007958static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007959{
Jeff Johnson9d295242017-08-29 14:39:48 -07007960 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007961 uint8_t *p2p_dev_addr;
7962
7963 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7964 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07007965 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007966 hdd_ctx->config->intfMacAddr[0].bytes,
7967 sizeof(tSirMacAddr));
7968
7969 /*
7970 * Generate the P2P Device Address. This consists of
7971 * the device's primary MAC address with the locally
7972 * administered bit set.
7973 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07007974 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007975 } else {
7976 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7977 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007978 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007979 return -ENOSPC;
7980 }
7981
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07007982 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
7983 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007984 }
7985
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007986 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07007987 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007988 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007989
7990 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007991 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007992 return -ENOSPC;
7993 }
7994
7995 return 0;
7996}
7997#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007998static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007999 bool rtnl_held)
8000{
8001 return 0;
8002}
8003#endif
8004
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008005static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008006{
Jeff Johnson9d295242017-08-29 14:39:48 -07008007 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008008 int ret = 0;
8009
8010 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8011 wlan_hdd_get_intf_addr(hdd_ctx),
8012 NET_NAME_UNKNOWN, rtnl_held);
8013 if (adapter == NULL) {
8014 hdd_err("Failed to open 802.11p interface");
8015 ret = -ENOSPC;
8016 }
8017
8018 return ret;
8019}
8020
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008021/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308022 * hdd_start_station_adapter()- Start the Station Adapter
8023 * @adapter: HDD adapter
8024 *
8025 * This function initializes the adapter for the station mode.
8026 *
8027 * Return: 0 on success or errno on failure.
8028 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008029int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308030{
8031 QDF_STATUS status;
8032
8033 ENTER_DEV(adapter->dev);
8034
8035 status = hdd_init_station_mode(adapter);
8036
8037 if (QDF_STATUS_SUCCESS != status) {
8038 hdd_err("Error Initializing station mode: %d", status);
8039 return qdf_status_to_os_return(status);
8040 }
8041
Arun Khandavallifae92942016-08-01 13:31:08 +05308042 hdd_register_tx_flow_control(adapter,
8043 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008044 hdd_tx_resume_cb,
8045 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308046
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308047 EXIT();
8048 return 0;
8049}
8050
8051/**
8052 * hdd_start_ap_adapter()- Start AP Adapter
8053 * @adapter: HDD adapter
8054 *
8055 * This function initializes the adapter for the AP mode.
8056 *
8057 * Return: 0 on success errno on failure.
8058 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008059int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308060{
8061 QDF_STATUS status;
8062
8063 ENTER();
8064
Arun Khandavallicc544b32017-01-30 19:52:16 +05308065 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308066
8067 if (QDF_STATUS_SUCCESS != status) {
8068 hdd_err("Error Initializing the AP mode: %d", status);
8069 return qdf_status_to_os_return(status);
8070 }
8071
Arun Khandavallifae92942016-08-01 13:31:08 +05308072 hdd_register_tx_flow_control(adapter,
8073 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008074 hdd_softap_tx_resume_cb,
8075 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308076
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308077 EXIT();
8078 return 0;
8079}
8080
8081/**
8082 * hdd_start_ftm_adapter()- Start FTM adapter
8083 * @adapter: HDD adapter
8084 *
8085 * This function initializes the adapter for the FTM mode.
8086 *
8087 * Return: 0 on success or errno on failure.
8088 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008089int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308090{
8091 QDF_STATUS qdf_status;
8092
8093 ENTER_DEV(adapter->dev);
8094
8095 qdf_status = hdd_init_tx_rx(adapter);
8096
8097 if (QDF_STATUS_SUCCESS != qdf_status) {
8098 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8099 return qdf_status_to_os_return(qdf_status);
8100 }
8101
8102 return 0;
8103 EXIT();
8104}
8105
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308106static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8107 bool rtnl_held)
8108{
8109 struct hdd_adapter *adapter;
8110
8111 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8112 hdd_ctx->config->enableConcurrentSTA,
8113 wlan_hdd_get_intf_addr(hdd_ctx),
8114 NET_NAME_UNKNOWN, rtnl_held);
8115
8116 if (!adapter)
8117 return -ENOSPC;
8118
8119 return 0;
8120}
8121
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308122/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008123 * hdd_open_interfaces - Open all required interfaces
8124 * hdd_ctx: HDD context
8125 * rtnl_held: True if RTNL lock is held
8126 *
8127 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8128 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008129 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008130 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008131static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008132{
Jeff Johnson9d295242017-08-29 14:39:48 -07008133 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008134 int ret;
8135
Ravi Joshia307f632017-07-17 23:41:41 -07008136 /* open monitor mode adapter if con_mode is monitor mode */
8137 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8138 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8139 wlan_hdd_get_intf_addr(hdd_ctx),
8140 NET_NAME_UNKNOWN, rtnl_held);
8141 if (!adapter) {
8142 hdd_err("open adapter failed");
8143 return -ENOSPC;
8144 }
8145 return 0;
8146 }
8147
Jeff Johnson957bc272017-02-02 08:54:48 -08008148 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308149 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008150 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008151
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008152 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008153 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008154 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008155
8156 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008157 return -ENOSPC;
8158
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008159 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8160 adapter->fast_roaming_allowed = true;
8161
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308162 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8163 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8164 if (ret)
8165 hdd_err("Cannot create concurrent STA interface");
8166 }
8167
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008168 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8169 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008170 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008171
8172 /* Open 802.11p Interface */
8173 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008174 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8175 if (ret)
8176 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008177 }
8178
Jeff Johnson957bc272017-02-02 08:54:48 -08008179 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008180
Jeff Johnson957bc272017-02-02 08:54:48 -08008181err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008182 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008183 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008184}
8185
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008186/**
8187 * hdd_update_country_code - Update country code
8188 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008189 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008190 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008191 *
8192 * Return: 0 on success and errno on failure
8193 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008194static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008195{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008196 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008197 return 0;
8198
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008199 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008200}
8201
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308202#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8203/**
8204 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8205 * @cds_cfg: CDS Configuration
8206 * @hdd_ctx: Pointer to hdd context
8207 *
8208 * Return: none
8209 */
8210static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8211 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008212 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308213{
8214 cds_cfg->tx_flow_stop_queue_th =
8215 hdd_ctx->config->TxFlowStopQueueThreshold;
8216 cds_cfg->tx_flow_start_queue_offset =
8217 hdd_ctx->config->TxFlowStartQueueOffset;
8218}
8219#else
8220static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8221 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008222 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308223{
8224}
8225#endif
8226
8227#ifdef FEATURE_WLAN_RA_FILTERING
8228/**
8229 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8230 * @cds_cfg: CDS Configuration
8231 * @hdd_ctx: Pointer to hdd context
8232 *
8233 * Return: none
8234 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308235static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008236 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308237{
8238 cds_cfg->ra_ratelimit_interval =
8239 hdd_ctx->config->RArateLimitInterval;
8240 cds_cfg->is_ra_ratelimit_enabled =
8241 hdd_ctx->config->IsRArateLimitEnabled;
8242}
8243#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308244static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008245 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308246{
8247}
8248#endif
8249
8250/**
8251 * hdd_update_cds_config() - API to update cds configuration parameters
8252 * @hdd_ctx: HDD Context
8253 *
8254 * Return: 0 for Success, errno on failure
8255 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008256static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308257{
8258 struct cds_config_info *cds_cfg;
8259
8260 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8261 if (!cds_cfg) {
8262 hdd_err("failed to allocate cds config");
8263 return -ENOMEM;
8264 }
8265
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008266 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008267 if (!hdd_ctx->config->nMaxPsPoll ||
8268 !hdd_ctx->config->enablePowersaveOffload) {
8269 cds_cfg->powersave_offload_enabled =
8270 hdd_ctx->config->enablePowersaveOffload;
8271 } else {
8272 if ((hdd_ctx->config->enablePowersaveOffload ==
8273 PS_QPOWER_NODEEPSLEEP) ||
8274 (hdd_ctx->config->enablePowersaveOffload ==
8275 PS_LEGACY_NODEEPSLEEP))
8276 cds_cfg->powersave_offload_enabled =
8277 PS_LEGACY_NODEEPSLEEP;
8278 else
8279 cds_cfg->powersave_offload_enabled =
8280 PS_LEGACY_DEEPSLEEP;
8281 hdd_info("Qpower disabled in cds config, %d",
8282 cds_cfg->powersave_offload_enabled);
8283 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308284 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8285 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8286 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8287 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8288 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8289
8290 /* Here ol_ini_info is used to store ini status of arp offload
8291 * ns offload and others. Currently 1st bit is used for arp
8292 * off load and 2nd bit for ns offload currently, rest bits are unused
8293 */
8294 if (hdd_ctx->config->fhostArpOffload)
8295 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8296 if (hdd_ctx->config->fhostNSOffload)
8297 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8298
8299 /*
8300 * Copy the DFS Phyerr Filtering Offload status.
8301 * This parameter reflects the value of the
8302 * dfs_phyerr_filter_offload flag as set in the ini.
8303 */
8304 cds_cfg->dfs_phyerr_filter_offload =
8305 hdd_ctx->config->fDfsPhyerrFilterOffload;
8306 if (hdd_ctx->config->ssdp)
8307 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8308
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308309 cds_cfg->force_target_assert_enabled =
8310 hdd_ctx->config->crash_inject_enabled;
8311
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308312 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8313 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8314
8315 cds_cfg->ap_maxoffload_reorderbuffs =
8316 hdd_ctx->config->apMaxOffloadReorderBuffs;
8317
8318 cds_cfg->ap_disable_intrabss_fwd =
8319 hdd_ctx->config->apDisableIntraBssFwd;
8320
8321 cds_cfg->dfs_pri_multiplier =
8322 hdd_ctx->config->dfsRadarPriMultiplier;
8323 cds_cfg->reorder_offload =
8324 hdd_ctx->config->reorderOffloadSupport;
8325
8326 /* IPA micro controller data path offload resource config item */
8327 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008328 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8329 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008330 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008331 hdd_ctx->config->IpaUcTxBufCount);
8332 hdd_ctx->config->IpaUcTxBufCount =
8333 rounddown_pow_of_two(
8334 hdd_ctx->config->IpaUcTxBufCount);
8335 if (!hdd_ctx->config->IpaUcTxBufCount) {
8336 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308337 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008338 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008339 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008340 hdd_ctx->config->IpaUcTxBufCount);
8341 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308342 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8343 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008344 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8345 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008346 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008347 hdd_ctx->config->IpaUcRxIndRingCount);
8348 hdd_ctx->config->IpaUcRxIndRingCount =
8349 rounddown_pow_of_two(
8350 hdd_ctx->config->IpaUcRxIndRingCount);
8351 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8352 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308353 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008354 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008355 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008356 hdd_ctx->config->IpaUcRxIndRingCount);
8357 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308358 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008359 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308360 cds_cfg->uc_tx_partition_base =
8361 hdd_ctx->config->IpaUcTxPartitionBase;
8362 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8363
8364 cds_cfg->ip_tcp_udp_checksum_offload =
8365 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008366 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308367 cds_cfg->ce_classify_enabled =
8368 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008369 cds_cfg->bpf_packet_filter_enable =
8370 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308371 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8372 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8373 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008374 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008375 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008376 cds_cfg->max_msdus_per_rxinorderind =
8377 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008378 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008379 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308380 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8381 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308382 cds_cfg->auto_power_save_fail_mode =
8383 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308384
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308385 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008386 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308387
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308388 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8389 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8390 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008391 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308392 cds_init_ini_config(cds_cfg);
8393 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308394
8395exit:
8396 qdf_mem_free(cds_cfg);
8397 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308398}
8399
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008400/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008401 * hdd_update_user_config() - API to update user configuration
8402 * parameters to obj mgr which are used by multiple components
8403 * @hdd_ctx: HDD Context
8404 *
8405 * Return: 0 for Success, errno on failure
8406 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008407static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008408{
8409 struct wlan_objmgr_psoc_user_config *user_config;
8410
8411 user_config = qdf_mem_malloc(sizeof(*user_config));
8412 if (user_config == NULL) {
8413 hdd_alert("Failed to alloc memory for user_config!");
8414 return -ENOMEM;
8415 }
8416
8417 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8418 user_config->dual_mac_feature_disable =
8419 hdd_ctx->config->dual_mac_feature_disable;
8420 user_config->indoor_channel_support =
8421 hdd_ctx->config->indoor_channel_support;
8422 user_config->is_11d_support_enabled =
8423 hdd_ctx->config->Is11dSupportEnabled;
8424 user_config->is_11h_support_enabled =
8425 hdd_ctx->config->Is11hSupportEnabled;
8426 user_config->optimize_chan_avoid_event =
8427 hdd_ctx->config->goptimize_chan_avoid_event;
8428 user_config->skip_dfs_chnl_in_p2p_search =
8429 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008430 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008431 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8432
8433 qdf_mem_free(user_config);
8434 return 0;
8435}
8436
8437/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008438 * hdd_init_thermal_info - Initialize thermal level
8439 * @hdd_ctx: HDD context
8440 *
8441 * Initialize thermal level at SME layer and set the thermal level callback
8442 * which would be called when a configured thermal threshold is hit.
8443 *
8444 * Return: 0 on success and errno on failure
8445 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008446static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008447{
8448 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308449 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008450
8451 thermal_param.smeThermalMgmtEnabled =
8452 hdd_ctx->config->thermalMitigationEnable;
8453 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8454
Poddar, Siddarth83905022016-04-16 17:56:08 -07008455 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8456 hdd_ctx->config->throttle_dutycycle_level0;
8457 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8458 hdd_ctx->config->throttle_dutycycle_level1;
8459 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8460 hdd_ctx->config->throttle_dutycycle_level2;
8461 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8462 hdd_ctx->config->throttle_dutycycle_level3;
8463
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008464 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8465 hdd_ctx->config->thermalTempMinLevel0;
8466 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8467 hdd_ctx->config->thermalTempMaxLevel0;
8468 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8469 hdd_ctx->config->thermalTempMinLevel1;
8470 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8471 hdd_ctx->config->thermalTempMaxLevel1;
8472 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8473 hdd_ctx->config->thermalTempMinLevel2;
8474 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8475 hdd_ctx->config->thermalTempMaxLevel2;
8476 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8477 hdd_ctx->config->thermalTempMinLevel3;
8478 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8479 hdd_ctx->config->thermalTempMaxLevel3;
8480
8481 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8482
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308483 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308484 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008485
8486 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8487 hdd_set_thermal_level_cb);
8488
8489 return 0;
8490
8491}
8492
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008493#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8494/**
8495 * hdd_hold_rtnl_lock - Hold RTNL lock
8496 *
8497 * Hold RTNL lock
8498 *
8499 * Return: True if held and false otherwise
8500 */
8501static inline bool hdd_hold_rtnl_lock(void)
8502{
8503 rtnl_lock();
8504 return true;
8505}
8506
8507/**
8508 * hdd_release_rtnl_lock - Release RTNL lock
8509 *
8510 * Release RTNL lock
8511 *
8512 * Return: None
8513 */
8514static inline void hdd_release_rtnl_lock(void)
8515{
8516 rtnl_unlock();
8517}
8518#else
8519static inline bool hdd_hold_rtnl_lock(void) { return false; }
8520static inline void hdd_release_rtnl_lock(void) { }
8521#endif
8522
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008523#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008524
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308525/* MAX iwpriv command support */
8526#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308527#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308528#define MAX_PKTLOG_SIZE 16
8529
8530/**
8531 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8532 * @hdd_ctx: hdd context
8533 * @set_value2: pktlog buffer size value
8534 *
8535 *
8536 * Return: 0 for success or error.
8537 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008538static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308539{
8540 struct sir_wifi_start_log start_log = { 0 };
8541 QDF_STATUS status;
8542
8543 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8544 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8545 start_log.ini_triggered = cds_is_packet_log_enabled();
8546 start_log.user_triggered = 1;
8547 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308548 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308549
8550 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8551 if (!QDF_IS_STATUS_SUCCESS(status)) {
8552 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8553 EXIT();
8554 return -EINVAL;
8555 }
8556
8557 return 0;
8558}
8559
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008560/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308561 * hdd_pktlog_clear_buff() - clear pktlog buffer
8562 * @hdd_ctx: hdd context
8563 *
8564 * Return: 0 for success or error.
8565 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008566static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308567{
8568 struct sir_wifi_start_log start_log;
8569 QDF_STATUS status;
8570
8571 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8572 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8573 start_log.ini_triggered = cds_is_packet_log_enabled();
8574 start_log.user_triggered = 1;
8575 start_log.size = 0;
8576 start_log.is_pktlog_buff_clear = true;
8577
8578 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8579 if (!QDF_IS_STATUS_SUCCESS(status)) {
8580 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8581 EXIT();
8582 return -EINVAL;
8583 }
8584
8585 return 0;
8586}
8587
8588
8589/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008590 * hdd_process_pktlog_command() - process pktlog command
8591 * @hdd_ctx: hdd context
8592 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308593 * @set_value2: pktlog buffer size value
8594 *
8595 * This function process pktlog command.
8596 * set_value2 only matters when set_value is 3 (set buff size)
8597 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008598 *
8599 * Return: 0 for success or error.
8600 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008601int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308602 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008603{
8604 int ret;
8605 bool enable;
8606 uint8_t user_triggered = 0;
8607
8608 ret = wlan_hdd_validate_context(hdd_ctx);
8609 if (0 != ret)
8610 return ret;
8611
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008612 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008613
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308614 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008615 hdd_err("invalid pktlog value %d", set_value);
8616 return -EINVAL;
8617 }
8618
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308619 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8620 if (set_value2 <= 0) {
8621 hdd_err("invalid pktlog size %d", set_value2);
8622 return -EINVAL;
8623 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8624 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8625 return -EINVAL;
8626 }
8627 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308628 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8629 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308630 }
8631
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008632 /*
8633 * set_value = 0 then disable packetlog
8634 * set_value = 1 enable packetlog forcefully
8635 * set_vlaue = 2 then disable packetlog if disabled through ini or
8636 * enable packetlog with AUTO type.
8637 */
8638 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8639 true : false;
8640
8641 if (1 == set_value) {
8642 enable = true;
8643 user_triggered = 1;
8644 }
8645
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308646 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008647}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008648
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008649/**
8650 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8651 * @hdd_ctx: HDD context
8652 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308653 * @user_triggered: triggered through iwpriv
8654 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008655 *
8656 * Return: 0 on success; error number otherwise
8657 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008658int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308659 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008660{
8661 struct sir_wifi_start_log start_log;
8662 QDF_STATUS status;
8663
8664 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8665 start_log.verbose_level =
8666 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008667 start_log.ini_triggered = cds_is_packet_log_enabled();
8668 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308669 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308670 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308671 /*
8672 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8673 * commands. Host uses this flag to decide whether to send pktlog
8674 * disable command to fw without sending pktlog enable command
8675 * previously. For eg, If vendor sends pktlog disable command without
8676 * sending pktlog enable command, then host discards the packet
8677 * but for iwpriv command, host will send it to fw.
8678 */
8679 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008680 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8681 if (!QDF_IS_STATUS_SUCCESS(status)) {
8682 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8683 EXIT();
8684 return -EINVAL;
8685 }
8686
8687 return 0;
8688}
8689#endif /* REMOVE_PKT_LOG */
8690
Komal Seelam92fff912016-03-24 11:51:41 +05308691/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008692 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8693 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308694 * @dev: Device Pointer
8695 * @num: Number of Valid Mac address
8696 *
8697 * Return: Pointer to MAC address buffer
8698 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008699static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8700 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308701{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008702 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308703}
Komal Seelam92fff912016-03-24 11:51:41 +05308704
8705/**
8706 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8707 * @hdd_ctx: HDD Context
8708 * @num: Number of random mac addresses needed
8709 *
8710 * Generate random addresses using bit manipulation on the base mac address
8711 *
8712 * Return: None
8713 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008714void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308715{
8716 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8717 uint32_t iter;
8718 struct hdd_config *ini = hdd_ctx->config;
8719 uint8_t *buf = NULL;
8720 uint8_t macaddr_b3, tmp_br3;
8721 uint8_t *src = ini->intfMacAddr[0].bytes;
8722
8723 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8724 buf = ini->intfMacAddr[iter].bytes;
8725 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8726 macaddr_b3 = buf[3];
8727 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8728 INTF_MACADDR_MASK;
8729 macaddr_b3 += tmp_br3;
8730 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8731 buf[0] |= 0x02;
8732 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008733 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308734 }
8735}
8736
8737/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008738 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308739 * @hdd_ctx: HDD Context
8740 *
8741 * API to get mac addresses from platform driver and update the driver
8742 * structures and configure FW with the base mac address.
8743 * Return: int
8744 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008745static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308746{
8747 uint32_t no_of_mac_addr, iter;
8748 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8749 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8750 uint8_t *addr, *buf;
8751 struct device *dev = hdd_ctx->parent_dev;
8752 struct hdd_config *ini = hdd_ctx->config;
8753 tSirMacAddr mac_addr;
8754 QDF_STATUS status;
8755
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008756 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308757
8758 if (no_of_mac_addr == 0 || !addr) {
8759 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8760 return -EINVAL;
8761 }
8762
8763 if (no_of_mac_addr > max_mac_addr)
8764 no_of_mac_addr = max_mac_addr;
8765
8766 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8767
8768 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8769 buf = ini->intfMacAddr[iter].bytes;
8770 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008771 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308772 }
8773
8774 status = sme_set_custom_mac_addr(mac_addr);
8775
8776 if (!QDF_IS_STATUS_SUCCESS(status))
8777 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008778
Komal Seelam92fff912016-03-24 11:51:41 +05308779 if (no_of_mac_addr < max_mac_addr)
8780 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8781 no_of_mac_addr);
8782 return 0;
8783}
8784
8785/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008786 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8787 * @hdd_ctx: HDD Context
8788 *
8789 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8790 * will generate its own MAC and update it to FW.
8791 *
8792 * Return: 0 for success
8793 * Non-zero error code for failure
8794 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008795static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008796{
8797 tSirMacAddr customMacAddr;
8798 QDF_STATUS status;
8799
8800 qdf_mem_copy(&customMacAddr,
8801 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8802 sizeof(tSirMacAddr));
8803 status = sme_set_custom_mac_addr(customMacAddr);
8804 if (!QDF_IS_STATUS_SUCCESS(status))
8805 return -EAGAIN;
8806 return 0;
8807}
8808
8809/**
Komal Seelam92fff912016-03-24 11:51:41 +05308810 * hdd_initialize_mac_address() - API to get wlan mac addresses
8811 * @hdd_ctx: HDD Context
8812 *
8813 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8814 * is provisioned with mac addresses, driver uses it, else it will use
8815 * wlan_mac.bin to update HW MAC addresses.
8816 *
8817 * Return: None
8818 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008819static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308820{
8821 QDF_STATUS status;
8822 int ret;
8823
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008824 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308825 if (ret == 0)
8826 return;
8827
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008828 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8829 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308830
8831 status = hdd_update_mac_config(hdd_ctx);
8832
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008833 if (QDF_IS_STATUS_SUCCESS(status))
8834 return;
8835
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008836 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8837 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008838
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008839 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008840 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008841 if (ret != 0) {
8842 hdd_err("MAC address out-of-sync, ret:%d", ret);
8843 QDF_ASSERT(ret);
8844 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008845 }
Komal Seelam92fff912016-03-24 11:51:41 +05308846}
8847
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008848static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008849{
8850 int vdev_id = 0;
8851 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8852 int value = hdd_ctx->config->smart_chainmask_enabled;
8853 int vpdev = PDEV_CMD;
8854 int ret;
8855
Naveen Rawat247a8682017-06-05 15:00:31 -07008856 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008857 if (ret)
8858 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8859
8860 return ret;
8861}
8862
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008863static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008864{
8865 int vdev_id = 0;
8866 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8867 int value = hdd_ctx->config->alternative_chainmask_enabled;
8868 int vpdev = PDEV_CMD;
8869 int ret;
8870
Naveen Rawat247a8682017-06-05 15:00:31 -07008871 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008872 if (ret)
8873 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8874 ret);
8875
8876 return ret;
8877}
8878
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008879static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008880{
8881 int vdev_id = 0;
8882 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8883 int value = hdd_ctx->config->ani_enabled;
8884 int vpdev = PDEV_CMD;
8885 int ret;
8886
Naveen Rawat247a8682017-06-05 15:00:31 -07008887 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008888 if (ret)
8889 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8890
8891 return ret;
8892}
8893
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008894/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008895 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8896 * @hdd_ctx: HDD context
8897 *
8898 * Pre configurations to be done at lower layer before calling cds enable.
8899 *
8900 * Return: 0 on success and errno on failure.
8901 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008902static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008903{
8904 int ret;
8905 QDF_STATUS status;
8906 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008907 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008908
Leo Changfdb45c32016-10-28 11:09:23 -07008909 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008910 /*
8911 * Set 802.11p config
8912 * TODO-OCB: This has been temporarily added here to ensure this
8913 * parameter is set in CSR when we init the channel list. This should
8914 * be removed once the 5.9 GHz channels are added to the regulatory
8915 * domain.
8916 */
8917 hdd_set_dot11p_config(hdd_ctx);
8918
8919 /*
8920 * Note that the cds_pre_enable() sequence triggers the cfg download.
8921 * The cfg download must occur before we update the SME config
8922 * since the SME config operation must access the cfg database
8923 */
8924 status = hdd_set_sme_config(hdd_ctx);
8925
8926 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008927 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008928 ret = qdf_status_to_os_return(status);
8929 goto out;
8930 }
8931
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008932 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8933 if (QDF_STATUS_SUCCESS != status) {
8934 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8935 ret = qdf_status_to_os_return(status);
8936 goto out;
8937 }
8938
Naveen Rawat247a8682017-06-05 15:00:31 -07008939 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008940 hdd_ctx->config->tx_chain_mask_1ss,
8941 PDEV_CMD);
8942 if (0 != ret) {
8943 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8944 goto out;
8945 }
8946
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008947 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8948 if (ret)
8949 goto out;
8950
8951 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8952 if (ret)
8953 goto out;
8954
Jeff Johnson12a744b2017-04-04 08:19:37 -07008955 ret = hdd_set_ani_enabled(hdd_ctx);
8956 if (ret)
8957 goto out;
8958
Naveen Rawat247a8682017-06-05 15:00:31 -07008959 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008960 hdd_ctx->config->arp_ac_category,
8961 PDEV_CMD);
8962 if (0 != ret) {
8963 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8964 hdd_ctx->config->arp_ac_category, ret);
8965 goto out;
8966 }
8967
8968
Prashanth Bhatta07998752016-04-28 12:35:33 -07008969 status = hdd_set_sme_chan_list(hdd_ctx);
8970 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008971 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008972 ret = qdf_status_to_os_return(status);
8973 goto out;
8974 }
8975
8976 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008977 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008978 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008979 ret = -EINVAL;
8980 goto out;
8981 }
8982
Prashanth Bhatta07998752016-04-28 12:35:33 -07008983 /*
8984 * Set the MAC Address Currently this is used by HAL to add self sta.
8985 * Remove this once self sta is added as part of session open.
8986 */
8987 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8988 hdd_ctx->config->intfMacAddr[0].bytes,
8989 sizeof(hdd_ctx->config->intfMacAddr[0]));
8990
8991 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8992 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8993 hal_status, hal_status);
8994 ret = -EINVAL;
8995 goto out;
8996 }
8997
8998 hdd_init_channel_avoidance(hdd_ctx);
8999
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309000 /* update enable sap mandatory chan list */
9001 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9002 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009003out:
9004 return ret;
9005}
9006
9007/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009008 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9009 * @context_ptr - hdd context pointer
9010 * @event_ptr - event structure pointer
9011 *
9012 * This is the p2p listen offload stop event handler, it sends vendor
9013 * event back to supplicant to notify the stop reason.
9014 *
9015 * Return: None
9016 */
9017static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9018 void *event_ptr)
9019{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009020 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009021 struct sir_p2p_lo_event *evt = event_ptr;
9022 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009023 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009024
9025 ENTER();
9026
9027 if (hdd_ctx == NULL) {
9028 hdd_err("Invalid HDD context pointer");
9029 return;
9030 }
9031
Peng Xu5c682812017-08-06 07:39:13 -07009032 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9033 if (!adapter) {
9034 hdd_err("Cannot find adapter by vdev_id = %d",
9035 evt->vdev_id);
9036 return;
9037 }
9038
Peng Xu8fdaa492016-06-22 10:20:47 -07009039 vendor_event =
9040 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009041 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009042 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9043 GFP_KERNEL);
9044
9045 if (!vendor_event) {
9046 hdd_err("cfg80211_vendor_event_alloc failed");
9047 return;
9048 }
9049
9050 if (nla_put_u32(vendor_event,
9051 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9052 evt->reason_code)) {
9053 hdd_err("nla put failed");
9054 kfree_skb(vendor_event);
9055 return;
9056 }
9057
9058 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009059 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9060 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009061}
9062
9063/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309064 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9065 * @hdd_ctx: HDD context
9066 *
9067 * This function sends the adaptive dwell time config configuration to the
9068 * firmware via WMA
9069 *
9070 * Return: 0 - success, < 0 - failure
9071 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009072static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309073{
9074 QDF_STATUS status;
9075 struct adaptive_dwelltime_params dwelltime_params;
9076
9077 dwelltime_params.is_enabled =
9078 hdd_ctx->config->adaptive_dwell_mode_enabled;
9079 dwelltime_params.dwelltime_mode =
9080 hdd_ctx->config->global_adapt_dwelltime_mode;
9081 dwelltime_params.lpf_weight =
9082 hdd_ctx->config->adapt_dwell_lpf_weight;
9083 dwelltime_params.passive_mon_intval =
9084 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9085 dwelltime_params.wifi_act_threshold =
9086 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9087
9088 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9089 &dwelltime_params);
9090
9091 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9092 if (!QDF_IS_STATUS_SUCCESS(status)) {
9093 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9094 return -EAGAIN;
9095 }
9096 return 0;
9097}
9098
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009099int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309100{
9101 QDF_STATUS status;
9102 struct wmi_dbs_scan_sel_params dbs_scan_params;
9103 uint32_t i = 0;
9104 uint8_t count = 0, numentries = 0;
9105 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9106 * CDS_DBS_SCAN_CLIENTS_MAX];
9107
9108 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009109 if (hdd_ctx->config->dual_mac_feature_disable ==
9110 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309111 return -EINVAL;
9112
9113 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9114 dbs_scan_config, &numentries,
9115 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9116 * CDS_DBS_SCAN_CLIENTS_MAX));
9117
9118 hdd_info("numentries %hu", numentries);
9119 if (!numentries) {
9120 hdd_info("Donot send scan_selection_config");
9121 return 0;
9122 }
9123
9124 /* hdd_set_fw_log_params */
9125 dbs_scan_params.num_clients = 0;
9126 while (count < (numentries - 2)) {
9127 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9128 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9129 dbs_scan_params.num_non_dbs_scans[i] =
9130 dbs_scan_config[count + 2];
9131 dbs_scan_params.num_clients++;
9132 hdd_debug("module:%d NDS:%d NNDS:%d",
9133 dbs_scan_params.module_id[i],
9134 dbs_scan_params.num_dbs_scans[i],
9135 dbs_scan_params.num_non_dbs_scans[i]);
9136 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9137 i++;
9138 }
9139
9140 dbs_scan_params.pdev_id = 0;
9141
9142 hdd_debug("clients:%d pdev:%d",
9143 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9144
9145 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9146 &dbs_scan_params);
9147 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9148 if (!QDF_IS_STATUS_SUCCESS(status)) {
9149 hdd_err("Failed to send DBS Scan selection configuration!");
9150 return -EAGAIN;
9151 }
9152 return 0;
9153}
9154
Arun Khandavallid4349a92016-07-25 11:10:43 +05309155#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9156/**
9157 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9158 * @hdd_ctx: HDD context
9159 *
9160 * Set auto shutdown callback to get indications from firmware to indicate
9161 * userspace to shutdown WLAN after a configured amount of inactivity.
9162 *
9163 * Return: 0 on success and errno on failure.
9164 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009165static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309166{
9167 QDF_STATUS status;
9168
9169 if (!hdd_ctx->config->WlanAutoShutdown)
9170 return 0;
9171
9172 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9173 wlan_hdd_auto_shutdown_cb);
9174 if (status != QDF_STATUS_SUCCESS)
9175 hdd_err("Auto shutdown feature could not be enabled: %d",
9176 status);
9177
9178 return qdf_status_to_os_return(status);
9179}
9180#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009181static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309182{
9183 return 0;
9184}
9185#endif
9186
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009187static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009188{
9189 QDF_STATUS status = QDF_STATUS_SUCCESS;
9190
9191 switch (hdd_ctx->config->dual_mac_feature_disable) {
9192 case DISABLE_DBS_CXN_AND_SCAN:
9193 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9194 if (status != QDF_STATUS_SUCCESS)
9195 hdd_err("Failed to disable dual mac features");
9196 break;
9197 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9198 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9199 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9200 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9201 if (status != QDF_STATUS_SUCCESS)
9202 hdd_err("Failed to set dbs scan and fw mode config");
9203 break;
9204 default:
9205 break;
9206 }
9207
9208 return status;
9209}
9210
Arun Khandavallid4349a92016-07-25 11:10:43 +05309211/**
9212 * hdd_features_init() - Init features
9213 * @hdd_ctx: HDD context
9214 * @adapter: Primary adapter context
9215 *
9216 * Initialize features and their feature context after WLAN firmware is up.
9217 *
9218 * Return: 0 on success and errno on failure.
9219 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009220static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309221{
9222 tSirTxPowerLimit hddtxlimit;
9223 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309224 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309225 int ret;
9226
9227 ENTER();
9228
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009229 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309230 if (ret) {
9231 hdd_err("Failed to update country code: %d", ret);
9232 goto out;
9233 }
9234
9235 /* FW capabilities received, Set the Dot11 mode */
9236 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009237 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9238 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309239
Arun Khandavallid4349a92016-07-25 11:10:43 +05309240
9241 if (hdd_ctx->config->fIsImpsEnabled)
9242 hdd_set_idle_ps_config(hdd_ctx, true);
9243 else
9244 hdd_set_idle_ps_config(hdd_ctx, false);
9245
Poddar, Siddarth37033032017-10-11 15:47:40 +05309246 /* Send Enable/Disable data stall detection cmd to FW */
9247 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9248 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9249
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309250 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009251 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309252
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309253 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9254 hdd_warn("Error in setting Voltage Corner mode config to FW");
9255
Arun Khandavallid4349a92016-07-25 11:10:43 +05309256 if (hdd_lro_init(hdd_ctx))
9257 hdd_err("Unable to initialize LRO in fw");
9258
9259 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9260 hdd_err("Unable to send adaptive dwelltime setting to FW");
9261
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309262 if (hdd_dbs_scan_selection_init(hdd_ctx))
9263 hdd_err("Unable to send DBS scan selection setting to FW");
9264
Arun Khandavallid4349a92016-07-25 11:10:43 +05309265 ret = hdd_init_thermal_info(hdd_ctx);
9266 if (ret) {
9267 hdd_err("Error while initializing thermal information");
9268 goto deregister_frames;
9269 }
9270
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309271 if (cds_is_packet_log_enabled())
9272 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9273
Arun Khandavallid4349a92016-07-25 11:10:43 +05309274 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9275 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9276 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9277 if (!QDF_IS_STATUS_SUCCESS(status))
9278 hdd_err("Error setting txlimit in sme: %d", status);
9279
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009280 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309281
Arun Khandavallid4349a92016-07-25 11:10:43 +05309282 ret = hdd_register_cb(hdd_ctx);
9283 if (ret) {
9284 hdd_err("Failed to register HDD callbacks!");
9285 goto deregister_frames;
9286 }
9287
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009288 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9289 if (!QDF_IS_STATUS_SUCCESS(status)) {
9290 hdd_err("Failed to set dbs scan and fw mode cfg");
9291 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309292 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009293
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309294 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9295 status = sme_enable_disable_chanavoidind_event(
9296 hdd_ctx->hHal, 0);
9297 if (!QDF_IS_STATUS_SUCCESS(status)) {
9298 hdd_err("Failed to disable Chan Avoidance Indication");
9299 goto deregister_cb;
9300 }
9301 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309302
Manjeet Singha9cae432017-02-28 11:58:22 +05309303 if (hdd_ctx->config->enable_5g_band_pref) {
9304 band_pref_params.rssi_boost_threshold_5g =
9305 hdd_ctx->config->rssi_boost_threshold_5g;
9306 band_pref_params.rssi_boost_factor_5g =
9307 hdd_ctx->config->rssi_boost_factor_5g;
9308 band_pref_params.max_rssi_boost_5g =
9309 hdd_ctx->config->max_rssi_boost_5g;
9310 band_pref_params.rssi_penalize_threshold_5g =
9311 hdd_ctx->config->rssi_penalize_threshold_5g;
9312 band_pref_params.rssi_penalize_factor_5g =
9313 hdd_ctx->config->rssi_penalize_factor_5g;
9314 band_pref_params.max_rssi_penalize_5g =
9315 hdd_ctx->config->max_rssi_penalize_5g;
9316 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9317 }
9318
Arun Khandavallid4349a92016-07-25 11:10:43 +05309319 /* register P2P Listen Offload event callback */
9320 if (wma_is_p2p_lo_capable())
9321 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9322 wlan_hdd_p2p_lo_event_callback);
9323
9324 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9325
9326 if (ret)
9327 goto deregister_cb;
9328
9329 EXIT();
9330 return 0;
9331
9332deregister_cb:
9333 hdd_deregister_cb(hdd_ctx);
9334deregister_frames:
9335 wlan_hdd_cfg80211_deregister_frames(adapter);
9336out:
9337 return -EINVAL;
9338
9339}
9340
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009341/**
9342 * hdd_features_deinit() - Deinit features
9343 * @hdd_ctx: HDD context
9344 *
9345 * De-Initialize features and their feature context.
9346 *
9347 * Return: none.
9348 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009349static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009350{
9351 wlan_hdd_tsf_deinit(hdd_ctx);
9352}
9353
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309354/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009355 * hdd_register_bcn_cb() - register scan beacon callback
9356 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309357 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009358 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309359 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009360static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309361{
9362 QDF_STATUS status;
9363
9364 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9365 wlan_cfg80211_inform_bss_frame,
9366 SCAN_CB_TYPE_INFORM_BCN);
9367 if (!QDF_IS_STATUS_SUCCESS(status)) {
9368 hdd_err("failed with status code %08d [x%08x]",
9369 status, status);
9370 return status;
9371 }
9372
9373 return QDF_STATUS_SUCCESS;
9374}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309375
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309376/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309377 * hdd_configure_cds() - Configure cds modules
9378 * @hdd_ctx: HDD context
9379 * @adapter: Primary adapter context
9380 *
9381 * Enable Cds modules after WLAN firmware is up.
9382 *
9383 * Return: 0 on success and errno on failure.
9384 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009385int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309386{
9387 int ret;
9388 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309389 int set_value;
9390 uint32_t num_abg_tx_chains = 0;
9391 uint32_t num_11b_tx_chains = 0;
9392 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009393 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309394
9395 if (hdd_ctx->config->sifs_burst_duration) {
9396 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9397 hdd_ctx->config->sifs_burst_duration;
9398
9399 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9400 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9401 set_value, PDEV_CMD);
9402 }
9403
9404 if (hdd_ctx->config->is_force_1x1)
9405 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9406 1, PDEV_CMD);
9407 /* set chip power save failure detected callback */
9408 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9409 hdd_chip_pwr_save_fail_detected_cb);
9410
9411 if (hdd_ctx->config->max_mpdus_inampdu) {
9412 set_value = hdd_ctx->config->max_mpdus_inampdu;
9413 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9414 set_value, PDEV_CMD);
9415 }
9416
9417 if (hdd_ctx->config->enable_rts_sifsbursting) {
9418 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9419 sme_cli_set_command(0,
9420 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9421 set_value, PDEV_CMD);
9422 }
9423
9424 if (hdd_ctx->config->sap_get_peer_info) {
9425 set_value = hdd_ctx->config->sap_get_peer_info;
9426 sme_cli_set_command(0,
9427 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9428 set_value, PDEV_CMD);
9429 }
9430
9431 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9432 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9433 if (!hdd_ctx->config->enable2x2) {
9434 if (num_11b_tx_chains > 1)
9435 num_11b_tx_chains = 1;
9436 if (num_11ag_tx_chains > 1)
9437 num_11ag_tx_chains = 1;
9438 }
9439 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9440 num_11b_tx_chains);
9441 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9442 num_11ag_tx_chains);
9443 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9444 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309445
9446 ret = hdd_pre_enable_configure(hdd_ctx);
9447 if (ret) {
9448 hdd_err("Failed to pre-configure cds");
9449 goto out;
9450 }
9451
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009452 /* Always get latest IPA resources allocated from cds_open and configure
9453 * IPA module before configuring them to FW. Sequence required as crash
9454 * observed otherwise.
9455 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009456 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9457 hdd_err("Failed to setup pipes");
9458 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009459 }
9460
Arun Khandavallifae92942016-08-01 13:31:08 +05309461 /*
9462 * Start CDS which starts up the SME/MAC/HAL modules and everything
9463 * else
9464 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009465 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309466
9467 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009468 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309469 goto out;
9470 }
9471
9472 status = hdd_post_cds_enable_config(hdd_ctx);
9473 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009474 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009475 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309476 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309477 status = hdd_register_bcn_cb(hdd_ctx);
9478 if (!QDF_IS_STATUS_SUCCESS(status)) {
9479 hdd_alert("hdd_post_cds_enable_config failed");
9480 goto cds_disable;
9481 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309482
9483 ret = hdd_features_init(hdd_ctx, adapter);
9484 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009485 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309486
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009487 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009488 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009489 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9490 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009491 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009492 goto cds_disable;
9493 }
9494
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309495 if (hdd_enable_egap(hdd_ctx))
9496 hdd_debug("enhance green ap is not enabled");
9497
Nachiket Kukadedd302662017-07-13 17:31:44 +05309498 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9499 hdd_debug("Failed to set wow pulse");
9500
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309501 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9502 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9503
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309504
9505 if (hdd_ctx->config->enable_phy_reg_retention)
9506 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9507 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9508
Arun Khandavallifae92942016-08-01 13:31:08 +05309509 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009510
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009511cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009512 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009513
Arun Khandavallifae92942016-08-01 13:31:08 +05309514out:
9515 return -EINVAL;
9516}
9517
9518/**
9519 * hdd_deconfigure_cds() -De-Configure cds
9520 * @hdd_ctx: HDD context
9521 *
9522 * Deconfigure Cds modules before WLAN firmware is down.
9523 *
9524 * Return: 0 on success and errno on failure.
9525 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009526static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309527{
9528 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009529 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309530
9531 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009532
9533 /* De-init features */
9534 hdd_features_deinit(hdd_ctx);
9535
Arun Khandavallifae92942016-08-01 13:31:08 +05309536 /* De-register the SME callbacks */
9537 hdd_deregister_cb(hdd_ctx);
9538
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009539 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309540 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9541 hdd_err("Failed to Disable the CDS Modules! :%d",
9542 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009543 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309544 }
9545
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309546 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9547 hdd_err("Failed to disconnect pipes");
9548 ret = -EINVAL;
9549 }
9550
Arun Khandavallifae92942016-08-01 13:31:08 +05309551 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009552 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309553}
9554
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009555#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9556static void hdd_deregister_policy_manager_callback(
9557 struct wlan_objmgr_psoc *psoc)
9558{
9559 if (QDF_STATUS_SUCCESS !=
9560 policy_mgr_deregister_hdd_cb(psoc)) {
9561 hdd_err("HDD callback deregister with policy manager failed");
9562 }
9563}
9564#else
9565static void hdd_deregister_policy_manager_callback(
9566 struct wlan_objmgr_psoc *psoc)
9567{
9568}
9569#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309570
9571/**
9572 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9573 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009574 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309575 *
9576 * This function maintains the driver state machine it will be invoked from
9577 * exit, shutdown and con_mode change handler. Depending on the driver state
9578 * shall perform the stopping/closing of the modules.
9579 *
9580 * Return: 0 for success; non-zero for failure
9581 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009582int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309583{
9584 void *hif_ctx;
9585 qdf_device_t qdf_ctx;
9586 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309587 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009588 bool is_idle_stop = !cds_is_driver_unloading() &&
9589 !cds_is_driver_recovering();
9590 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309591
9592 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009593 hdd_alert("stop WLAN module: entering driver status=%d",
9594 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309595
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009596 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9597
Arun Khandavallifae92942016-08-01 13:31:08 +05309598 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9599 if (!qdf_ctx) {
9600 hdd_err("QDF device context NULL");
9601 return -EINVAL;
9602 }
9603
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309604 mutex_lock(&hdd_ctx->iface_change_lock);
9605 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009606 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +05309607
Dustin Brown70111822017-03-30 15:31:40 -07009608 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -07009609 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009610 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -07009611 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -07009612
9613 cds_print_external_threads();
9614
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009615 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009616 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -07009617 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
9618 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309619 hdd_prevent_suspend_timeout(
9620 hdd_ctx->config->iface_change_wait_time,
9621 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009622 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009623 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -07009624 return 0;
9625 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009626 }
9627
Arun Khandavallifae92942016-08-01 13:31:08 +05309628 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9629
Kabilan Kannan6edafeb2017-11-16 16:34:34 -08009630 /* free user wowl patterns */
9631 hdd_free_user_wowl_ptrns();
9632
Arun Khandavallifae92942016-08-01 13:31:08 +05309633 switch (hdd_ctx->driver_status) {
9634 case DRIVER_MODULES_UNINITIALIZED:
9635 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309636 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309637 case DRIVER_MODULES_CLOSED:
9638 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309639 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309640 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309641 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309642 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009643 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309644 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309645 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309646 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009647 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309648 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9649 break;
9650 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009651 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309652 break;
9653 default:
9654 hdd_err("Trying to stop wlan in a wrong state: %d",
9655 hdd_ctx->driver_status);
9656 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309657 ret = -EINVAL;
9658 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309659 }
9660
Rajeev Kumarbe021242017-02-16 16:12:23 -08009661 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309662 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9663 hdd_err("Failed to process post CDS disable Modules! :%d",
9664 qdf_status);
9665 ret = -EINVAL;
9666 QDF_ASSERT(0);
9667 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07009668
9669 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
9670 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9671 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
9672 ret = -EINVAL;
9673 QDF_ASSERT(0);
9674 }
9675
Dustin Brown0707ddf2017-09-20 15:31:56 -07009676 /*
9677 * Close the scheduler before calling cds_close to make sure
9678 * no thread is scheduled after the each module close is
9679 * is called i.e after all the data structures are freed.
9680 */
9681 qdf_status = cds_sched_close();
9682 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
9683 if (QDF_IS_STATUS_ERROR(qdf_status))
9684 hdd_alert("Failed to close CDS Scheduler");
9685
Jeff Johnsone4b14592017-09-13 14:23:33 -07009686 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309687 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009688 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309689 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309690 QDF_ASSERT(0);
9691 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009692
Arun Khandavallifae92942016-08-01 13:31:08 +05309693 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9694 if (!hif_ctx) {
9695 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309696 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309697 }
9698
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309699 hdd_runtime_suspend_context_deinit(hdd_ctx);
9700
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309701 if (hdd_ctx->target_hw_name) {
9702 qdf_mem_free(hdd_ctx->target_hw_name);
9703 hdd_ctx->target_hw_name = NULL;
9704 }
9705
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309706 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309707
9708 ol_cds_free();
9709
Dustin Brown70111822017-03-30 15:31:40 -07009710 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309711 ret = pld_power_off(qdf_ctx->dev);
9712 if (ret)
9713 hdd_err("CNSS power down failed put device into Low power mode:%d",
9714 ret);
9715 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309716
9717 /* Once the firmware sequence is completed reset this flag */
9718 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309719 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009720 /*
9721 * Reset total mac phy during module stop such that during
9722 * next module start same psoc is used to populate new service
9723 * ready data
9724 */
9725 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309726
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309727done:
9728 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009729 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309730 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07009731 hdd_alert("stop WLAN module: exit driver status=%d",
9732 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309733 EXIT();
9734
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309735 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309736
9737}
9738
Arun Khandavallifae92942016-08-01 13:31:08 +05309739
9740/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309741 * hdd_state_info_dump() - prints state information of hdd layer
9742 * @buf: buffer pointer
9743 * @size: size of buffer to be filled
9744 *
9745 * This function is used to dump state information of hdd layer
9746 *
9747 * Return: None
9748 */
9749static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9750{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009751 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309752 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9753 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009754 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009755 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309756 uint16_t len = 0;
9757 char *buf = *buf_ptr;
9758
9759 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9760 if (!hdd_ctx) {
9761 hdd_err("Failed to get hdd context ");
9762 return;
9763 }
9764
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009765 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309766
9767 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -07009768 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309769 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009770 "\n is_scheduler_suspended %d",
9771 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309772
9773 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9774
9775 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009776 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309777 if (adapter->dev)
9778 len += scnprintf(buf + len, *size - len,
9779 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009780 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309781 "\n device_mode: %d", adapter->device_mode);
9782 switch (adapter->device_mode) {
9783 case QDF_STA_MODE:
9784 case QDF_P2P_CLIENT_MODE:
9785 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9786 len += scnprintf(buf + len, *size - len,
9787 "\n connState: %d",
9788 hdd_sta_ctx->conn_info.connState);
9789 break;
9790
9791 default:
9792 break;
9793 }
9794 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9795 adapter_node = next;
9796 }
9797
9798 *size -= len;
9799 *buf_ptr += len;
9800}
9801
9802/**
9803 * hdd_register_debug_callback() - registration function for hdd layer
9804 * to print hdd state information
9805 *
9806 * Return: None
9807 */
9808static void hdd_register_debug_callback(void)
9809{
9810 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9811}
9812
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309813/*
9814 * wlan_init_bug_report_lock() - Initialize bug report lock
9815 *
9816 * This function is used to create bug report lock
9817 *
9818 * Return: None
9819 */
9820static void wlan_init_bug_report_lock(void)
9821{
9822 p_cds_contextType p_cds_context;
9823
9824 p_cds_context = cds_get_global_context();
9825 if (!p_cds_context) {
9826 hdd_err("cds context is NULL");
9827 return;
9828 }
9829
9830 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9831}
9832
Mohit Khannaf8f96822017-05-17 17:11:59 -07009833void hdd_dp_trace_init(struct hdd_config *config)
9834{
9835
9836 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9837 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9838 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9839 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9840 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9841 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9842 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +08009843 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -07009844
9845 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9846 &num_entries, sizeof(config_params));
9847
9848 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +08009849 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +08009850 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +08009851 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +08009852 else if (bw_compute_interval > 1000) {
9853 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
9854 thresh_time_limit = 1;
9855 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -07009856 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9857
9858 switch (num_entries) {
9859 case 4:
9860 proto_bitmap = config_params[3];
9861 case 3:
9862 verbosity = config_params[2];
9863 case 2:
9864 thresh = config_params[1];
9865 case 1:
9866 live_mode = config_params[0];
9867 default:
9868 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9869 live_mode, thresh, thresh_time_limit,
9870 verbosity, proto_bitmap);
9871 };
9872
9873 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9874 verbosity, proto_bitmap);
9875
9876}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309877/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009878 * hdd_wlan_startup() - HDD init function
9879 * @dev: Pointer to the underlying device
9880 *
9881 * This is the driver startup code executed once a WLAN device has been detected
9882 *
9883 * Return: 0 for success, < 0 for failure
9884 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309885int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009886{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309887 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009888 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009889 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009890 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009891
9892 ENTER();
9893
Arun Khandavallifae92942016-08-01 13:31:08 +05309894 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009895
9896 if (IS_ERR(hdd_ctx))
9897 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009898
Abhishek Singhe9068f12017-03-31 14:14:52 +05309899 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9900 DEFAULT_PSOC_ID);
9901 if (ret) {
9902 hdd_err("Psoc creation fails!");
9903 QDF_BUG(0);
9904 goto err_hdd_free_context;
9905 }
9906
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309907 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309908#ifdef FEATURE_WLAN_CH_AVOID
9909 mutex_init(&hdd_ctx->avoid_freq_lock);
9910#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309911
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009912 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009913 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309914
Jeff Johnson957bc272017-02-02 08:54:48 -08009915 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309916 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009917 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009918 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009919 }
9920
Yingying Tang80e15f32016-09-27 18:23:01 +08009921 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009922
Anurag Chouhan6d760662016-02-20 16:05:43 +05309923 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009924
9925 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009926 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309927 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009928 }
9929
Prashanth Bhatta07998752016-04-28 12:35:33 -07009930 ret = hdd_wiphy_init(hdd_ctx);
9931 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009932 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309933 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009934 }
9935
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309936 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009937 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309938
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309939 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009940 goto err_wiphy_unregister;
9941
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309942 wlan_hdd_init_chan_info(hdd_ctx);
9943
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009944 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009945
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309946 ret = hdd_register_notifiers(hdd_ctx);
9947 if (ret)
9948 goto err_ipa_cleanup;
9949
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009950 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009951
Jeff Johnson957bc272017-02-02 08:54:48 -08009952 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9953 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009954 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009955 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009956 }
9957
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009958 hdd_release_rtnl_lock();
9959 rtnl_held = false;
9960
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009961 wlan_hdd_update_11n_mode(hdd_ctx->config);
9962
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009963#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309964 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309965 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009966 hdd_skip_acs_scan_timer_handler,
9967 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309968 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009969 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009970 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009971#endif
9972
Prashanth Bhattaab004382016-10-11 16:08:11 -07009973 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009974
Jeff Johnson9afc5012016-09-23 13:56:27 -07009975 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009976
Nirav Shahbd36b062016-07-18 11:12:59 +05309977 if (hdd_ctx->rps)
9978 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009979
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309980 status = wlansap_global_init();
9981 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009982 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009983
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009984 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309985 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009986
Arun Khandavallifae92942016-08-01 13:31:08 +05309987 if (hdd_ctx->config->fIsImpsEnabled)
9988 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -07009989 else
9990 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309991
Mukul Sharma07bd8752017-10-10 16:58:14 +05309992 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -07009993 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
9994 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309995 hdd_prevent_suspend_timeout(
9996 hdd_ctx->config->iface_change_wait_time,
9997 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
9998 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309999
Sachin Ahujadddd2632017-03-07 19:07:24 +053010000 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010001 goto success;
10002
Jeff Johnson957bc272017-02-02 08:54:48 -080010003err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010004 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010005
Jeff Johnson46bde382017-02-01 15:31:16 -080010006err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010007 if (rtnl_held)
10008 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010009
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010010 unregister_netdevice_notifier(&hdd_netdev_notifier);
10011
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010012err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010013 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010014
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010015err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010016 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010017
Arun Khandavallifae92942016-08-01 13:31:08 +053010018err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010019 hdd_wlan_stop_modules(hdd_ctx, false);
Dustin Brown792513d2017-11-07 11:07:09 -080010020 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010021
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -070010022err_hdd_free_psoc:
Houston Hoffman47a4a052016-11-14 23:22:44 -080010023 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010024 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010025 hdd_exit_netlink_services(hdd_ctx);
10026
Dustin Brown20912462017-06-07 13:48:25 -070010027 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10028
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010029err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010030 if (cds_is_fw_down())
10031 hdd_err("Not setting the complete event as fw is down");
10032 else
10033 hdd_start_complete(ret);
10034
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010035 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010036 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010037 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010038
10039success:
10040 EXIT();
10041 return 0;
10042}
10043
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010044/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010045 * hdd_wlan_update_target_info() - update target type info
10046 * @hdd_ctx: HDD context
10047 * @context: hif context
10048 *
10049 * Update target info received from firmware in hdd context
10050 * Return:None
10051 */
10052
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010053void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010054{
10055 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10056
10057 if (!tgt_info) {
10058 hdd_err("Target info is Null");
10059 return;
10060 }
10061
10062 hdd_ctx->target_type = tgt_info->target_type;
10063}
10064
10065/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010066 * hdd_get_nud_stats_cb() - callback api to update the stats
10067 * received from the firmware
10068 * @data: pointer to adapter.
10069 * @rsp: pointer to data received from FW.
10070 *
10071 * This is called when wlan driver received response event for
10072 * get arp stats to firmware.
10073 *
10074 * Return: None
10075 */
10076static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10077{
10078 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10079 struct hdd_nud_stats_context *context;
10080 int status;
10081 struct hdd_adapter *adapter = NULL;
10082
10083 ENTER();
10084
10085 if (!rsp) {
10086 hdd_err("data is null");
10087 return;
10088 }
10089
10090 status = wlan_hdd_validate_context(hdd_ctx);
10091 if (0 != status)
10092 return;
10093
10094 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10095 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10096 hdd_err("Invalid adapter or adapter has invalid magic");
10097 return;
10098 }
10099
10100 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10101 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10102 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10103 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10104 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10105 rsp->out_of_order_arp_rsp_drop_cnt);
10106 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10107 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10108 hdd_notice("rsp->ba_session_establishment_status :%x",
10109 rsp->ba_session_establishment_status);
10110
10111 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10112 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10113 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10114 adapter->dad |= rsp->dad_detected;
10115 adapter->con_status = rsp->connect_status;
10116
10117 spin_lock(&hdd_context_lock);
10118 context = &hdd_ctx->nud_stats_context;
10119 complete(&context->response_event);
10120 spin_unlock(&hdd_context_lock);
10121
10122 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010123}
10124
10125/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010126 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010127 * @hdd_ctx: HDD context
10128 *
10129 * Register the HDD callbacks to CDS/SME.
10130 *
10131 * Return: 0 for success or Error code for failure
10132 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010133int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010134{
10135 QDF_STATUS status;
10136 int ret = 0;
10137
10138 ENTER();
10139
10140 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10141
10142 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10143 hdd_send_oem_data_rsp_msg);
10144
10145 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10146 wlan_hdd_cfg80211_fw_mem_dump_cb);
10147 if (!QDF_IS_STATUS_SUCCESS(status)) {
10148 hdd_err("Failed to register memdump callback");
10149 ret = -EINVAL;
10150 return ret;
10151 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010152 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10153 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010154 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10155 sme_nan_register_callback(hdd_ctx->hHal,
10156 wlan_hdd_cfg80211_nan_callback);
10157 sme_stats_ext_register_callback(hdd_ctx->hHal,
10158 wlan_hdd_cfg80211_stats_ext_callback);
10159
10160 sme_ext_scan_register_callback(hdd_ctx->hHal,
10161 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010162 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10163 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010164
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010165 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10166 hdd_rssi_threshold_breached);
10167
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010168 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10169
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010170 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10171 wlan_hdd_cfg80211_link_layer_stats_callback);
10172
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010173 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10174
Zhang Qianca38fb12016-12-23 11:10:48 +080010175 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10176 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10177
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010178 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10179 hdd_lost_link_info_cb);
10180 /* print error and not block the startup process */
10181 if (!QDF_IS_STATUS_SUCCESS(status))
10182 hdd_err("set lost link info callback failed");
10183
Poddar, Siddarth34872782017-08-10 14:08:51 +053010184 ret = hdd_register_data_stall_detect_cb();
10185 if (ret) {
10186 hdd_err("Register data stall detect detect callback failed.");
10187 return ret;
10188 }
10189
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010190 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10191
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010192 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010193 hdd_set_connection_in_progress,
10194 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010195
10196 status = sme_congestion_register_callback(hdd_ctx->hHal,
10197 hdd_update_cca_info_cb);
10198 if (!QDF_IS_STATUS_SUCCESS(status))
10199 hdd_err("set congestion callback failed");
10200
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010201 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10202 hdd_bt_activity_cb);
10203 if (!QDF_IS_STATUS_SUCCESS(status))
10204 hdd_err("set bt activity info callback failed");
10205
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010206 EXIT();
10207
10208 return ret;
10209}
10210
10211/**
10212 * hdd_deregister_cb() - De-Register HDD callbacks.
10213 * @hdd_ctx: HDD context
10214 *
10215 * De-Register the HDD callbacks to CDS/SME.
10216 *
10217 * Return: void
10218 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010219void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010220{
10221 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010222 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010223
10224 ENTER();
10225
10226 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10227 if (!QDF_IS_STATUS_SUCCESS(status))
10228 hdd_err("De-register of dcc stats callback failed: %d",
10229 status);
10230
10231 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010232 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10233
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010234 sme_stats_ext_register_callback(hdd_ctx->hHal,
10235 wlan_hdd_cfg80211_stats_ext_callback);
10236
10237 sme_nan_deregister_callback(hdd_ctx->hHal);
10238 status = sme_reset_tsfcb(hdd_ctx->hHal);
10239 if (!QDF_IS_STATUS_SUCCESS(status))
10240 hdd_err("Failed to de-register tsfcb the callback:%d",
10241 status);
10242 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10243 if (!QDF_IS_STATUS_SUCCESS(status))
10244 hdd_err("Failed to de-register the fw mem dump callback: %d",
10245 status);
10246
Poddar, Siddarth34872782017-08-10 14:08:51 +053010247 ret = hdd_deregister_data_stall_detect_cb();
10248 if (ret)
10249 hdd_err("Failed to de-register data stall detect event callback");
10250
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010251 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10252 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10253
10254 EXIT();
10255}
10256
10257/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010258 * hdd_softap_sta_deauth() - handle deauth req from HDD
10259 * @adapter: Pointer to the HDD
10260 * @enable: bool value
10261 *
10262 * This to take counter measure to handle deauth req from HDD
10263 *
10264 * Return: None
10265 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010266QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010267 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010268{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010269 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010270
10271 ENTER();
10272
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010273 /* Ignore request to deauth bcmc station */
10274 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010275 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010276
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010277 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010278 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10279 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010280
10281 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010282 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010283}
10284
10285/**
10286 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10287 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010288 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010289 *
10290 * This to take counter measure to handle deauth req from HDD
10291 *
10292 * Return: None
10293 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010294void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010295 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010296{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010297 ENTER();
10298
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010299 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010300 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010301 return;
10302
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010303 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010304 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010305}
10306
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010307/**
10308 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10309 * @hdd_ctx: HDD Context
10310 *
10311 * API to find if there is any STA or P2P-Client is connected
10312 *
10313 * Return: true if connected; false otherwise
10314 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010315QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010316{
10317 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10318}
10319
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010320/**
10321 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10322 * @adapter: HDD adapter pointer
10323 *
10324 * This function loop through each adapter and disable roaming on each STA
10325 * device mode except the input adapter.
10326 *
10327 * Note: On the input adapter roaming is not enabled yet hence no need to
10328 * disable.
10329 *
10330 * Return: None
10331 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010332void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010333{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010334 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010335 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010336 hdd_adapter_list_node_t *adapterNode = NULL;
10337 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010338 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010339
10340 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010341 hdd_ctx->config->isRoamOffloadScanEnabled &&
10342 QDF_STA_MODE == adapter->device_mode &&
10343 policy_mgr_is_sta_active_connection_exists(
10344 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010345 hdd_debug("Connect received on STA session Id(%d)",
10346 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010347 /*
10348 * Loop through adapter and disable roaming for each STA device
10349 * mode except the input adapter.
10350 */
10351 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10352
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010353 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010354 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010355
Jeff Johnson1b780e42017-10-31 14:11:45 -070010356 if (QDF_STA_MODE == adapterIdx->device_mode &&
10357 adapter->session_id != adapterIdx->session_id) {
10358 hdd_debug("Disable Roaming on session Id(%d)",
10359 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010360 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10361 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010362 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010363 }
10364
10365 status = hdd_get_next_adapter(hdd_ctx,
10366 adapterNode,
10367 &pNext);
10368 adapterNode = pNext;
10369 }
10370 }
10371}
10372
10373/**
10374 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10375 * @adapter: HDD adapter pointer
10376 *
10377 * This function loop through each adapter and enable roaming on each STA
10378 * device mode except the input adapter.
10379 * Note: On the input adapter no need to enable roaming because link got
10380 * disconnected on this.
10381 *
10382 * Return: None
10383 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010384void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010385{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010386 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010387 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010388 hdd_adapter_list_node_t *adapterNode = NULL;
10389 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010390 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010391
10392 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010393 hdd_ctx->config->isRoamOffloadScanEnabled &&
10394 QDF_STA_MODE == adapter->device_mode &&
10395 policy_mgr_is_sta_active_connection_exists(
10396 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010397 hdd_debug("Disconnect received on STA session Id(%d)",
10398 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010399 /*
10400 * Loop through adapter and enable roaming for each STA device
10401 * mode except the input adapter.
10402 */
10403 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10404
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010405 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010406 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010407
Jeff Johnson1b780e42017-10-31 14:11:45 -070010408 if (QDF_STA_MODE == adapterIdx->device_mode &&
10409 adapter->session_id != adapterIdx->session_id) {
10410 hdd_debug("Enabling Roaming on session Id(%d)",
10411 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010412 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10413 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010414 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010415 REASON_CONNECT);
10416 }
10417
10418 status = hdd_get_next_adapter(hdd_ctx,
10419 adapterNode,
10420 &pNext);
10421 adapterNode = pNext;
10422 }
10423 }
10424}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010425
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010426/**
10427 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10428 * @skb: sk buffer pointer
10429 *
10430 * Sends the bcast message to SVC multicast group with generic nl socket
10431 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10432 *
10433 * Return: None
10434 */
10435static void nl_srv_bcast_svc(struct sk_buff *skb)
10436{
10437#ifdef CNSS_GENL
10438 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10439#else
10440 nl_srv_bcast(skb);
10441#endif
10442}
10443
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010444void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010445{
10446 struct sk_buff *skb;
10447 struct nlmsghdr *nlh;
10448 tAniMsgHdr *ani_hdr;
10449 void *nl_data = NULL;
10450 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010451 struct radio_index_tlv *radio_info;
10452 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010453
10454 if (in_interrupt() || irqs_disabled() || in_atomic())
10455 flags = GFP_ATOMIC;
10456
10457 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10458
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010459 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010460 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010461
10462 nlh = (struct nlmsghdr *)skb->data;
10463 nlh->nlmsg_pid = 0; /* from kernel */
10464 nlh->nlmsg_flags = 0;
10465 nlh->nlmsg_seq = 0;
10466 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10467
10468 ani_hdr = NLMSG_DATA(nlh);
10469 ani_hdr->type = type;
10470
10471 switch (type) {
10472 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010473 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010474 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010475 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010476 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010477 ani_hdr->length = 0;
10478 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010479 break;
10480 case WLAN_SVC_WLAN_STATUS_IND:
10481 case WLAN_SVC_WLAN_VERSION_IND:
10482 case WLAN_SVC_DFS_CAC_START_IND:
10483 case WLAN_SVC_DFS_CAC_END_IND:
10484 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10485 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10486 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010487 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010488 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010489 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010490 ani_hdr->length = len;
10491 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10492 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10493 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010494 break;
10495
10496 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010497 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010498 type);
10499 kfree_skb(skb);
10500 return;
10501 }
10502
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010503 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010504 * Add radio index at the end of the svc event in TLV format
10505 * to maintain the backward compatibility with userspace
10506 * applications.
10507 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010508
10509 tlv_len = 0;
10510
10511 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10512 < WLAN_NL_MAX_PAYLOAD) {
10513 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10514 sizeof(*ani_hdr) + len);
10515 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10516 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10517 radio_info->radio = radio;
10518 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010519 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010520 "Added radio index tlv - radio index %d",
10521 radio_info->radio);
10522 }
10523
10524 nlh->nlmsg_len += tlv_len;
10525 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10526
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010527 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010528}
10529
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010530#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10531void wlan_hdd_auto_shutdown_cb(void)
10532{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010533 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010534
10535 if (!hdd_ctx)
10536 return;
10537
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010538 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010539 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10540 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010541}
10542
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010543void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010544{
10545 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010546 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010547 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010548 bool ap_connected = false, sta_connected = false;
10549 tHalHandle hal_handle;
10550
10551 hal_handle = hdd_ctx->hHal;
10552 if (hal_handle == NULL)
10553 return;
10554
10555 if (hdd_ctx->config->WlanAutoShutdown == 0)
10556 return;
10557
10558 if (enable == false) {
10559 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010560 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010561 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010562 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010563 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010564 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010565 return;
10566 }
10567
10568 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010569 if (policy_mgr_concurrent_open_sessions_running(
10570 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010571 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10572
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010573 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010574 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010575 if (adapter
10576 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010577 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010578 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10579 conn_info.connState ==
10580 eConnectionState_Associated) {
10581 sta_connected = true;
10582 break;
10583 }
10584 }
10585 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010586 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010587 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070010588 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010589 ap_connected = true;
10590 break;
10591 }
10592 }
10593 status = hdd_get_next_adapter(hdd_ctx,
10594 adapterNode,
10595 &pNext);
10596 adapterNode = pNext;
10597 }
10598 }
10599
10600 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010601 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010602 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010603 }
Jeff Johnson68755312017-02-10 11:46:55 -080010604
10605 if (sme_set_auto_shutdown_timer(hal_handle,
10606 hdd_ctx->config->WlanAutoShutdown)
10607 != QDF_STATUS_SUCCESS)
10608 hdd_err("Failed to start wlan auto shutdown timer");
10609 else
10610 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10611 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010612}
10613#endif
10614
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010615struct hdd_adapter *
10616hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10617 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010618{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010619 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010620 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010621 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010622 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10623
10624 con_sap_adapter = NULL;
10625
10626 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010627 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010628 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010629 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10630 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010631 adapter != this_sap_adapter) {
10632 if (check_start_bss) {
10633 if (test_bit(SOFTAP_BSS_STARTED,
10634 &adapter->event_flags)) {
10635 con_sap_adapter = adapter;
10636 break;
10637 }
10638 } else {
10639 con_sap_adapter = adapter;
10640 break;
10641 }
10642 }
10643 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10644 adapterNode = pNext;
10645 }
10646
10647 return con_sap_adapter;
10648}
10649
10650#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010651static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010652{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010653 return adapter->device_mode == QDF_STA_MODE ||
10654 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010655}
10656
Jeff Johnson9d295242017-08-29 14:39:48 -070010657static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010658{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010659 return adapter->device_mode == QDF_SAP_MODE ||
10660 adapter->device_mode == QDF_P2P_GO_MODE;
10661}
10662
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010663static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010664{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010665 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010666 hdd_adapter_list_node_t *node;
10667
10668 status = hdd_get_front_adapter(hdd_ctx, &node);
10669 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010670 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010671
10672 if (adapter &&
10673 hdd_adapter_is_sta(adapter) &&
10674 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10675 conn_info.connState == eConnectionState_Associated) {
10676 return true;
10677 }
10678
10679 if (adapter &&
10680 hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070010681 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070010682 return true;
10683 }
10684
10685 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10686 }
10687
10688 return false;
10689}
10690
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010691static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010692{
10693 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010694
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010695 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010696 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010697 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010698
Dustin Brown5ec6b552017-03-31 12:11:40 -070010699 return is_running;
10700}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010701
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010702static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010703{
10704 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10705 hdd_ctx->bus_bw_timer_running = true;
10706 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10707 hdd_ctx->config->busBandwidthComputeInterval);
10708 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10709}
10710
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010711void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010712{
10713 ENTER();
10714
10715 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10716 hdd_debug("Bandwidth compute timer already started");
10717 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010718 }
10719
Dustin Brown5ec6b552017-03-31 12:11:40 -070010720 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10721
10722 EXIT();
10723}
10724
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010725void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010726{
10727 ENTER();
10728
10729 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10730 hdd_debug("Bandwidth compute timer already started");
10731 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010732 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010733
10734 if (hdd_any_adapter_is_assoc(hdd_ctx))
10735 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10736
10737 EXIT();
10738}
10739
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010740static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010741{
10742 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10743
10744 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10745 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10746 hdd_ctx->bus_bw_timer_running = false;
10747 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10748
10749 hdd_reset_tcp_delack(hdd_ctx);
10750}
10751
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010752void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010753{
10754 ENTER();
10755
10756 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10757 hdd_debug("Bandwidth compute timer already stopped");
10758 return;
10759 }
10760
10761 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10762
10763 EXIT();
10764}
10765
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010766void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010767{
10768 ENTER();
10769
10770 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10771 hdd_debug("Bandwidth compute timer already stopped");
10772 return;
10773 }
10774
10775 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10776 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10777
10778 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010779}
10780#endif
10781
10782/**
10783 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10784 * and sta's operating channel.
10785 * @sta_adapter: Describe the first argument to foobar.
10786 * @ap_adapter: Describe the second argument to foobar.
10787 * @roam_profile: Roam profile of AP to which STA wants to connect.
10788 * @concurrent_chnl_same: If both SAP and STA channels are same then
10789 * set this flag to true else false.
10790 *
10791 * This function checks the sap's operating channel and sta's operating channel.
10792 * if both are same then it will return false else it will restart the sap in
10793 * sta's channel and return true.
10794 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010795 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010796 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010797QDF_STATUS
10798wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10799 struct hdd_adapter *ap_adapter,
10800 tCsrRoamProfile *roam_profile,
10801 tScanResultHandle *scan_cache,
10802 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010803{
Jeff Johnson87251032017-08-29 13:31:11 -070010804 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010805 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010806 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080010807 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010808 *concurrent_chnl_same = true;
10809
10810 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10811 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010812 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010813 scan_cache,
10814 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010815 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010816 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010817 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070010818 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010819 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010820 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010821 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010822 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010823 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070010824 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010825 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010826 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010827 }
10828 }
10829 } else {
10830 /*
10831 * Lets handle worst case scenario here, Scan cache lookup is
10832 * failed so we have to stop the SAP to avoid any channel
10833 * discrepancy between SAP's channel and STA's channel.
10834 * Return the status as failure so caller function could know
10835 * that scan look up is failed.
10836 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010837 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010838 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010839 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010840 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010841}
10842
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010843/**
10844 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10845 * @ap_adapter: SAP adapter
10846 *
10847 * This function will process the stopping of sap adapter.
10848 *
10849 * Return: None
10850 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010851void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010852{
Jeff Johnson87251032017-08-29 13:31:11 -070010853 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010854 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010855 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010856 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010857
10858 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010859 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010860 return;
10861 }
10862
10863 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10864 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010865 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010866 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010867
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010868 mutex_lock(&hdd_ctx->sap_lock);
10869 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010870 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010871 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010872 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010873 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010874 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070010875 sap_context)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010876 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010877 qdf_stop_bss_event,
10878 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010879 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010880 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010881 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010882 return;
10883 }
10884 }
10885 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010886 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10887 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070010888 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010889 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010890 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010891 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010892 }
10893 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010894}
10895
10896/**
10897 * wlan_hdd_start_sap() - this function starts bss of SAP.
10898 * @ap_adapter: SAP adapter
10899 *
10900 * This function will process the starting of sap adapter.
10901 *
10902 * Return: None
10903 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010904void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010905{
Jeff Johnson87251032017-08-29 13:31:11 -070010906 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010907 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010908 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010909 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010910 tsap_Config_t *sap_config;
10911
10912 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010913 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010914 return;
10915 }
10916
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010917 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010918 hdd_err("SoftAp role has not been enabled");
10919 return;
10920 }
10921
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010922 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10923 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10924 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070010925 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010926
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010927 mutex_lock(&hdd_ctx->sap_lock);
10928 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10929 goto end;
10930
10931 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010932 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010933 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10934 goto end;
10935 }
10936
Wei Song2f76f642016-11-18 16:32:53 +080010937 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070010938 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070010939 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010940 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010941 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010942 goto end;
10943
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010944 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010945 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010946 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010947 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010948 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010949 goto end;
10950 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010951 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010952 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070010953 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010954 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10955 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070010956 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053010957 mutex_unlock(&hdd_ctx->sap_lock);
10958
10959 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010960end:
10961 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010962 /* SAP context and beacon cleanup will happen during driver unload
10963 * in hdd_stop_adapter
10964 */
10965 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10966
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010967}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010968
10969/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010970 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10971 * mac scan config
10972 * @status: Status of set antenna mode
10973 *
10974 * Callback on setting the dual mac configuration
10975 *
10976 * Return: None
10977 */
10978void wlan_hdd_soc_set_antenna_mode_cb(
10979 enum set_antenna_mode_status status)
10980{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010981 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010982
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010983 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010984
10985 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10986 if (0 != wlan_hdd_validate_context(hdd_ctx))
10987 return;
10988
10989 /* Signal the completion of set dual mac config */
10990 complete(&hdd_ctx->set_antenna_mode_cmpl);
10991}
10992
10993/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010994 * hdd_get_fw_version() - Get FW version
10995 * @hdd_ctx: pointer to HDD context.
10996 * @major_spid: FW version - major spid.
10997 * @minor_spid: FW version - minor spid
10998 * @ssid: FW version - ssid
10999 * @crmid: FW version - crmid
11000 *
11001 * This function is called to get the firmware build version stored
11002 * as part of the HDD context
11003 *
11004 * Return: None
11005 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011006void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011007 uint32_t *major_spid, uint32_t *minor_spid,
11008 uint32_t *siid, uint32_t *crmid)
11009{
11010 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11011 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11012 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11013 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11014}
11015
11016#ifdef QCA_CONFIG_SMP
11017/**
11018 * wlan_hdd_get_cpu() - get cpu_index
11019 *
11020 * Return: cpu_index
11021 */
11022int wlan_hdd_get_cpu(void)
11023{
11024 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011025
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011026 put_cpu();
11027 return cpu_index;
11028}
11029#endif
11030
11031/**
11032 * hdd_get_fwpath() - get framework path
11033 *
11034 * This function is used to get the string written by
11035 * userspace to start the wlan driver
11036 *
11037 * Return: string
11038 */
11039const char *hdd_get_fwpath(void)
11040{
11041 return fwpath.string;
11042}
11043
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011044static int hdd_qdf_print_init(void)
11045{
11046 int qdf_print_idx;
11047 QDF_STATUS status;
11048
11049 status = qdf_print_setup();
11050 if (status != QDF_STATUS_SUCCESS) {
11051 pr_err("qdf_print_setup failed\n");
11052 return -EINVAL;
11053 }
11054
11055 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11056
11057 if (qdf_print_idx < 0) {
11058 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11059 qdf_print_idx);
11060 return -EINVAL;
11061 }
11062
11063 qdf_set_pidx(qdf_print_idx);
11064
11065 return 0;
11066}
11067
11068static void hdd_qdf_print_deinit(void)
11069{
11070 int qdf_print_idx;
11071
11072 qdf_print_idx = qdf_get_pidx();
11073 qdf_print_ctrl_cleanup(qdf_print_idx);
11074}
11075
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011076/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011077 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011078 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011079 * This function initilizes CDS global context with the help of cds_init. This
11080 * has to be the first function called after probe to get a valid global
11081 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011082 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011083 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011084 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011085int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011086{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011087 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011088 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011089
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011090 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011091 if (QDF_IS_STATUS_ERROR(status)) {
11092 hdd_err("Failed to allocate CDS context");
11093 ret = -ENOMEM;
11094 goto err_out;
11095 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011096
11097 wlan_init_bug_report_lock();
11098
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011099#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11100 wlan_logging_sock_init_svc();
11101#endif
11102
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011103 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11104 (void *)hdd_drv_ops_inactivity_handler, NULL,
11105 QDF_TIMER_TYPE_SW);
11106
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011107 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011108 hdd_qdf_print_init();
11109
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011110 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011111
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011112err_out:
11113 return ret;
11114}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011115
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011116/**
11117 * hdd_deinit() - Deinitialize Driver
11118 *
11119 * This function frees CDS global context with the help of cds_deinit. This
11120 * has to be the last function call in remove callback to free the global
11121 * context.
11122 */
11123void hdd_deinit(void)
11124{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011125 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011126
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011127 wlan_destroy_bug_report_lock();
11128 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011129
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011130 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011131#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11132 wlan_logging_sock_deinit_svc();
11133#endif
11134}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011135
Yue Ma6e7b1a02017-04-03 14:17:46 -070011136#ifdef QCA_WIFI_NAPIER_EMULATION
11137#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11138#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011139#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011140#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011141
Sachin Ahujadddd2632017-03-07 19:07:24 +053011142static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11143 struct file *file)
11144{
11145 return 0;
11146}
11147
11148static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11149 const char __user *user_buf,
11150 size_t count,
11151 loff_t *f_pos)
11152{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011153 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011154 static const char wlan_off_str[] = "OFF";
11155 static const char wlan_on_str[] = "ON";
11156 int ret;
11157 unsigned long rc;
11158
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011159 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011160 pr_err("Failed to read buffer\n");
11161 return -EINVAL;
11162 }
11163
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011164 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011165 pr_debug("Wifi turning off from UI\n");
11166 goto exit;
11167 }
11168
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011169 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011170 pr_err("Invalid value received from framework");
11171 goto exit;
11172 }
11173
11174 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011175 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011176 rc = wait_for_completion_timeout(&wlan_start_comp,
11177 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11178 if (!rc) {
11179 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11180 ret = -EINVAL;
11181 hdd_start_complete(ret);
11182 return ret;
11183 }
11184
11185 hdd_start_complete(0);
11186 }
11187
11188exit:
11189 return count;
11190}
11191
11192
11193const struct file_operations wlan_hdd_state_fops = {
11194 .owner = THIS_MODULE,
11195 .open = wlan_hdd_state_ctrl_param_open,
11196 .write = wlan_hdd_state_ctrl_param_write,
11197};
11198
11199static int wlan_hdd_state_ctrl_param_create(void)
11200{
11201 unsigned int wlan_hdd_state_major = 0;
11202 int ret;
11203 struct device *dev;
11204
11205 device = MKDEV(wlan_hdd_state_major, 0);
11206
11207 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11208 if (ret) {
11209 pr_err("Failed to register qcwlanstate");
11210 goto dev_alloc_err;
11211 }
11212 wlan_hdd_state_major = MAJOR(device);
11213
11214 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11215 if (IS_ERR(class)) {
11216 pr_err("wlan_hdd_state class_create error");
11217 goto class_err;
11218 }
11219
11220 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11221 if (IS_ERR(dev)) {
11222 pr_err("wlan_hdd_statedevice_create error");
11223 goto err_class_destroy;
11224 }
11225
11226 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11227 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11228 if (ret) {
11229 pr_err("Failed to add cdev error");
11230 goto cdev_add_err;
11231 }
11232
11233 pr_info("wlan_hdd_state %s major(%d) initialized",
11234 WLAN_MODULE_NAME, wlan_hdd_state_major);
11235
11236 return 0;
11237
11238cdev_add_err:
11239 device_destroy(class, device);
11240err_class_destroy:
11241 class_destroy(class);
11242class_err:
11243 unregister_chrdev_region(device, dev_num);
11244dev_alloc_err:
11245 return -ENODEV;
11246}
11247
11248static void wlan_hdd_state_ctrl_param_destroy(void)
11249{
11250 cdev_del(&wlan_hdd_state_cdev);
11251 device_destroy(class, device);
11252 class_destroy(class);
11253 unregister_chrdev_region(device, dev_num);
11254
11255 pr_info("Device node unregistered");
11256}
11257
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011258/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011259 * component_init - API to init cld component's
11260 *
11261 * Return: None
11262 */
11263static void component_init(void)
11264{
11265 pmo_init();
11266}
11267
11268/**
11269 * component_deinit - API to deinit cld component's
11270 *
11271 * Return: None
11272 */
11273static void component_deinit(void)
11274{
11275 pmo_deinit();
11276}
11277
11278/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011279 * __hdd_module_init - Module init helper
11280 *
11281 * Module init helper function used by both module and static driver.
11282 *
11283 * Return: 0 for success, errno on failure
11284 */
11285static int __hdd_module_init(void)
11286{
11287 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011288
Dustin Brown96cd9632017-11-13 12:45:04 -080011289 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011290 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011291 g_wlan_driver_version,
Dustin Brownab482ac2017-06-09 17:00:44 -070011292 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011293
Sachin Ahujadddd2632017-03-07 19:07:24 +053011294 ret = wlan_hdd_state_ctrl_param_create();
11295 if (ret) {
11296 pr_err("wlan_hdd_state_create:%x\n", ret);
11297 goto err_dev_state;
11298 }
11299
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011300 pld_init();
11301
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011302 ret = hdd_init();
11303 if (ret) {
11304 pr_err("hdd_init failed %x\n", ret);
11305 goto err_hdd_init;
11306 }
11307
Rajeev Kumar97767a02016-11-30 11:20:40 -080011308 dispatcher_init();
11309
Mukul Sharmad75a6672017-06-22 15:40:53 +053011310 /* Ensure to call post objmgr init */
11311 component_init();
11312
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011313 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011314
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011315 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011316
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011317 ret = wlan_hdd_register_driver();
11318 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011319 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11320 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011321 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011322 }
11323
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011324 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011325
11326 return 0;
11327out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011328 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011329 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011330 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011331 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011332
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011333err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011334 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011335 wlan_hdd_state_ctrl_param_destroy();
11336err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011337 return ret;
11338}
11339
11340/**
11341 * __hdd_module_exit - Module exit helper
11342 *
11343 * Module exit helper function used by both module and static driver.
11344 */
11345static void __hdd_module_exit(void)
11346{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011347
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011348 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11349 QWLAN_VERSIONSTR);
11350
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011351 hdd_wait_for_recovery_completion();
11352
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011353 wlan_hdd_unregister_driver();
11354
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011355 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011356
Mukul Sharmad75a6672017-06-22 15:40:53 +053011357 /* Ensure to call prior to objmgr deinit */
11358 component_deinit();
11359
Rajeev Kumar97767a02016-11-30 11:20:40 -080011360 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011361 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011362 pld_deinit();
11363
Sachin Ahujadddd2632017-03-07 19:07:24 +053011364 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011365}
11366
Arun Khandavallifae92942016-08-01 13:31:08 +053011367#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011368/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011369 * wlan_boot_cb() - Wlan boot callback
11370 * @kobj: object whose directory we're creating the link in.
11371 * @attr: attribute the user is interacting with
11372 * @buff: the buffer containing the user data
11373 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011374 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011375 * This callback is invoked when the fs is ready to start the
11376 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011377 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011378 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011379 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011380static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011381 struct kobj_attribute *attr,
11382 const char *buf,
11383 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011384{
Arun Khandavallifae92942016-08-01 13:31:08 +053011385
Arun Khandavallifae92942016-08-01 13:31:08 +053011386 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011387 pr_err("%s: wlan driver already initialized\n", __func__);
11388 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011389 }
11390
Arun Khandavallifae92942016-08-01 13:31:08 +053011391 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011392 pr_err("%s: wlan driver initialization failed\n", __func__);
11393 return -EIO;
11394 }
11395
11396 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011397
11398 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011399}
Arun Khandavallifae92942016-08-01 13:31:08 +053011400
11401/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011402 * hdd_sysfs_cleanup() - cleanup sysfs
11403 *
11404 * Return: None
11405 *
11406 */
11407static void hdd_sysfs_cleanup(void)
11408{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011409 /* remove from group */
11410 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11411 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11412 wlan_loader->attr_group);
11413
11414 /* unlink the object from parent */
11415 kobject_del(wlan_loader->boot_wlan_obj);
11416
11417 /* free the object */
11418 kobject_put(wlan_loader->boot_wlan_obj);
11419
11420 kfree(wlan_loader->attr_group);
11421 kfree(wlan_loader);
11422
11423 wlan_loader = NULL;
11424}
11425
11426/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011427 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11428 * ready
11429 *
11430 * This is creates the syfs entry boot_wlan. Which shall be invoked
11431 * when the filesystem is ready.
11432 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011433 * QDF API cannot be used here since this function is called even before
11434 * initializing WLAN driver.
11435 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011436 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011437 */
11438static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011439{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011440 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011441
11442 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011443 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011444 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011445
11446 wlan_loader->boot_wlan_obj = NULL;
11447 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11448 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011449 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011450 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011451
11452 wlan_loader->loaded_state = 0;
11453 wlan_loader->attr_group->attrs = attrs;
11454
11455 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11456 kernel_kobj);
11457 if (!wlan_loader->boot_wlan_obj) {
11458 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011459 goto error_return;
11460 }
11461
11462 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11463 wlan_loader->attr_group);
11464 if (ret) {
11465 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11466 goto error_return;
11467 }
11468
11469 return 0;
11470
11471error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011472 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011473
11474 return ret;
11475}
11476
11477/**
11478 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11479 *
11480 * Return: 0 on success or errno on failure
11481 */
11482static int wlan_deinit_sysfs(void)
11483{
Arun Khandavallifae92942016-08-01 13:31:08 +053011484 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011485 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011486 return -EINVAL;
11487 }
11488
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011489 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011490 return 0;
11491}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011492
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011493#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011494
11495#ifdef MODULE
11496/**
11497 * __hdd_module_init - Module init helper
11498 *
11499 * Module init helper function used by both module and static driver.
11500 *
11501 * Return: 0 for success, errno on failure
11502 */
11503static int hdd_module_init(void)
11504{
Arun Khandavallifae92942016-08-01 13:31:08 +053011505 if (__hdd_module_init()) {
11506 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011507 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011508 }
11509
Dustin Brownab482ac2017-06-09 17:00:44 -070011510 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011511}
11512#else
11513static int __init hdd_module_init(void)
11514{
11515 int ret = -EINVAL;
11516
11517 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011518 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011519 pr_err("Failed to create sysfs entry for loading wlan");
11520
11521 return ret;
11522}
11523#endif
11524
11525
11526#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011527/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011528 * hdd_module_exit() - Exit function
11529 *
11530 * This is the driver exit point (invoked when module is unloaded using rmmod)
11531 *
11532 * Return: None
11533 */
11534static void __exit hdd_module_exit(void)
11535{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011536 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011537}
Arun Khandavallifae92942016-08-01 13:31:08 +053011538#else
11539static void __exit hdd_module_exit(void)
11540{
11541 __hdd_module_exit();
11542 wlan_deinit_sysfs();
11543}
11544#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011545
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011546static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11547{
11548 return param_set_copystring(kmessage, kp);
11549}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011550
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011551/**
11552 * is_con_mode_valid() check con mode is valid or not
11553 * @mode: global con mode
11554 *
11555 * Return: TRUE on success FALSE on failure
11556 */
11557static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11558{
11559 switch (mode) {
11560 case QDF_GLOBAL_MONITOR_MODE:
11561 case QDF_GLOBAL_FTM_MODE:
11562 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011563 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011564 return true;
11565 default:
11566 return false;
11567 }
11568}
11569
11570/**
11571 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11572 * @mode: global con mode
11573 *
11574 * Return: adapter mode
11575 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011576static enum QDF_OPMODE hdd_get_adpter_mode(
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011577 enum tQDF_GLOBAL_CON_MODE mode)
11578{
11579
11580 switch (mode) {
11581 case QDF_GLOBAL_MISSION_MODE:
11582 return QDF_STA_MODE;
11583 case QDF_GLOBAL_MONITOR_MODE:
11584 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011585 case QDF_GLOBAL_EPPING_MODE:
11586 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011587 case QDF_GLOBAL_FTM_MODE:
11588 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011589 case QDF_GLOBAL_QVIT_MODE:
11590 return QDF_QVIT_MODE;
11591 default:
11592 return QDF_MAX_NO_OF_MODE;
11593 }
11594}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011595
Dustin Brown27cd9942017-09-27 16:11:44 -070011596static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11597 enum tQDF_GLOBAL_CON_MODE curr_mode)
11598{
11599 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11600 return;
11601
11602 switch (curr_mode) {
11603 case QDF_GLOBAL_MISSION_MODE:
11604 case QDF_GLOBAL_MONITOR_MODE:
11605 case QDF_GLOBAL_FTM_MODE:
11606 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11607 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11608
11609 /* re-use the existing session */
11610 hdd_stop_all_adapters(hdd_ctx, false);
11611 break;
11612 default:
11613 break;
11614 }
11615}
11616
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011617static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011618 enum tQDF_GLOBAL_CON_MODE curr_mode)
11619{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011620 int driver_status;
11621
11622 driver_status = hdd_ctx->driver_status;
11623
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011624 switch (curr_mode) {
11625 case QDF_GLOBAL_MISSION_MODE:
11626 case QDF_GLOBAL_MONITOR_MODE:
11627 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011628 hdd_deinit_all_adapters(hdd_ctx, false);
11629 hdd_close_all_adapters(hdd_ctx, false);
11630 break;
11631 case QDF_GLOBAL_EPPING_MODE:
11632 epping_disable();
11633 epping_close();
11634 break;
11635 default:
11636 return;
11637 }
11638}
11639
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011640static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011641 enum tQDF_GLOBAL_CON_MODE mode)
11642{
Jeff Johnson9d295242017-08-29 14:39:48 -070011643 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011644 int ret = 0;
11645 bool rtnl_held;
11646 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11647 QDF_STATUS status;
11648
11649 if (!qdf_dev) {
11650 hdd_err("qdf device context is Null return!");
11651 return -EINVAL;
11652 }
11653
11654 rtnl_held = hdd_hold_rtnl_lock();
11655 switch (mode) {
11656 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011657 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11658 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011659 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011660 break;
11661 case QDF_GLOBAL_FTM_MODE:
11662 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11663 wlan_hdd_get_intf_addr(hdd_ctx),
11664 NET_NAME_UNKNOWN, rtnl_held);
11665 if (adapter == NULL)
11666 ret = -EINVAL;
11667 break;
11668 case QDF_GLOBAL_MONITOR_MODE:
11669 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11670 wlan_hdd_get_intf_addr(hdd_ctx),
11671 NET_NAME_UNKNOWN, rtnl_held);
11672 if (adapter == NULL)
11673 ret = -EINVAL;
11674 break;
11675 case QDF_GLOBAL_EPPING_MODE:
11676 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011677 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011678 hdd_err("Failed to open in eeping mode: %d", status);
11679 ret = -EINVAL;
11680 break;
11681 }
11682 ret = epping_enable(qdf_dev->dev);
11683 if (ret) {
11684 hdd_err("Failed to enable in epping mode : %d", ret);
11685 epping_close();
11686 }
11687 break;
11688 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011689 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011690 ret = -ENOTSUPP;
11691 break;
11692 }
11693 hdd_release_rtnl_lock();
11694 rtnl_held = false;
11695 return ret;
11696}
11697
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011698/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011699 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011700 * @kmessage: con mode name on which driver to be bring up
11701 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011702 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011703 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011704 * This function is invoked when user updates con mode using sys entry,
11705 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011706 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011707 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011708 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011709static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011710 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011711{
11712 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011713 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011714 enum tQDF_GLOBAL_CON_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011715 enum QDF_OPMODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011716
Dustin Brownab6029b2017-05-24 13:04:19 -070011717 hdd_info("con_mode handler: %s", kmessage);
11718
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011719 ret = wlan_hdd_validate_context(hdd_ctx);
11720 if (ret)
11721 return ret;
11722
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011723 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011724
11725 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011726
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011727 if (!(is_con_mode_valid(con_mode))) {
11728 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011729 ret = -EINVAL;
11730 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011731 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011732
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011733 curr_mode = hdd_get_conparam();
11734 if (curr_mode == con_mode) {
11735 hdd_err("curr mode: %d is same as user triggered mode %d",
11736 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011737 ret = 0;
11738 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011739 }
11740
Dustin Brown27cd9942017-09-27 16:11:44 -070011741 /* ensure adapters are stopped */
11742 hdd_stop_present_mode(hdd_ctx, curr_mode);
11743
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011744 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011745 if (ret) {
11746 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011747 goto reset_flags;
11748 }
11749
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011750 /* Cleanup present mode before switching to new mode */
11751 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11752
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011753 hdd_set_conparam(con_mode);
11754
11755 /* Register for new con_mode & then kick_start modules again */
11756 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11757 if (ret) {
11758 hdd_err("Failed to register for new mode");
11759 goto reset_flags;
11760 }
11761
11762 adapter_mode = hdd_get_adpter_mode(con_mode);
11763 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11764 hdd_err("invalid adapter");
11765 ret = -EINVAL;
11766 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011767 }
11768
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011769 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011770 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011771 hdd_err("Failed to get adapter:%d", adapter_mode);
11772 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011773 }
11774
11775 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11776 if (ret) {
11777 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011778 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011779 }
11780
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011781 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011782 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011783 if (hdd_start_adapter(adapter)) {
11784 hdd_err("Failed to start %s adapter", kmessage);
11785 ret = -EINVAL;
11786 goto reset_flags;
11787 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011788 }
11789
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011790 hdd_info("Mode successfully changed to %s", kmessage);
11791 ret = 0;
11792
11793reset_flags:
11794 cds_set_load_in_progress(false);
11795 return ret;
11796}
11797
11798
11799static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11800{
11801 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011802 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011803
11804 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11805 ret = wlan_hdd_validate_context(hdd_ctx);
11806 if (ret)
11807 return ret;
11808
11809 cds_ssr_protect(__func__);
11810 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11811 cds_ssr_unprotect(__func__);
11812
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011813 return ret;
11814}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011815
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011816static int con_mode_handler_ftm(const char *kmessage,
11817 struct kernel_param *kp)
11818{
11819 int ret;
11820
11821 ret = param_set_int(kmessage, kp);
11822
11823 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11824 pr_err("Only FTM mode supported!");
11825 return -ENOTSUPP;
11826 }
11827
11828 hdd_set_conparam(con_mode_ftm);
11829 con_mode = con_mode_ftm;
11830
11831 return ret;
11832}
11833
Ravi Joshia307f632017-07-17 23:41:41 -070011834static int con_mode_handler_monitor(const char *kmessage,
11835 struct kernel_param *kp)
11836{
11837 int ret;
11838
11839 ret = param_set_int(kmessage, kp);
11840
11841 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11842 pr_err("Only Monitor mode supported!");
11843 return -ENOTSUPP;
11844 }
11845
11846 hdd_set_conparam(con_mode_monitor);
11847 con_mode = con_mode_monitor;
11848
11849 return ret;
11850}
11851
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011852/**
11853 * hdd_get_conparam() - driver exit point
11854 *
11855 * This is the driver exit point (invoked when module is unloaded using rmmod)
11856 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011857 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011858 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011859enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011860{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011861 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011862}
11863
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011864void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011865{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011866 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011867}
11868
Komal Seelamc11bb222016-01-27 18:57:10 +053011869/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011870 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11871 * @hdd_ctx: HDD context
11872 *
11873 * Cleans up the pre cac interface, if it exists
11874 *
11875 * Return: None
11876 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011877void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011878{
11879 uint8_t session_id;
11880 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011881 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011882
11883 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11884 if (QDF_IS_STATUS_ERROR(status)) {
11885 hdd_err("failed to get pre cac vdev id");
11886 return;
11887 }
11888
11889 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11890 if (!precac_adapter) {
11891 hdd_err("invalid pre cac adapater");
11892 return;
11893 }
11894
11895 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11896 wlan_hdd_sap_pre_cac_failure,
11897 (void *)precac_adapter);
11898 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11899
11900}
11901
11902/**
Komal Seelamec702b02016-02-24 18:42:16 +053011903 * hdd_update_ol_config - API to update ol configuration parameters
11904 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011905 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011906 * Return: void
11907 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011908static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011909{
Komal Seelamec702b02016-02-24 18:42:16 +053011910 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011911 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011912
Komal Seelamec702b02016-02-24 18:42:16 +053011913 if (!ol_ctx)
11914 return;
11915
11916 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11917 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11918 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11919 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011920 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011921
11922 ol_init_ini_config(ol_ctx, &cfg);
11923}
11924
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011925#ifdef FEATURE_RUNTIME_PM
11926/**
11927 * hdd_populate_runtime_cfg() - populate runtime configuration
11928 * @hdd_ctx: hdd context
11929 * @cfg: pointer to the configuration memory being populated
11930 *
11931 * Return: void
11932 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011933static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011934 struct hif_config_info *cfg)
11935{
11936 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11937 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11938}
11939#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011940static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011941 struct hif_config_info *cfg)
11942{
11943}
11944#endif
11945
Komal Seelamec702b02016-02-24 18:42:16 +053011946/**
11947 * hdd_update_hif_config - API to update HIF configuration parameters
11948 * @hdd_ctx: HDD Context
11949 *
11950 * Return: void
11951 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011952static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011953{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011954 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011955 struct hif_config_info cfg;
11956
11957 if (!scn)
11958 return;
11959
11960 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011961 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011962 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011963
11964 if (hdd_ctx->config->prevent_link_down)
11965 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011966}
11967
11968/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011969 * hdd_update_dp_config() - Propagate config parameters to Lithium
11970 * datapath
11971 * @hdd_ctx: HDD Context
11972 *
11973 * Return: 0 for success/errno for failure
11974 */
11975static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
11976{
11977 struct cdp_config_params params;
11978 QDF_STATUS status;
11979
11980 params.tso_enable = hdd_ctx->config->tso_enable;
11981 params.lro_enable = hdd_ctx->config->lro_enable;
11982#ifdef QCA_LL_TX_FLOW_CONTROL_V2
11983 params.tx_flow_stop_queue_threshold =
11984 hdd_ctx->config->TxFlowStopQueueThreshold;
11985 params.tx_flow_start_queue_offset =
11986 hdd_ctx->config->TxFlowStartQueueOffset;
11987#endif
11988 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
11989 params.napi_enable = hdd_ctx->napi_enable;
11990 params.tcp_udp_checksumoffload =
11991 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
11992
11993 status = cdp_update_config_parameters(
11994 cds_get_context(QDF_MODULE_ID_SOC),
11995 &params);
11996 if (status) {
11997 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
11998 "%s: Failed to attach config parameters", __func__);
11999 return status;
12000 }
12001
12002 return 0;
12003}
12004
12005/**
Komal Seelamec702b02016-02-24 18:42:16 +053012006 * hdd_update_config() - Initialize driver per module ini parameters
12007 * @hdd_ctx: HDD Context
12008 *
12009 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012010 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012011 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012012int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012013{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012014 int ret;
12015
Komal Seelamec702b02016-02-24 18:42:16 +053012016 hdd_update_ol_config(hdd_ctx);
12017 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012018 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12019 ret = hdd_update_cds_config_ftm(hdd_ctx);
12020 else
12021 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012022 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012023
12024 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012025}
12026
Mukul Sharma9d797a02017-01-05 20:26:03 +053012027#ifdef FEATURE_WLAN_RA_FILTERING
12028/**
12029 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12030 * @psoc_cfg: pmo psoc Configuration
12031 * @hdd_ctx: Pointer to hdd context
12032 *
12033 * Return: none
12034 */
12035static inline void hdd_ra_populate_pmo_config(
12036 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012037 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012038{
12039 psoc_cfg->ra_ratelimit_interval =
12040 hdd_ctx->config->RArateLimitInterval;
12041 psoc_cfg->ra_ratelimit_enable =
12042 hdd_ctx->config->IsRArateLimitEnabled;
12043}
12044#else
12045static inline void hdd_ra_populate_pmo_config(
12046 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012047 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012048{
12049}
12050#endif
12051/**
12052 * hdd_update_pmo_config - API to update pmo configuration parameters
12053 * @hdd_ctx: HDD context
12054 *
12055 * Return: void
12056 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012057static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012058{
12059 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12060 struct pmo_psoc_cfg psoc_cfg;
12061 QDF_STATUS status;
12062
12063 /*
12064 * Value of hdd_ctx->wowEnable can be,
12065 * 0 - Disable both magic pattern match and pattern byte match.
12066 * 1 - Enable magic pattern match on all interfaces.
12067 * 2 - Enable pattern byte match on all interfaces.
12068 * 3 - Enable both magic patter and pattern byte match on
12069 * all interfaces.
12070 */
12071 psoc_cfg.magic_ptrn_enable =
12072 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12073 psoc_cfg.ptrn_match_enable_all_vdev =
12074 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012075 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12076 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012077 psoc_cfg.bpf_enable =
12078 hdd_ctx->config->bpf_packet_filter_enable;
12079 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012080 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012081 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12082 if (hdd_ctx->config->fhostNSOffload)
12083 psoc_cfg.ns_offload_enable_dynamic = true;
12084 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12085 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12086 psoc_cfg.active_mode_offload =
12087 hdd_ctx->config->active_mode_offload;
12088 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
12089 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012090 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12091 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12092 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12093 psoc_cfg.power_save_mode =
12094 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012095 psoc_cfg.auto_power_save_fail_mode =
12096 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012097
12098 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012099 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12100 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012101 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012102 if (status != QDF_STATUS_SUCCESS) {
12103 hdd_err("failed pmo psoc configuration");
12104 return -EINVAL;
12105 }
12106
12107 return 0;
12108}
12109
Abhishek Singhb20db962017-03-03 21:28:46 +053012110#ifdef FEATURE_WLAN_SCAN_PNO
12111static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12112 struct hdd_config *cfg)
12113{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012114 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12115
Abhishek Singhb20db962017-03-03 21:28:46 +053012116 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12117 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12118 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12119 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12120 pno_cfg->channel_prediction_full_scan =
12121 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012122 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12123 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12124 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12125 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012126}
12127#else
12128static inline void
12129hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012130 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012131{
Abhishek Singhb20db962017-03-03 21:28:46 +053012132}
12133#endif
12134
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012135void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12136 struct hdd_config *cfg)
12137{
12138 uint8_t i = 0;
12139
12140 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12141 if (!ie_whitelist->white_list)
12142 return;
12143
12144 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12145 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12146 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12147 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12148 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12149 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12150 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12151 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12152
12153 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12154 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12155 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12156}
12157
Abhishek Singh257a9482017-03-06 16:52:39 +053012158/**
12159 * hdd_update_scan_config - API to update scan configuration parameters
12160 * @hdd_ctx: HDD context
12161 *
12162 * Return: 0 if success else err
12163 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012164static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012165{
12166 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12167 struct scan_user_cfg scan_cfg;
12168 struct hdd_config *cfg = hdd_ctx->config;
12169 QDF_STATUS status;
12170
12171 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12172 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12173 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12174 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12175 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12176 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12177 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012178 /* convert to ms */
12179 scan_cfg.scan_cache_aging_time =
12180 cfg->scanAgingTimeout * 1000;
12181 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12182 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12183 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12184 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012185 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012186 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012187 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12188 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012189 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012190 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singh257a9482017-03-06 16:52:39 +053012191
Abhishek Singhb20db962017-03-03 21:28:46 +053012192 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012193 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012194
Abhishek Singh257a9482017-03-06 16:52:39 +053012195 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12196 if (status != QDF_STATUS_SUCCESS) {
12197 hdd_err("failed pmo psoc configuration");
12198 return -EINVAL;
12199 }
12200
12201 return 0;
12202}
Abhishek Singh257a9482017-03-06 16:52:39 +053012203
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012204static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012205{
12206 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12207 struct tdls_start_params tdls_cfg;
12208 struct tdls_user_config *config = &tdls_cfg.config;
12209 struct hdd_config *cfg = hdd_ctx->config;
12210 QDF_STATUS status;
12211
12212 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12213 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12214 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12215 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12216 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12217 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12218 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12219 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12220 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12221 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12222 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12223 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12224 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12225 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12226 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12227 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12228 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12229 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12230 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12231 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12232 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12233 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12234 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12235 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12236 (cfg->fEnableTDLSImplicitTrigger ?
12237 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12238 (cfg->fTDLSExternalControl ?
12239 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12240
12241 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12242 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12243 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12244 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012245 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012246 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012247 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12248 tdls_cfg.tdls_evt_cb_data = psoc;
12249 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12250 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12251 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012252 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12253 tdls_cfg.tdls_wmm_cb_data = psoc;
12254 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12255 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012256 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012257
12258 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12259 if (status != QDF_STATUS_SUCCESS) {
12260 hdd_err("failed pmo psoc configuration");
12261 return -EINVAL;
12262 }
12263
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012264 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012265 /* enable napier specific tdls data path */
12266 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012267
Frank Liud4b2fa02017-03-29 11:46:48 +080012268 return 0;
12269}
Frank Liud4b2fa02017-03-29 11:46:48 +080012270
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012271int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012272{
12273 int ret;
12274
12275 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012276 if (ret)
12277 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012278
Abhishek Singh257a9482017-03-06 16:52:39 +053012279 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012280 if (ret)
12281 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012282
Frank Liud4b2fa02017-03-29 11:46:48 +080012283 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012284 if (ret)
12285 return ret;
12286
12287 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012288
12289 return ret;
12290}
12291
Agrawal Ashish65634612016-08-18 13:24:32 +053012292/**
12293 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12294 * @mode : cfg80211 DFS mode
12295 *
12296 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12297 */
12298enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12299{
12300 switch (mode) {
12301 case DFS_MODE_ENABLE:
12302 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012303 case DFS_MODE_DISABLE:
12304 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012305 case DFS_MODE_DEPRIORITIZE:
12306 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012307 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012308 hdd_debug("ACS dfs mode is NONE");
12309 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012310 }
12311}
12312
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012313/**
12314 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12315 * @hddctx: pointer to hdd context
12316 * @set_value: enable/disable
12317 *
12318 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12319 * Host(even though it is duplicate). When Host send vendor command
12320 * disable,FW doesn't perform any action. Whenever any change in
12321 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12322 *
12323 * return - 0 on success, appropriate error values on failure.
12324 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012325int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012326{
12327 QDF_STATUS status;
12328
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012329 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012330 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012331
12332 if (!hddctx->config->goptimize_chan_avoid_event) {
12333 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12334 return -EINVAL;
12335 }
12336
12337 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12338 if (!QDF_IS_STATUS_SUCCESS(status)) {
12339 hdd_err("Failed to send chan avoid command to SME");
12340 return -EINVAL;
12341 }
12342 return 0;
12343}
Agrawal Ashish65634612016-08-18 13:24:32 +053012344
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012345/**
12346 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12347 * @value: value to set
12348 *
12349 * This function will set the passed value to roaming in progress flag.
12350 *
12351 * Return: None
12352 */
12353void hdd_set_roaming_in_progress(bool value)
12354{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012355 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012356
12357 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12358 if (!hdd_ctx) {
12359 hdd_err("HDD context is NULL");
12360 return;
12361 }
12362
12363 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012364 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012365}
12366
12367/**
12368 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012369 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012370 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012371 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012372 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012373bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012374{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012375 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012376 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012377
12378 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12379 if (!hdd_ctx) {
12380 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012381 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012382 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012383 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12384 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012385 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12386 hdd_ctx->roaming_in_progress);
12387
12388 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012389}
12390
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012391/**
12392 * hdd_is_connection_in_progress() - check if connection is in
12393 * progress
12394 * @session_id: session id
12395 * @reason: scan reject reason
12396 *
12397 * Go through each adapter and check if Connection is in progress
12398 *
12399 * Return: true if connection is in progress else false
12400 */
12401bool hdd_is_connection_in_progress(uint8_t *session_id,
12402 enum scan_reject_states *reason)
12403{
12404 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012405 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012406 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012407 QDF_STATUS status = 0;
12408 uint8_t sta_id = 0;
12409 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012410 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012411
12412 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12413 if (!hdd_ctx) {
12414 hdd_err("HDD context is NULL");
12415 return false;
12416 }
12417
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012418 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12419 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012420 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012421 if (!adapter)
12422 goto end;
12423
12424 hdd_info("Adapter with device mode %s(%d) exists",
12425 hdd_device_mode_to_string(adapter->device_mode),
12426 adapter->device_mode);
12427 if (((QDF_STA_MODE == adapter->device_mode)
12428 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12429 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12430 && (eConnectionState_Connecting ==
12431 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12432 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012433 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012434 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012435 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012436 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012437 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012438 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012439 }
12440 return true;
12441 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012442 /*
12443 * sme_neighbor_middle_of_roaming is for LFR2
12444 * hdd_is_roaming_in_progress is for LFR3
12445 */
12446 if (((QDF_STA_MODE == adapter->device_mode) &&
12447 sme_neighbor_middle_of_roaming(
12448 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012449 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012450 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012451 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012452 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012453 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012454 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012455 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012456 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012457 }
12458 return true;
12459 }
12460 if ((QDF_STA_MODE == adapter->device_mode) ||
12461 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12462 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12463 hdd_sta_ctx =
12464 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12465 if ((eConnectionState_Associated ==
12466 hdd_sta_ctx->conn_info.connState)
12467 && (false ==
12468 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12469 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070012470 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012471 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012472 " is in middle of WPS/EAPOL exchange.",
12473 MAC_ADDR_ARRAY(sta_mac));
12474 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012475 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012476 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012477 }
12478 return true;
12479 }
12480 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12481 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12482 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12483 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012484 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012485 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012486 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012487 continue;
12488
12489 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012490 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070012491 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012492 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012493 " of SAP/GO is in middle of WPS/EAPOL exchange",
12494 MAC_ADDR_ARRAY(sta_mac));
12495 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012496 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012497 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012498 }
12499 return true;
12500 }
12501 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012502 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012503 return true;
12504 }
12505 }
12506end:
12507 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12508 adapter_node = next;
12509 }
12510 return false;
12511}
12512
12513/**
12514 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012515 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012516 *
12517 * Return: None
12518 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012519void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012520{
Jeff Johnson87251032017-08-29 13:31:11 -070012521 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012522 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012523 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012524 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012525 tsap_Config_t *sap_config;
12526 void *sap_ctx;
12527
12528 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070012529 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012530 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012531
12532 mutex_lock(&hdd_ctx->sap_lock);
12533 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12534 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012535 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12536 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12537 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12538 qdf_status =
12539 qdf_wait_single_event(&hostapd_state->
12540 qdf_stop_bss_event,
12541 SME_CMD_TIMEOUT_VALUE);
12542
12543 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012544 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012545 goto end;
12546 }
12547 }
12548 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012549 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012550 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012551 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012552
12553 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012554 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012555 wlansap_reset_sap_config_add_ie(sap_config,
12556 eUPDATE_IE_ALL);
12557 goto end;
12558 }
12559
12560 qdf_event_reset(&hostapd_state->qdf_event);
12561 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12562 sap_config,
12563 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012564 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012565 wlansap_reset_sap_config_add_ie(sap_config,
12566 eUPDATE_IE_ALL);
12567 goto end;
12568 }
12569
Jeff Johnson6867ec32017-09-29 20:30:20 -070012570 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012571 qdf_status =
12572 qdf_wait_single_event(&hostapd_state->qdf_event,
12573 SME_CMD_TIMEOUT_VALUE);
12574 wlansap_reset_sap_config_add_ie(sap_config,
12575 eUPDATE_IE_ALL);
12576 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012577 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012578 goto end;
12579 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012580 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012581 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070012582 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012583 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12584 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012585 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012586 }
12587end:
12588 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012589}
12590
12591/**
12592 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12593 * with non dfs acs
12594 *
12595 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12596 *
12597 * Return: None
12598 */
12599void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12600{
Jeff Johnson9d295242017-08-29 14:39:48 -070012601 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012602 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012603 cds_context_type *cds_ctx;
12604
12605 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12606 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012607 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012608 return;
12609 }
12610
12611 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12612 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012613 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012614 return;
12615 }
12616
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012617 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12618 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012619 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012620 return;
12621 }
12622
12623 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012624 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12625 &ap_adapter->event_flags) &&
12626 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070012627 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012628
Jeff Johnson6867ec32017-09-29 20:30:20 -070012629 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070012630 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012631 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070012632 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012633 acs_cfg.acs_mode = true;
12634
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012635 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012636 }
12637}
12638
12639/**
12640 * hdd_set_connection_in_progress() - to set the connection in
12641 * progress flag
12642 * @value: value to set
12643 *
12644 * This function will set the passed value to connection in progress flag.
12645 * If value is previously being set to true then no need to set it again.
12646 *
12647 * Return: true if value is being set correctly and false otherwise.
12648 */
12649bool hdd_set_connection_in_progress(bool value)
12650{
12651 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012652 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012653
12654 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12655 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012656 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012657 return false;
12658 }
12659
12660 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12661 /*
12662 * if the value is set to true previously and if someone is
12663 * trying to make it true again then it could be some race
12664 * condition being triggered. Avoid this situation by returning
12665 * false
12666 */
12667 if (hdd_ctx->connection_in_progress && value)
12668 status = false;
12669 else
12670 hdd_ctx->connection_in_progress = value;
12671 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12672 return status;
12673}
12674
Jeff Johnson9d295242017-08-29 14:39:48 -070012675int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012676{
12677 if (!adapter) {
12678 hdd_err("Invalid adapter");
12679 return -EINVAL;
12680 }
12681 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070012682 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012683 WMA_VDEV_MCC_SET_TIME_QUOTA,
12684 set_value, VDEV_CMD);
12685 return 0;
12686
12687}
12688
Jeff Johnson9d295242017-08-29 14:39:48 -070012689int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012690{
12691 if (!adapter) {
12692 hdd_err("Invalid adapter");
12693 return -EINVAL;
12694 }
12695
12696 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070012697 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012698 WMA_VDEV_MCC_SET_TIME_LATENCY,
12699 set_value, VDEV_CMD);
12700 return 0;
12701}
12702
Jeff Johnson9d295242017-08-29 14:39:48 -070012703struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012704 *psoc, uint8_t vdev_id)
12705{
Jeff Johnson9d295242017-08-29 14:39:48 -070012706 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012707 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012708
12709 /*
12710 * Currently PSOC is not being used. But this logic will
12711 * change once we have the converged implementation of
12712 * HDD context per PSOC in place. This would break if
12713 * multiple vdev objects reuse the vdev id.
12714 */
12715 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12716 if (!adapter)
12717 hdd_err("Get adapter by vdev id failed");
12718
12719 return adapter;
12720}
12721
Jeff Johnson9d295242017-08-29 14:39:48 -070012722int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012723 int8_t *rssi, int8_t *snr)
12724{
12725 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012726 struct hdd_wext_state *wext_state =
12727 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012728 tCsrRoamProfile *profile = &wext_state->roamProfile;
12729
12730 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12731 profile, bssid, rssi, snr);
12732 if (QDF_STATUS_SUCCESS != status) {
12733 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12734 return -EINVAL;
12735 }
12736
12737 return 0;
12738}
12739
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012740/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012741 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12742 * @adapter - HDD adapter
12743 * @tos - type of service
12744 * @status - status of the traffic
12745 *
12746 * Return: 0 on success and non zero value on failure
12747 */
12748
12749int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12750 bool is_tos_active)
12751{
12752 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012753 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012754 uint32_t max_off_chan_time = 0;
12755 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012756 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012757 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012758
12759 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12760 ret = wlan_hdd_validate_context(hdd_ctx);
12761
12762 if (ret < 0) {
12763 hdd_err("failed to set limit off chan params");
12764 return ret;
12765 }
12766
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012767 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12768
12769 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012770 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012771 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012772 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012773
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012774 if (adapter->active_ac) {
12775 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012776 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012777 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12778 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12779 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012780 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012781 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012782 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12783 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12784 PM_LATENCY);
12785 } else {
12786 /*ignore this command if only BE/BK is active */
12787 is_tos_active = false;
12788 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12789 hdd_ctx->config->conc_system_pref);
12790 }
12791 } else {
12792 /* No active tos */
12793 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12794 hdd_ctx->config->conc_system_pref);
12795 }
12796
Jeff Johnson1b780e42017-10-31 14:11:45 -070012797 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012798 is_tos_active, max_off_chan_time,
12799 hdd_ctx->config->nRestTimeConc, true);
12800 if (!QDF_IS_STATUS_SUCCESS(status)) {
12801 hdd_err("failed to set limit off chan params");
12802 ret = -EINVAL;
12803 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012804
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012805 return ret;
12806}
12807
12808/**
12809 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
12810 * @adapter - HDD adapter
12811 *
12812 * Return: 0 on success and non zero value on failure
12813 */
12814int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
12815{
12816 struct hdd_context *hdd_ctx;
12817 int ret;
12818 QDF_STATUS status;
12819 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
12820
12821 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12822 ret = wlan_hdd_validate_context(hdd_ctx);
12823 if (ret < 0)
12824 return ret;
12825
12826 /* set the system preferece to default */
12827 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12828 hdd_ctx->config->conc_system_pref);
12829
12830 /* clear the bitmap */
12831 adapter->active_ac = 0;
12832
12833 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070012834 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012835
Jeff Johnson1b780e42017-10-31 14:11:45 -070012836 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012837 false, 0, 0, false);
12838 if (!QDF_IS_STATUS_SUCCESS(status)) {
12839 hdd_err("failed to reset limit off chan params");
12840 ret = -EINVAL;
12841 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012842
12843 return ret;
12844}
12845
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012846/**
12847 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12848 * @drv_op: Enum indicating driver op
12849 *
12850 * Return: none
12851 */
12852void hdd_start_driver_ops_timer(int drv_op)
12853{
12854 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12855 switch (drv_op) {
12856 case eHDD_DRV_OP_PROBE:
12857 memcpy(drv_ops_string, "probe", sizeof("probe"));
12858 break;
12859 case eHDD_DRV_OP_REMOVE:
12860 memcpy(drv_ops_string, "remove", sizeof("remove"));
12861 break;
12862 case eHDD_DRV_OP_SHUTDOWN:
12863 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12864 break;
12865 case eHDD_DRV_OP_REINIT:
12866 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12867 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053012868 case eHDD_DRV_OP_IFF_UP:
12869 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
12870 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012871 }
12872
12873 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12874 HDD_OPS_INACTIVITY_TIMEOUT);
12875}
12876
12877/**
12878 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12879 *
12880 * Return: none
12881 */
12882void hdd_stop_driver_ops_timer(void)
12883{
12884 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12885}
12886
12887/**
12888 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12889 * inactivity timer
12890 *
12891 * Return: None
12892 */
12893void hdd_drv_ops_inactivity_handler(void)
12894{
12895 hdd_err("%s: %d Sec timer expired while in .%s",
12896 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12897
12898 /* Driver shutdown is stuck, no recovery possible at this point */
12899 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12900 sizeof("shutdown")))
12901 QDF_BUG(0);
12902
12903 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012904 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012905 else
12906 QDF_BUG(0);
12907}
12908
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012909void hdd_pld_ipa_uc_shutdown_pipes(void)
12910{
12911 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12912
12913 if (!hdd_ctx)
12914 return;
12915
12916 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12917}
12918
Yun Parkff6a16a2017-09-26 16:38:18 -070012919/**
12920 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
12921 * @struct hdd_context *hdd_ctx
12922 * @struct hdd_adapter *padapter
12923 * @bool enble
12924 *
12925 * Return: none
12926 */
12927void hdd_set_rx_mode_rps(bool enable)
12928{
12929 struct cds_config_info *cds_cfg = cds_get_ini_config();
12930 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12931 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
12932
12933 if (adapter && hdd_ctx &&
12934 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
12935 if (enable && !cds_cfg->rps_enabled)
12936 hdd_send_rps_ind(adapter);
12937 else if (!enable && cds_cfg->rps_enabled)
12938 hdd_send_rps_disable_ind(adapter);
12939 }
12940}
12941
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012942/* Register the module init/exit functions */
12943module_init(hdd_module_init);
12944module_exit(hdd_module_exit);
12945
12946MODULE_LICENSE("Dual BSD/GPL");
12947MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12948MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12949
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012950module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12951 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012952
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012953module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12954 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12955
Ravi Joshia307f632017-07-17 23:41:41 -070012956module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12957 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12958
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012959module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12960 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12961
12962module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12963
12964module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12965
12966module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);