blob: e95f26b04c4b062e6a89b157eb118c3be9fe4de4 [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},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700267};
268
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530269int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
270 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
271 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
272 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
273 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
274};
275
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800276/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530277struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800278
279struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800280#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700281static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800282#endif
283
Sachin Ahujadddd2632017-03-07 19:07:24 +0530284void hdd_start_complete(int ret)
285{
286 wlan_start_ret_val = ret;
287
288 complete(&wlan_start_comp);
289}
290
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800291/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530292 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700293 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530294 *
295 * Return: none
296 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700297static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530298{
Jeff Johnson9d295242017-08-29 14:39:48 -0700299 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530300 hdd_adapter_list_node_t *adapter_node, *next;
301 QDF_STATUS status = QDF_STATUS_SUCCESS;
302
303 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
304 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -0700305 adapter = adapter_node->adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530306 if (NULL != adapter)
307 hdd_send_rps_ind(adapter);
308 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
309 adapter_node = next;
310 }
311}
312
313/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800314 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
315 * @vdev_id: vdev_id
316 * @action: action type
317 * @reason: reason type
318 *
319 * Return: none
320 */
321void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
322 enum netif_action_type action, enum netif_reason_type reason)
323{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700324 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700325 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800326
327 if (!hdd_ctx) {
328 hdd_err("hdd ctx is NULL");
329 return;
330 }
331 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
332
333 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800334}
335
336/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700337 * Store WLAN driver version and timestamp info in global variables such that
338 * crash debugger can extract them from driver debug symbol and crashdump for
339 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800340 */
341uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700342
343#ifndef BUILD_TIMESTAMP
344#define BUILD_TIMESTAMP ""
345#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700346uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
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:
541 if (true == adapter->isLinkUpSvcNeeded)
542 complete(&adapter->linkup_event_var);
543 break;
544
545 case NETDEV_GOING_DOWN:
546 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530547 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
548 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800549 } else {
hqueaa33ee2017-05-04 17:56:35 +0800550 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800551 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800552 }
553 break;
554
555 default:
556 break;
557 }
558
559 return NOTIFY_DONE;
560}
561
562/**
563 * hdd_netdev_notifier_call() - netdev notifier callback function
564 * @nb: pointer to notifier block
565 * @state: state
566 * @ndev: ndev pointer
567 *
568 * Return: 0 on success, error number otherwise.
569 */
570static int hdd_netdev_notifier_call(struct notifier_block *nb,
571 unsigned long state,
572 void *ndev)
573{
574 int ret;
575
576 cds_ssr_protect(__func__);
577 ret = __hdd_netdev_notifier_call(nb, state, ndev);
578 cds_ssr_unprotect(__func__);
579
580 return ret;
581}
582
583struct notifier_block hdd_netdev_notifier = {
584 .notifier_call = hdd_netdev_notifier_call,
585};
586
587/* variable to hold the insmod parameters */
588static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800589
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530590static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700591int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530592
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800593/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800594static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800595
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530596/**
597 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
598 * @ch_width: NL channel width
599 *
600 * Converts the NL channel width to the driver's internal representation
601 *
602 * Return: Converted channel width. In case of non matching NL channel width,
603 * CH_WIDTH_MAX will be returned.
604 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800605enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530606{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800607 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700608
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800609 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530610 switch (ch_width) {
611 case NL80211_CHAN_WIDTH_20_NOHT:
612 case NL80211_CHAN_WIDTH_20:
613 return CH_WIDTH_20MHZ;
614 case NL80211_CHAN_WIDTH_40:
615 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530616 case NL80211_CHAN_WIDTH_80:
617 return CH_WIDTH_80MHZ;
618 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800619 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
620 return CH_WIDTH_80P80MHZ;
621 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
622 return CH_WIDTH_160MHZ;
623 else
624 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530625 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800626 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
627 return CH_WIDTH_160MHZ;
628 else
629 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530630 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800631 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530632 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800633 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530634 default:
635 hdd_err("Invalid channel width %d, setting to default",
636 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800637 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530638 }
639}
640
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530641/* wlan_hdd_find_opclass() - Find operating class for a channel
642 * @hal: handler to HAL
643 * @channel: channel id
644 * @bw_offset: bandwidth offset
645 *
646 * Function invokes sme api to find the operating class
647 *
648 * Return: operating class
649 */
650uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
651 uint8_t bw_offset)
652{
653 uint8_t opclass = 0;
654
655 sme_get_opclass(hal, channel, bw_offset, &opclass);
656 return opclass;
657}
658
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800659/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530660 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530661 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800662 * @bitmask: Bitmask of log levels to be enabled
663 *
664 * Called immediately after the cfg.ini is read in order to configure
665 * the desired trace levels.
666 *
667 * Return: None
668 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530669int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800670{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530671 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530672 int qdf_print_idx = -1;
673 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800674 /*
675 * if the bitmask is the default value, then a bitmask was not
676 * specified in cfg.ini, so leave the logging level alone (it
677 * will remain at the "compiled in" default value)
678 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700679 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530680 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800681
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530682 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800683
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530684 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530685 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530686 QDF_TRACE_LEVEL_NONE, 0);
687
688 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530689 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800690 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530691 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800692 while (0 != bitmask) {
693 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530694 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530695 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530696 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530697 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800698 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700699
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800700 level++;
701 bitmask >>= 1;
702 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530703 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800704}
705
706/**
Chris Guo1751acf2017-07-03 14:09:01 +0800707 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
708 * @hdd_ctx: HDD context pointer
709 *
710 * Return: 0 if the context is valid. Error code otherwise
711 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700712int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800713{
714 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
715 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
716 return -ENODEV;
717 }
718
719 if (cds_is_driver_recovering()) {
720 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
721 (void *)_RET_IP_, cds_get_driver_state());
722 return -EAGAIN;
723 }
724
725 if (hdd_ctx->start_modules_in_progress ||
726 hdd_ctx->stop_modules_in_progress) {
727 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
728 (void *)_RET_IP_);
729 return -EAGAIN;
730 }
731
732 return 0;
733}
734
735
736/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800737 * wlan_hdd_validate_context() - check the HDD context
738 * @hdd_ctx: HDD context pointer
739 *
740 * Return: 0 if the context is valid. Error code otherwise
741 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700742int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800744 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530745 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746 return -ENODEV;
747 }
748
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800749 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800750 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530751 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800752 return -EAGAIN;
753 }
754
Yue Ma9f275d92017-09-14 16:58:41 -0700755 if (cds_is_load_or_unload_in_progress()) {
756 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
757 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700759 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530760
761 if (hdd_ctx->start_modules_in_progress ||
762 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800763 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530764 (void *)_RET_IP_);
765 return -EAGAIN;
766 }
767
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530768 if (cds_is_driver_in_bad_state()) {
769 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
770 (void *)_RET_IP_, cds_get_driver_state());
771 return -ENODEV;
772 }
773
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774 return 0;
775}
776
Jeff Johnson9d295242017-08-29 14:39:48 -0700777int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700778{
779 if (!adapter) {
780 hdd_err("adapter is null");
781 return -EINVAL;
782 }
783
784 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
785 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
786 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
787 return -EINVAL;
788 }
789
790 if (!adapter->dev) {
791 hdd_err("adapter net_device is null");
792 return -EINVAL;
793 }
794
795 if (!(adapter->dev->flags & IFF_UP)) {
796 hdd_info("adapter net_device is not up");
797 return -EAGAIN;
798 }
799
800 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
801 hdd_info("adapter session is not open");
802 return -EAGAIN;
803 }
804
805 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
806 hdd_err("bad adapter session Id: %u", adapter->sessionId);
807 return -EINVAL;
808 }
809
810 return 0;
811}
812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800813/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530814 * wlan_hdd_validate_modules_state() - Check modules status
815 * @hdd_ctx: HDD context pointer
816 *
817 * Check's the driver module's state and returns true if the
818 * modules are enabled returns false if modules are closed.
819 *
820 * Return: True if modules are enabled or false.
821 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700822bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530823{
824 mutex_lock(&hdd_ctx->iface_change_lock);
825 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
826 mutex_unlock(&hdd_ctx->iface_change_lock);
827 hdd_notice("Modules not enabled, Present status: %d",
828 hdd_ctx->driver_status);
829 return false;
830 }
831 mutex_unlock(&hdd_ctx->iface_change_lock);
832 return true;
833}
834
835/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800836 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700837 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838 *
839 * This function sets the IBSS power save config parameters to WMA
840 * which will send it to firmware if FW supports IBSS power save
841 * before vdev start.
842 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530843 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800844 * on failure.
845 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700846QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847{
848 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700849 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850
851 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700852 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530853 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 }
855
Naveen Rawat247a8682017-06-05 15:00:31 -0700856 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
858 hdd_ctx->config->ibssATIMWinSize,
859 VDEV_CMD);
860 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700861 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530862 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 }
864
Naveen Rawat247a8682017-06-05 15:00:31 -0700865 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
867 hdd_ctx->config->isIbssPowerSaveAllowed,
868 VDEV_CMD);
869 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700870 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
871 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530872 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873 }
874
Naveen Rawat247a8682017-06-05 15:00:31 -0700875 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
877 hdd_ctx->config->
878 isIbssPowerCollapseAllowed, VDEV_CMD);
879 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700880 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
881 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530882 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800883 }
884
Naveen Rawat247a8682017-06-05 15:00:31 -0700885 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
887 hdd_ctx->config->isIbssAwakeOnTxRx,
888 VDEV_CMD);
889 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700890 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530891 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892 }
893
Naveen Rawat247a8682017-06-05 15:00:31 -0700894 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800895 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
896 hdd_ctx->config->ibssInactivityCount,
897 VDEV_CMD);
898 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700899 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530900 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 }
902
Naveen Rawat247a8682017-06-05 15:00:31 -0700903 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
905 hdd_ctx->config->ibssTxSpEndInactivityTime,
906 VDEV_CMD);
907 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700908 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
909 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530910 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 }
912
Naveen Rawat247a8682017-06-05 15:00:31 -0700913 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
915 hdd_ctx->config->ibssPsWarmupTime,
916 VDEV_CMD);
917 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700918 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
919 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530920 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 }
922
Naveen Rawat247a8682017-06-05 15:00:31 -0700923 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
925 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
926 VDEV_CMD);
927 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700928 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
929 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530930 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800931 }
932
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530933 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800934}
935
Yue Macd359b72017-10-03 15:21:00 -0700936#ifdef FEATURE_RUNTIME_PM
937/**
938 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
939 * @hdd_ctx: HDD context
940 *
941 * Return: None
942 */
943static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
944{
945 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
946
Yue Macd359b72017-10-03 15:21:00 -0700947 qdf_runtime_lock_init(&ctx->dfs);
948
949 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
950}
951
952/**
953 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
954 * @hdd_ctx: HDD Context
955 *
956 * Return: None
957 */
958static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
959{
960 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
961
Yue Macd359b72017-10-03 15:21:00 -0700962 qdf_runtime_lock_deinit(&ctx->dfs);
963
964 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
965}
966
967static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
968{
969 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
970
971 qdf_runtime_lock_init(&ctx->connect);
972}
973
974static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
975{
976 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
977
978 qdf_runtime_lock_deinit(&ctx->connect);
979}
980#else /* FEATURE_RUNTIME_PM */
981static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
982static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
983static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
984static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
985#endif /* FEATURE_RUNTIME_PM */
986
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800987#define INTF_MACADDR_MASK 0x7
988
989/**
990 * hdd_update_macaddr() - update mac address
991 * @config: hdd configuration
992 * @hw_macaddr: mac address
993 *
994 * Mac address for multiple virtual interface is found as following
995 * i) The mac address of the first interface is just the actual hw mac address.
996 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
997 * define the mac address for the remaining interfaces and locally
998 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
999 * supported virtual interfaces, right now this is 0x07 (meaning 8
1000 * interface).
1001 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1002 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1003 *
1004 * Return: None
1005 */
1006void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301007 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001008{
1009 int8_t i;
1010 uint8_t macaddr_b3, tmp_br3;
1011
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301012 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301013 QDF_MAC_ADDR_SIZE);
1014 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301015 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301016 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001017 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1018 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1019 INTF_MACADDR_MASK;
1020 macaddr_b3 += tmp_br3;
1021
1022 /* XOR-ing bit-24 of the mac address. This will give enough
1023 * mac address range before collision
1024 */
1025 macaddr_b3 ^= (1 << 7);
1026
1027 /* Set locally administered bit */
1028 config->intfMacAddr[i].bytes[0] |= 0x02;
1029 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001030 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001031 MAC_ADDRESS_STR, i,
1032 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1033 }
1034}
1035
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001036static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037 struct wma_tgt_services *cfg)
1038{
1039 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040
1041 /* Set up UAPSD */
1042 config->apUapsdEnabled &= cfg->uapsd;
1043
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001044 /* 11AX mode support */
1045 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1046 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1047 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1048
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001049 /* 11AC mode support */
1050 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1051 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1052 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001053
1054 /* ARP offload: override user setting if invalid */
1055 config->fhostArpOffload &= cfg->arp_offload;
1056
1057#ifdef FEATURE_WLAN_SCAN_PNO
1058 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001059 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001060 if (cfg->pno_offload)
1061 config->PnoOffload = true;
1062#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063#ifdef FEATURE_WLAN_TDLS
1064 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301065 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1066 cfg->en_tdls_offchan;
1067 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1068 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001069 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001071 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001072 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1075 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1076#endif
Will Huang496b36c2017-07-11 16:38:50 +08001077 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001078 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001079 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080
1081}
1082
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001083/**
1084 * hdd_update_vdev_nss() - sets the vdev nss
1085 * @hdd_ctx: HDD context
1086 *
1087 * Sets the Nss per vdev type based on INI
1088 *
1089 * Return: None
1090 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001091static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001092{
1093 struct hdd_config *cfg_ini = hdd_ctx->config;
1094 uint8_t max_supp_nss = 1;
1095
Naveen Rawat10b1c152017-01-18 11:16:06 -08001096 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001097 max_supp_nss = 2;
1098
1099 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1100 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1101
1102 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1103 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1104}
1105
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301106/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301107 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1108 * @hdd_ctx: HDD context
1109 *
1110 * Updates wiphy vhtcap fields
1111 *
1112 * Return: None
1113 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001114static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301115{
1116 struct ieee80211_supported_band *band_5g =
1117 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1118 uint32_t val;
1119
1120 if (!band_5g) {
1121 hdd_debug("5GHz band disabled, skipping capability population");
1122 return;
1123 }
1124
1125 val = hdd_ctx->config->txBFCsnValue;
1126 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1127
1128 val = NUM_OF_SOUNDING_DIMENSIONS;
1129 band_5g->vht_cap.cap |=
1130 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1131
1132 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1133 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1134}
1135
1136/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301137 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1138 * @hdd_ctx: HDD context
1139 *
1140 * Sets the DBS capability as per INI and firmware capability
1141 *
1142 * Return: None
1143 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001144static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301145{
1146 struct hdd_config *cfg_ini = hdd_ctx->config;
1147 uint8_t hw_dbs_capable = 0;
1148
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001149 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1150 ((cfg_ini->dual_mac_feature_disable ==
1151 ENABLE_DBS_CXN_AND_SCAN) ||
1152 (cfg_ini->dual_mac_feature_disable ==
1153 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301154 hw_dbs_capable = 1;
1155
1156 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1157}
1158
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001159static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001160 struct wma_tgt_ht_cap *cfg)
1161{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301162 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163 uint32_t value, val32;
1164 uint16_t val16;
1165 struct hdd_config *pconfig = hdd_ctx->config;
1166 tSirMacHTCapabilityInfo *phtCapInfo;
1167 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1168 uint8_t enable_tx_stbc;
1169
1170 /* check and update RX STBC */
1171 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1172 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1173
1174 /* get the MPDU density */
1175 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1176
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301177 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001178 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001179 value = 0;
1180 }
1181
1182 /*
1183 * MPDU density:
1184 * override user's setting if value is larger
1185 * than the one supported by target
1186 */
1187 if (value > cfg->mpdu_density) {
1188 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1189 cfg->mpdu_density);
1190
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301191 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001192 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193 }
1194
1195 /* get the HT capability info */
1196 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301197 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001198 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199 return;
1200 }
1201 val16 = (uint16_t) val32;
1202 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1203
1204 /* Set the LDPC capability */
1205 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1206
1207 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1208 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1209
1210 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1211 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1212
1213 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1214 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1215
1216 enable_tx_stbc = pconfig->enableTxSTBC;
1217
1218 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1219 pconfig->enable2x2 = 1;
1220 } else {
1221 pconfig->enable2x2 = 0;
1222 enable_tx_stbc = 0;
1223
1224 /* 1x1 */
1225 /* Update Rx Highest Long GI data Rate */
1226 if (sme_cfg_set_int(hdd_ctx->hHal,
1227 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001228 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301229 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001230 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001231 }
1232
1233 /* Update Tx Highest Long GI data Rate */
1234 if (sme_cfg_set_int
1235 (hdd_ctx->hHal,
1236 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001237 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301238 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001239 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240 }
1241 }
1242 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1243 enable_tx_stbc = 0;
1244 phtCapInfo->txSTBC = enable_tx_stbc;
1245
1246 val32 = val16;
1247 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301248 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001249 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001250#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1251 value = SIZE_OF_SUPPORTED_MCS_SET;
1252 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301253 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001254 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001255
1256 if (pconfig->enable2x2) {
1257 for (value = 0; value < cfg->num_rf_chains; value++)
1258 mcs_set[value] =
1259 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1260
1261 status =
1262 sme_cfg_set_str(hdd_ctx->hHal,
1263 WNI_CFG_SUPPORTED_MCS_SET,
1264 mcs_set,
1265 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301266 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001267 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001268 }
1269 }
1270#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1271}
1272
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001273static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001274 struct wma_tgt_vht_cap *cfg)
1275{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301276 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001277 uint32_t value = 0;
1278 struct hdd_config *pconfig = hdd_ctx->config;
1279 struct wiphy *wiphy = hdd_ctx->wiphy;
1280 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001281 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001282 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001283 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001284 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001285
Dustin Brown5e06bd32016-10-04 12:49:10 -07001286 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001287 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001288 return;
1289 }
1290
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001291 /* Get the current MPDU length */
1292 status =
1293 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1294 &value);
1295
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301296 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001297 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001298 value = 0;
1299 }
1300
1301 /*
1302 * VHT max MPDU length:
1303 * override if user configured value is too high
1304 * that the target cannot support
1305 */
1306 if (value > cfg->vht_max_mpdu) {
1307 status = sme_cfg_set_int(hdd_ctx->hHal,
1308 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1309 cfg->vht_max_mpdu);
1310
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001311 if (status == QDF_STATUS_E_FAILURE)
1312 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313 }
1314
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001315 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1316 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1317
1318 if (pconfig->enable2x2)
1319 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1320
1321 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1322 QDF_STATUS_E_FAILURE) {
1323 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1324 }
1325
1326 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1327 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1328 if (pconfig->enable2x2)
1329 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1330
1331 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1332 QDF_STATUS_E_FAILURE) {
1333 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1334 }
1335
1336 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1337 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1338 if (pconfig->enable2x2)
1339 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1340
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001341 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001342 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1343
1344 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1345 QDF_STATUS_E_FAILURE) {
1346 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1347 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001348 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001349 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001350 &value);
1351
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301352 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001353 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 value = 0;
1355 }
1356
jiad4a7a33c2017-08-08 15:32:24 +08001357 /* Set HW RX LDPC capability */
1358 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1359 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 status = sme_cfg_set_int(hdd_ctx->hHal,
1361 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001362 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001364 if (status == QDF_STATUS_E_FAILURE)
1365 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366 }
1367
1368 /* Get current GI 80 value */
1369 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1370 &value);
1371
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301372 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001373 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 value = 0;
1375 }
1376
1377 /* set the Guard interval 80MHz */
1378 if (value && !cfg->vht_short_gi_80) {
1379 status = sme_cfg_set_int(hdd_ctx->hHal,
1380 WNI_CFG_VHT_SHORT_GI_80MHZ,
1381 cfg->vht_short_gi_80);
1382
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001383 if (status == QDF_STATUS_E_FAILURE)
1384 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385 }
1386
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387 /* Get VHT TX STBC cap */
1388 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1389
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301390 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001391 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001392 value = 0;
1393 }
1394
1395 /* VHT TX STBC cap */
1396 if (value && !cfg->vht_tx_stbc) {
1397 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1398 cfg->vht_tx_stbc);
1399
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001400 if (status == QDF_STATUS_E_FAILURE)
1401 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402 }
1403
1404 /* Get VHT RX STBC cap */
1405 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1406
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301407 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001408 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001409 value = 0;
1410 }
1411
1412 /* VHT RX STBC cap */
1413 if (value && !cfg->vht_rx_stbc) {
1414 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1415 cfg->vht_rx_stbc);
1416
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001417 if (status == QDF_STATUS_E_FAILURE)
1418 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001419 }
1420
1421 /* Get VHT SU Beamformer cap */
1422 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1423 &value);
1424
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301425 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001426 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001427 value = 0;
1428 }
1429
1430 /* set VHT SU Beamformer cap */
1431 if (value && !cfg->vht_su_bformer) {
1432 status = sme_cfg_set_int(hdd_ctx->hHal,
1433 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1434 cfg->vht_su_bformer);
1435
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001436 if (status == QDF_STATUS_E_FAILURE)
1437 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001438 }
1439
1440 /* check and update SU BEAMFORMEE capabality */
1441 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1442 pconfig->enableTxBF = cfg->vht_su_bformee;
1443
1444 status = sme_cfg_set_int(hdd_ctx->hHal,
1445 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1446 pconfig->enableTxBF);
1447
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001448 if (status == QDF_STATUS_E_FAILURE)
1449 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001450
1451 /* Get VHT MU Beamformer cap */
1452 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1453 &value);
1454
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301455 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001456 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001457 value = 0;
1458 }
1459
1460 /* set VHT MU Beamformer cap */
1461 if (value && !cfg->vht_mu_bformer) {
1462 status = sme_cfg_set_int(hdd_ctx->hHal,
1463 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1464 cfg->vht_mu_bformer);
1465
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001466 if (status == QDF_STATUS_E_FAILURE)
1467 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 }
1469
1470 /* Get VHT MU Beamformee cap */
1471 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1472 &value);
1473
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301474 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001475 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001476 value = 0;
1477 }
1478
1479 /* set VHT MU Beamformee cap */
1480 if (value && !cfg->vht_mu_bformee) {
1481 status = sme_cfg_set_int(hdd_ctx->hHal,
1482 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1483 cfg->vht_mu_bformee);
1484
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001485 if (status == QDF_STATUS_E_FAILURE)
1486 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001487 }
1488
1489 /* Get VHT MAX AMPDU Len exp */
1490 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1491 &value);
1492
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301493 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001494 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001495 value = 0;
1496 }
1497
1498 /*
1499 * VHT max AMPDU len exp:
1500 * override if user configured value is too high
1501 * that the target cannot support.
1502 * Even though Rome publish ampdu_len=7, it can
1503 * only support 4 because of some h/w bug.
1504 */
1505
1506 if (value > cfg->vht_max_ampdu_len_exp) {
1507 status = sme_cfg_set_int(hdd_ctx->hHal,
1508 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1509 cfg->vht_max_ampdu_len_exp);
1510
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001511 if (status == QDF_STATUS_E_FAILURE)
1512 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001513 }
1514
1515 /* Get VHT TXOP PS CAP */
1516 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1517
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301518 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001519 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001520 value = 0;
1521 }
1522
1523 /* set VHT TXOP PS cap */
1524 if (value && !cfg->vht_txop_ps) {
1525 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1526 cfg->vht_txop_ps);
1527
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001528 if (status == QDF_STATUS_E_FAILURE)
1529 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001530 }
1531
1532 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1533 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1534 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1535 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1536 else
1537 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1538
1539
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001540 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1541 status = sme_cfg_set_int(hdd_ctx->hHal,
1542 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1543 VHT_CAP_160_AND_80P80_SUPP);
1544 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001545 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001546 band_5g->vht_cap.cap |=
1547 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001548 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1549 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1550 status = sme_cfg_set_int(hdd_ctx->hHal,
1551 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1552 VHT_CAP_160_SUPP);
1553 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001554 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555 band_5g->vht_cap.cap |=
1556 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001557 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1558 }
1559 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1560 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301561 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001562 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301563 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001564 &value);
1565 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301566 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001567 value = 0;
1568 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301569 /* set the Guard interval 160MHz */
1570 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001571 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301572 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1573 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001574
1575 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301576 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001577 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001578
1579 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1580 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1581
1582 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1583 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1584 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1585 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1586
1587 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1588 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1589
1590 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1591 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1592 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1593 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1594 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1595 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1596
1597 band_5g->vht_cap.cap |=
1598 (cfg->vht_max_ampdu_len_exp <<
1599 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1600
1601 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1602 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1603 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1604 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1605 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1606 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1607 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1608 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1609
1610 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1611 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1612
1613}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001615/**
1616 * hdd_generate_macaddr_auto() - Auto-generate mac address
1617 * @hdd_ctx: Pointer to the HDD context
1618 *
1619 * Auto-generate mac address using device serial number.
1620 * Keep the first 3 bytes of OUI as before and replace
1621 * the last 3 bytes with the lower 3 bytes of serial number.
1622 *
1623 * Return: 0 for success
1624 * Non zero failure code for errors
1625 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001626static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001627{
1628 unsigned int serialno = 0;
1629 struct qdf_mac_addr mac_addr = {
1630 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1631 };
1632
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001633 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001634 if (serialno == 0)
1635 return -EINVAL;
1636
1637 serialno &= 0x00ffffff;
1638
1639 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1640 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1641 mac_addr.bytes[5] = serialno & 0xff;
1642
1643 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1644 return 0;
1645}
1646
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301647/**
1648 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1649 * configuration to cfg_ini in HDD
1650 * @hdd_ctx: Pointer to hdd_ctx
1651 * @cfg: target configuration
1652 *
1653 * Return: None
1654 */
1655#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001656static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301657 struct wma_tgt_cfg *cfg)
1658{
1659 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1660}
1661#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001662static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301663 struct wma_tgt_cfg *cfg)
1664{
1665}
1666#endif
1667
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001668void hdd_update_tgt_cfg(void *context, void *param)
1669{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001670 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001671 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001672 struct wma_tgt_cfg *cfg = param;
1673 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001674 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301675 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301676
Yue Mae3e86ab2017-05-08 10:48:24 -07001677 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301678 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1679 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1680 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1681 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1682 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001683 /* Restore pdev to MAC/WMA contexts */
1684 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001685 } else {
1686 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1687 if (ret) {
1688 hdd_err("pdev creation fails!");
1689 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301690 } else
1691 hdd_debug("New pdev has been created with pdev_id = %u",
1692 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301693 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001694
Naveen Rawat64e477e2016-05-20 10:34:56 -07001695 if (cds_cfg) {
1696 if (hdd_ctx->config->enable_sub_20_channel_width !=
1697 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1698 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1699 cds_cfg->sub_20_channel_width =
1700 WLAN_SUB_20_CH_WIDTH_NONE;
1701 } else {
1702 cds_cfg->sub_20_channel_width =
1703 hdd_ctx->config->enable_sub_20_channel_width;
1704 }
1705 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001706
1707 /* first store the INI band capability */
1708 temp_band_cap = hdd_ctx->config->nBandCapability;
1709
1710 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301711 hdd_ctx->is_fils_roaming_supported =
1712 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001713
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001714 /*
1715 * now overwrite the target band capability with INI
1716 * setting if INI setting is a subset
1717 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001718
1719 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1720 (temp_band_cap != eCSR_BAND_ALL))
1721 hdd_ctx->config->nBandCapability = temp_band_cap;
1722 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1723 (temp_band_cap != eCSR_BAND_ALL) &&
1724 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001725 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001726 }
1727
Amar Singhal58b45ef2017-08-01 13:43:54 -07001728 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1729
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301730 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001731 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1732 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1733 }
1734
1735 /* This can be extended to other configurations like ht, vht cap... */
1736
Anurag Chouhanc5548422016-02-24 18:33:27 +05301737 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001739 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001740 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001741 static struct qdf_mac_addr default_mac_addr = {
1742 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1743 };
1744 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1745 &default_mac_addr)) {
1746 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1747 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1748 MAC_ADDRESS_STR,
1749 MAC_ADDR_ARRAY(hdd_ctx->config->
1750 intfMacAddr[0].bytes));
1751 } else {
1752 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1753 MAC_ADDRESS_STR,
1754 MAC_ADDR_ARRAY(hdd_ctx->config->
1755 intfMacAddr[0].bytes));
1756 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001757 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001758 }
1759
1760 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001761 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001762
1763 hdd_ctx->max_intf_count = cfg->max_intf_count;
1764
Jeff Johnsonc875e242016-09-23 18:12:34 -07001765 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001766 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001767
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001768 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1769 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1770
1771 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1772
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001773 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001774 if (cfg->services.en_11ax) {
1775 hdd_info("11AX: 11ax is enabled - update HDD config");
1776 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1777 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001778
1779 hdd_update_vdev_nss(hdd_ctx);
1780
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301781 hdd_update_hw_dbs_capable(hdd_ctx);
1782
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001783 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001784 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001785 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001786 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001787
Nitesh Shahe50711f2017-04-26 16:30:45 +05301788 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1789 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1790 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001791 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001792 hdd_ctx->current_antenna_mode);
1793
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001794 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1795 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301796 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301797
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301798 if ((hdd_ctx->config->txBFCsnValue >
1799 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1800 !cfg->tx_bfee_8ss_enabled)
1801 hdd_ctx->config->txBFCsnValue =
1802 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1803
1804 if (sme_cfg_set_int(hdd_ctx->hHal,
1805 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1806 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1807 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1808
1809
1810 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1811 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1812 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301813
1814 /*
1815 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1816 */
1817 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301818
1819 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1820
Arun Khandavallid454d422016-08-17 12:47:05 +05301821 /*
1822 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1823 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1824 * configure the STA mode wow pattern.
1825 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301826 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301827 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301828
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301829 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1830
Yue Macd359b72017-10-03 15:21:00 -07001831 /*
1832 * This needs to be done after HDD pdev is created and stored since
1833 * it will access the HDD pdev object lock.
1834 */
1835 hdd_runtime_suspend_context_init(hdd_ctx);
1836
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001837 /* Configure NAN datapath features */
1838 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001839 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840}
1841
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001842bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001843{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001844 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001845 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301846 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001847 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001848
Arif Hussaincd151632017-02-11 16:57:19 -08001849 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001850 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001851 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301852 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001853 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001854
Arif Hussaincd151632017-02-11 16:57:19 -08001855 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1856 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001857 adapter = adapterNode->adapter;
Arif Hussaincd151632017-02-11 16:57:19 -08001858 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1859
1860 if ((QDF_SAP_MODE == adapter->device_mode ||
1861 QDF_P2P_GO_MODE == adapter->device_mode) &&
1862 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1863 ap_ctx->operatingChannel))) {
1864 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1865 true;
1866 hdd_info("tx blocked for session: %d",
1867 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301868 }
Arif Hussaincd151632017-02-11 16:57:19 -08001869 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1870 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001871 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301872
1873 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001874}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001875
1876/**
1877 * hdd_is_valid_mac_address() - validate MAC address
1878 * @pMacAddr: Pointer to the input MAC address
1879 *
1880 * This function validates whether the given MAC address is valid or not
1881 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1882 * where X is the hexa decimal digit character and separated by ':'
1883 * This algorithm works even if MAC address is not separated by ':'
1884 *
1885 * This code checks given input string mac contains exactly 12 hexadecimal
1886 * digits and a separator colon : appears in the input string only after
1887 * an even number of hex digits.
1888 *
1889 * Return: 1 for valid and 0 for invalid
1890 */
1891bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1892{
1893 int xdigit = 0;
1894 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001895
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001896 while (*pMacAddr) {
1897 if (isxdigit(*pMacAddr)) {
1898 xdigit++;
1899 } else if (':' == *pMacAddr) {
1900 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1901 break;
1902
1903 ++separator;
1904 } else {
1905 /* Invalid MAC found */
1906 return 0;
1907 }
1908 ++pMacAddr;
1909 }
1910 return xdigit == 12 && (separator == 5 || separator == 0);
1911}
1912
1913/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301914 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1915 * @dev: Handle to struct net_device to be updated.
1916 *
1917 * Return: None
1918 */
1919static void hdd_mon_mode_ether_setup(struct net_device *dev)
1920{
1921 dev->header_ops = NULL;
1922 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1923 dev->hard_header_len = ETH_HLEN;
1924 dev->mtu = ETH_DATA_LEN;
1925 dev->addr_len = ETH_ALEN;
1926 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1927 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1928 dev->priv_flags |= IFF_TX_SKB_SHARING;
1929
1930 memset(dev->broadcast, 0xFF, ETH_ALEN);
1931}
1932
1933/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001934 * __hdd__mon_open() - HDD Open function
1935 * @dev: Pointer to net_device structure
1936 *
1937 * This is called in response to ifconfig up
1938 *
1939 * Return: 0 for success; non-zero for failure
1940 */
1941static int __hdd_mon_open(struct net_device *dev)
1942{
1943 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001944 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1945 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001946
1947 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001948
1949 ret = wlan_hdd_validate_context(hdd_ctx);
1950 if (ret)
1951 return ret;
1952
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301953 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001954
1955 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1956 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1957 if (ret) {
1958 hdd_err("Failed to start WLAN modules return");
1959 return ret;
1960 }
1961 hdd_err("hdd_wlan_start_modules() successful !");
1962
1963 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1964 ret = hdd_start_adapter(adapter);
1965 if (ret) {
1966 hdd_err("Failed to start adapter :%d",
1967 adapter->device_mode);
1968 return ret;
1969 }
1970 hdd_err("hdd_start_adapters() successful !");
1971 }
1972 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1973 }
1974
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001975 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001976
1977 if (!ret)
1978 ret = hdd_enable_monitor_mode(dev);
1979
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001980 return ret;
1981}
1982
1983/**
1984 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1985 * @dev: Pointer to net_device structure
1986 *
1987 * This is called in response to ifconfig up
1988 *
1989 * Return: 0 for success; non-zero for failure
1990 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001991static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001992{
1993 int ret;
1994
1995 cds_ssr_protect(__func__);
1996 ret = __hdd_mon_open(dev);
1997 cds_ssr_unprotect(__func__);
1998
1999 return ret;
2000}
2001
2002/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302003 * hdd_start_adapter() - Wrapper function for device specific adapter
2004 * @adapter: pointer to HDD adapter
2005 *
2006 * This function is called to start the device specific adapter for
2007 * the mode passed in the adapter's device_mode.
2008 *
2009 * Return: 0 for success; non-zero for failure
2010 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002011int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302012{
2013
2014 int ret;
2015 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
2016
2017 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002018 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302019
2020 switch (device_mode) {
2021 case QDF_P2P_CLIENT_MODE:
2022 case QDF_P2P_DEVICE_MODE:
2023 case QDF_OCB_MODE:
2024 case QDF_STA_MODE:
2025 case QDF_MONITOR_MODE:
2026 ret = hdd_start_station_adapter(adapter);
2027 if (ret)
2028 goto err_start_adapter;
2029 break;
2030 case QDF_P2P_GO_MODE:
2031 case QDF_SAP_MODE:
2032 ret = hdd_start_ap_adapter(adapter);
2033 if (ret)
2034 goto err_start_adapter;
2035 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302036 case QDF_IBSS_MODE:
2037 /*
2038 * For IBSS interface is initialized as part of
2039 * hdd_init_station_mode()
2040 */
2041 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302042 case QDF_FTM_MODE:
2043 ret = hdd_start_ftm_adapter(adapter);
2044 if (ret)
2045 goto err_start_adapter;
2046 break;
2047 default:
2048 hdd_err("Invalid session type %d", device_mode);
2049 QDF_ASSERT(0);
2050 goto err_start_adapter;
2051 }
2052 if (hdd_set_fw_params(adapter))
2053 hdd_err("Failed to set the FW params for the adapter!");
2054
2055 /*
2056 * Action frame registered in one adapter which will
2057 * applicable to all interfaces
2058 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302059 ret = wlan_hdd_cfg80211_register_frames(adapter);
2060 if (ret < 0) {
2061 hdd_err("Failed to register frames - ret %d", ret);
2062 goto err_start_adapter;
2063 }
2064
Arun Khandavallifae92942016-08-01 13:31:08 +05302065 EXIT();
2066 return 0;
2067err_start_adapter:
2068 return -EINVAL;
2069}
2070
2071/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302072 * hdd_enable_power_management() - API to Enable Power Management
2073 *
2074 * API invokes Bus Interface Layer power management functionality
2075 *
2076 * Return: None
2077 */
2078static void hdd_enable_power_management(void)
2079{
2080 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2081
2082 if (!hif_ctx) {
2083 hdd_err("Bus Interface Context is Invalid");
2084 return;
2085 }
2086
2087 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2088}
2089
2090/**
2091 * hdd_disable_power_management() - API to disable Power Management
2092 *
2093 * API disable Bus Interface Layer Power management functionality
2094 *
2095 * Return: None
2096 */
2097static void hdd_disable_power_management(void)
2098{
2099 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2100
2101 if (!hif_ctx) {
2102 hdd_err("Bus Interface Context is Invalid");
2103 return;
2104 }
2105
2106 hif_disable_power_management(hif_ctx);
2107}
2108
2109/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302110 * hdd_update_hw_sw_info() - API to update the HW/SW information
2111 *
2112 * API to update the HW and SW information in the driver
2113 *
2114 * Return: None
2115 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002116static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302117{
2118 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002119 size_t target_hw_name_len;
2120 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302121
2122 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2123 if (!hif_sc) {
2124 hdd_err("HIF context is NULL");
2125 return;
2126 }
2127
2128 /*
2129 * target hw version/revision would only be retrieved after firmware
2130 * download
2131 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002132 hif_get_hw_info(hif_sc,
2133 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302134 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002135 &target_hw_name);
2136
2137 if (hdd_ctx->target_hw_name)
2138 qdf_mem_free(hdd_ctx->target_hw_name);
2139
2140 target_hw_name_len = strlen(target_hw_name) + 1;
2141 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2142 if (hdd_ctx->target_hw_name)
2143 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2144 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302145
2146 /* Get the wlan hw/fw version */
2147 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302148}
2149
2150/**
gbian62edd7e2017-03-07 13:12:13 +08002151 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2152 * @hdd_ctx: Pointer to hdd context
2153 *
2154 * Return: none
2155 */
2156static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002157hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002158{
2159 uint8_t num_entries = 0;
2160 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2161 uint8_t *tx_sched_wrr_ac;
2162 int i;
2163 cds_context_type *cds_ctx;
2164
2165 if (NULL == hdd_ctx)
2166 return;
2167
2168 if (NULL == hdd_ctx->config) {
2169 /* Do nothing if hdd_ctx is invalid */
2170 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2171 return;
2172 }
2173
2174 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2175
2176 if (!cds_ctx) {
2177 hdd_err("Invalid CDS Context");
2178 return;
2179 }
2180
2181 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2182 switch (i) {
2183 case OL_TX_WMM_AC_BE:
2184 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2185 break;
2186 case OL_TX_WMM_AC_BK:
2187 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2188 break;
2189 case OL_TX_WMM_AC_VI:
2190 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2191 break;
2192 case OL_TX_WMM_AC_VO:
2193 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2194 break;
2195 default:
2196 tx_sched_wrr_ac = NULL;
2197 break;
2198 }
2199
2200 hdd_string_to_u8_array(tx_sched_wrr_ac,
2201 tx_sched_wrr_param,
2202 &num_entries,
2203 sizeof(tx_sched_wrr_param));
2204
2205 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2206 cds_ctx->ac_specs[i].wrr_skip_weight =
2207 tx_sched_wrr_param[0];
2208 cds_ctx->ac_specs[i].credit_threshold =
2209 tx_sched_wrr_param[1];
2210 cds_ctx->ac_specs[i].send_limit =
2211 tx_sched_wrr_param[2];
2212 cds_ctx->ac_specs[i].credit_reserve =
2213 tx_sched_wrr_param[3];
2214 cds_ctx->ac_specs[i].discard_weight =
2215 tx_sched_wrr_param[4];
2216 }
2217
2218 num_entries = 0;
2219 }
2220}
2221
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002222#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002223static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2224 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2225{
Jeff Johnson9d295242017-08-29 14:39:48 -07002226 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002227 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002228
2229 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2230 if (!adapter) {
2231 hdd_err("Adapter is NULL");
2232 return PM_MAX_NUM_OF_MODE;
2233 }
2234
2235 return policy_mgr_convert_device_mode_to_qdf_type(
2236 adapter->device_mode);
2237}
2238
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002239static void hdd_register_policy_manager_callback(
2240 struct wlan_objmgr_psoc *psoc)
2241{
2242 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002243
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002244 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002245 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002246 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2247 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002248 hdd_cbacks.get_mode_for_non_connected_vdev =
2249 wlan_hdd_get_mode_for_non_connected_vdev;
2250
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002251 if (QDF_STATUS_SUCCESS !=
2252 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2253 hdd_err("HDD callback registration with policy manager failed");
2254 }
2255}
2256#else
2257static void hdd_register_policy_manager_callback(
2258 struct wlan_objmgr_psoc *psoc)
2259{
2260}
2261#endif
2262
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002263#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002264static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002265{
2266 struct nan_callbacks cb_obj = {0};
2267
2268 cb_obj.ndi_open = hdd_ndi_open;
2269 cb_obj.ndi_close = hdd_ndi_close;
2270 cb_obj.ndi_start = hdd_ndi_start;
2271 cb_obj.ndi_delete = hdd_ndi_delete;
2272 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2273 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2274
Naveen Rawat37f62c82017-03-26 22:24:43 -07002275 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2276 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002277 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002278
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002279 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2280}
2281#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002282static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002283{
2284}
2285#endif
2286
gbian62edd7e2017-03-07 13:12:13 +08002287/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302288 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2289 * @hdd_ctx: HDD context
2290 * @adapter: HDD adapter
2291 * @reinit: flag to indicate from SSR or normal path
2292 *
2293 * This function maintains the driver state machine it will be invoked from
2294 * startup, reinit and change interface. Depending on the driver state shall
2295 * perform the opening of the modules.
2296 *
2297 * Return: 0 for success; non-zero for failure
2298 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002299int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2300 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302301 bool reinit)
2302{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002303 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302304 qdf_device_t qdf_dev;
2305 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302306 bool unint = false;
2307 void *hif_ctx;
2308
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002309 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302310
2311 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2312 if (!qdf_dev) {
2313 hdd_err("QDF Device Context is Invalid return");
2314 return -EINVAL;
2315 }
2316
2317 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302318 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302319
2320 if (QDF_TIMER_STATE_RUNNING ==
2321 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2322
2323 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002324 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302325 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2326 }
2327
2328 switch (hdd_ctx->driver_status) {
2329 case DRIVER_MODULES_UNINITIALIZED:
2330 unint = true;
2331 /* Fall through dont add break here */
2332 case DRIVER_MODULES_CLOSED:
2333 if (!reinit && !unint) {
2334 ret = pld_power_on(qdf_dev->dev);
2335 if (ret) {
2336 hdd_err("Failed to Powerup the device: %d", ret);
2337 goto release_lock;
2338 }
2339 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002340
2341 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2342 hdd_ctx->config->enable_fw_log);
2343
Arun Khandavallifae92942016-08-01 13:31:08 +05302344 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2345 qdf_dev->bus_type,
2346 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2347 HIF_ENABLE_TYPE_PROBE);
2348 if (ret) {
2349 hdd_err("Failed to open hif: %d", ret);
2350 goto power_down;
2351 }
2352
2353 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302354 if (!hif_ctx) {
2355 hdd_err("hif context is null!!");
2356 goto power_down;
2357 }
2358
Arun Khandavallifae92942016-08-01 13:31:08 +05302359 status = ol_cds_init(qdf_dev, hif_ctx);
2360 if (status != QDF_STATUS_SUCCESS) {
2361 hdd_err("No Memory to Create BMI Context :%d", status);
2362 goto hif_close;
2363 }
2364
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002365 ret = hdd_update_config(hdd_ctx);
2366 if (ret) {
2367 hdd_err("Failed to update configuration :%d", ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002368 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002369 }
2370
gbian62edd7e2017-03-07 13:12:13 +08002371 hdd_update_cds_ac_specs_params(hdd_ctx);
2372
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302373 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002374 if (QDF_IS_STATUS_ERROR(status)) {
Arun Khandavallifae92942016-08-01 13:31:08 +05302375 hdd_err("Failed to Open CDS: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002376 ret = qdf_status_to_os_return(status);
2377 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302378 }
2379
Mukul Sharma9d797a02017-01-05 20:26:03 +05302380 /* initalize components configurations after psoc open */
2381 ret = hdd_update_components_config(hdd_ctx);
2382 if (ret) {
2383 hdd_err("Failed to update components configs :%d",
2384 ret);
2385 goto close;
2386 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002387 status = cds_dp_open(hdd_ctx->hdd_psoc);
2388 if (!QDF_IS_STATUS_SUCCESS(status)) {
2389 hdd_err("Failed to Open cds post open: %d", status);
2390 goto close;
2391 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302392
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002393 /*
2394 * NAN compoenet requires certian operations like, open adapter,
2395 * close adapter, etc. to be initiated by HDD, for those
2396 * register HDD callbacks with UMAC's NAN componenet.
2397 */
2398 hdd_nan_register_callbacks(hdd_ctx);
2399
Arun Khandavallifae92942016-08-01 13:31:08 +05302400 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2401
Jeff Johnson3a280122017-09-13 07:42:00 -07002402 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302403 if (!QDF_IS_STATUS_SUCCESS(status)) {
2404 hdd_err("Failed to pre-enable CDS: %d", status);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002405 ret = (status == QDF_STATUS_E_NOMEM) ? -ENOMEM : -EINVAL;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002406 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302407 }
2408
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002409 hdd_register_policy_manager_callback(
2410 hdd_ctx->hdd_psoc);
2411
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302412 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302413 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302414
Arun Khandavallifae92942016-08-01 13:31:08 +05302415 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2416 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2417 hdd_ftm_mc_process_msg);
2418 break;
2419 }
2420 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002421 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302422 break;
2423 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302424
2425 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002426 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2427 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002428 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002429 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302430 }
2431
Arun Khandavallifae92942016-08-01 13:31:08 +05302432 /* Fall through dont add break here */
2433 case DRIVER_MODULES_OPENED:
2434 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002435 hdd_alert("adapter is Null");
2436 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302437 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302438 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2439 hdd_err("in ftm mode, no need to configure cds modules");
2440 break;
2441 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302442 if (hdd_configure_cds(hdd_ctx, adapter)) {
2443 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002444 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302445 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302446 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302447 hdd_info("Driver Modules Successfully Enabled");
2448 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2449 break;
2450 case DRIVER_MODULES_ENABLED:
2451 hdd_info("Driver modules already Enabled");
2452 break;
2453 default:
2454 hdd_err("WLAN start invoked in wrong state! :%d\n",
2455 hdd_ctx->driver_status);
2456 goto release_lock;
2457 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302458 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302459 mutex_unlock(&hdd_ctx->iface_change_lock);
2460 EXIT();
2461 return 0;
2462
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002463post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002464 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002465
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002466cds_txrx_free:
2467 cds_dp_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302468close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002469 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002470 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302471
Dustin Brown28b17892017-10-10 13:29:38 -07002472deinit_config:
2473 cds_deinit_ini_config();
2474
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002475cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302476 ol_cds_free();
2477
2478hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002479 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2480 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302481power_down:
2482 if (!reinit && !unint)
2483 pld_power_off(qdf_dev->dev);
2484release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302485 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302486 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302487 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002488
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002489 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302490}
2491
Naveen Rawat910726a2017-03-06 11:42:51 -08002492#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002493static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002494{
2495 int ret = os_if_wifi_pos_register_nl();
2496
2497 if (ret)
2498 hdd_err("os_if_wifi_pos_register_nl failed");
2499
2500 return ret;
2501}
2502
2503static int hdd_deactivate_wifi_pos(void)
2504{
2505 int ret = os_if_wifi_pos_deregister_nl();
2506
2507 if (ret)
2508 hdd_err("os_if_wifi_pos_deregister_nl failed");
2509
2510 return ret;
2511}
2512
2513/**
2514 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2515 * @hdd_ctx: hdd context
2516 *
2517 * Return: status of operation
2518 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002519static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002520{
2521 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2522 struct hdd_config *cfg = hdd_ctx->config;
2523
2524 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2525 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2526 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2527 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2528 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2529 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2530 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2531 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2532}
2533#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002534static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002535{
2536 return oem_activate_service(hdd_ctx);
2537}
2538
2539static int hdd_deactivate_wifi_pos(void)
2540{
2541 return 0;
2542}
2543
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002544static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002545{
2546}
2547#endif
2548
Arun Khandavallifae92942016-08-01 13:31:08 +05302549/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002550 * __hdd_open() - HDD Open function
2551 * @dev: Pointer to net_device structure
2552 *
2553 * This is called in response to ifconfig up
2554 *
2555 * Return: 0 for success; non-zero for failure
2556 */
2557static int __hdd_open(struct net_device *dev)
2558{
Jeff Johnson9d295242017-08-29 14:39:48 -07002559 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002560 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002561 int ret;
2562
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002563 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302564 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302565 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002566
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302567 /* Nothing to be done if device is unloading */
2568 if (cds_is_driver_unloading()) {
2569 hdd_err("Driver is unloading can not open the hdd");
2570 return -EBUSY;
2571 }
2572
Dustin Brown01847752017-10-25 13:56:27 -07002573 if (cds_is_driver_recovering()) {
2574 hdd_err("WLAN is currently recovering; Please try again.");
2575 return -EBUSY;
2576 }
2577
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302578 mutex_lock(&hdd_init_deinit_lock);
2579
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302580 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2581
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302582 /*
2583 * This scenario can be hit in cases where in the wlan driver after
2584 * registering the netdevices and there is a failure in driver
2585 * initialization. So return error gracefully because the netdevices
2586 * will be de-registered as part of the load failure.
2587 */
2588
2589 if (!cds_is_driver_loaded()) {
2590 hdd_err("Failed to start the wlan driver!!");
2591 ret = -EIO;
2592 goto err_hdd_hdd_init_deinit_lock;
2593 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302594
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002595
Arun Khandavallifae92942016-08-01 13:31:08 +05302596 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2597 if (ret) {
2598 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302599 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302600 }
2601
2602
2603 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2604 ret = hdd_start_adapter(adapter);
2605 if (ret) {
2606 hdd_err("Failed to start adapter :%d",
2607 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302608 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302609 }
2610 }
2611
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002612 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2613 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002614 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002615 /* Enable TX queues only when we are connected */
2616 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302617 WLAN_START_ALL_NETIF_QUEUE,
2618 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002619 }
2620
Naveen Rawat286def52016-09-23 15:38:02 -07002621 /* Enable carrier and transmit queues for NDI */
2622 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002623 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002624 wlan_hdd_netif_queue_control(adapter,
2625 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2626 WLAN_CONTROL_PATH);
2627 }
2628
Naveen Rawat910726a2017-03-06 11:42:51 -08002629 hdd_populate_wifi_pos_cfg(hdd_ctx);
2630
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302631err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302632 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302633 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002634 return ret;
2635}
2636
Arun Khandavallifae92942016-08-01 13:31:08 +05302637
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002638/**
2639 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2640 * @dev: Pointer to net_device structure
2641 *
2642 * This is called in response to ifconfig up
2643 *
2644 * Return: 0 for success; non-zero for failure
2645 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002646static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002647{
2648 int ret;
2649
2650 cds_ssr_protect(__func__);
2651 ret = __hdd_open(dev);
2652 cds_ssr_unprotect(__func__);
2653
2654 return ret;
2655}
2656
2657/**
2658 * __hdd_stop() - HDD stop function
2659 * @dev: Pointer to net_device structure
2660 *
2661 * This is called in response to ifconfig down
2662 *
2663 * Return: 0 for success; non-zero for failure
2664 */
2665static int __hdd_stop(struct net_device *dev)
2666{
Jeff Johnson9d295242017-08-29 14:39:48 -07002667 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002668 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002669 int ret;
2670
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002671 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002672
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302673 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002674 adapter->sessionId, adapter->device_mode));
2675
2676 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302677 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002678 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002679
2680 /* Nothing to be done if the interface is not opened */
2681 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002682 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002683 return -ENODEV;
2684 }
2685
2686 /* Make sure the interface is marked as closed */
2687 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302688
2689 hdd_debug("Disabling Auto Power save timer");
2690 sme_ps_disable_auto_ps_timer(
2691 WLAN_HDD_GET_HAL_CTX(adapter),
2692 adapter->sessionId);
2693
2694 /*
2695 * Disable TX on the interface, after this hard_start_xmit() will not
2696 * be called on that interface
2697 */
2698 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302699 wlan_hdd_netif_queue_control(adapter,
2700 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2701 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002702
2703 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002704 * NAN data interface is different in some sense. The traffic on NDI is
2705 * bursty in nature and depends on the need to transfer. The service
2706 * layer may down the interface after the usage and up again when
2707 * required. In some sense, the NDI is expected to be available
2708 * (like SAP) iface until NDI delete request is issued by the service
2709 * layer. Skip BSS termination and adapter deletion for NAN Data
2710 * interface (NDI).
2711 */
2712 if (WLAN_HDD_IS_NDI(adapter))
2713 return 0;
2714
2715 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002716 * The interface is marked as down for outside world (aka kernel)
2717 * But the driver is pretty much alive inside. The driver needs to
2718 * tear down the existing connection on the netdev (session)
2719 * cleanup the data pipes and wait until the control plane is stabilized
2720 * for this interface. The call also needs to wait until the above
2721 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002722 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002723 * That is intentional to be able to scan if it is a STA/P2P interface
2724 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302725 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002726
2727 /* DeInit the adapter. This ensures datapath cleanup as well */
2728 hdd_deinit_adapter(hdd_ctx, adapter, true);
2729
Arun Khandavallifae92942016-08-01 13:31:08 +05302730
2731 /*
2732 * Find if any iface is up. If any iface is up then can't put device to
2733 * sleep/power save mode
2734 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302735 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002736 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302737 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302738 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302739 hdd_prevent_suspend_timeout(
2740 hdd_ctx->config->iface_change_wait_time,
2741 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302742 }
2743
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002744 EXIT();
2745 return 0;
2746}
2747
2748/**
2749 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2750 * @dev: pointer to net_device structure
2751 *
2752 * This is called in response to ifconfig down
2753 *
2754 * Return: 0 for success and error number for failure
2755 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002756static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002757{
2758 int ret;
2759
2760 cds_ssr_protect(__func__);
2761 ret = __hdd_stop(dev);
2762 cds_ssr_unprotect(__func__);
2763
2764 return ret;
2765}
2766
2767/**
2768 * __hdd_uninit() - HDD uninit function
2769 * @dev: Pointer to net_device structure
2770 *
2771 * This is called during the netdev unregister to uninitialize all data
2772 * associated with the device
2773 *
2774 * Return: None
2775 */
2776static void __hdd_uninit(struct net_device *dev)
2777{
Jeff Johnson9d295242017-08-29 14:39:48 -07002778 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002779 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002780
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002781 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002782
2783 do {
2784 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002785 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002786 break;
2787 }
2788
Jeff Johnson399c6272017-08-30 10:51:00 -07002789 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2790 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002791 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002792 break;
2793 }
2794
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002795 if (dev != adapter->dev)
2796 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002797
Jeff Johnson399c6272017-08-30 10:51:00 -07002798 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002799
2800 /* after uninit our adapter structure will no longer be valid */
2801 adapter->dev = NULL;
2802 adapter->magic = 0;
2803 } while (0);
2804
2805 EXIT();
2806}
2807
2808/**
2809 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2810 * @dev: pointer to net_device structure
2811 *
2812 * This is called during the netdev unregister to uninitialize all data
2813 * associated with the device
2814 *
2815 * Return: none
2816 */
2817static void hdd_uninit(struct net_device *dev)
2818{
2819 cds_ssr_protect(__func__);
2820 __hdd_uninit(dev);
2821 cds_ssr_unprotect(__func__);
2822}
2823
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002824static int hdd_open_cesium_nl_sock(void)
2825{
2826#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2827 struct netlink_kernel_cfg cfg = {
2828 .groups = WLAN_NLINK_MCAST_GRP_ID,
2829 .input = NULL
2830 };
2831#endif
2832 int ret = 0;
2833
2834#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2835 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2836#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2837 THIS_MODULE,
2838#endif
2839 &cfg);
2840#else
2841 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2842 WLAN_NLINK_MCAST_GRP_ID,
2843 NULL, NULL, THIS_MODULE);
2844#endif
2845
2846 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002847 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002848 ret = -ECONNREFUSED;
2849 }
2850
2851 return ret;
2852}
2853
2854static void hdd_close_cesium_nl_sock(void)
2855{
2856 if (NULL != cesium_nl_srv_sock) {
2857 netlink_kernel_release(cesium_nl_srv_sock);
2858 cesium_nl_srv_sock = NULL;
2859 }
2860}
2861
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002862/**
2863 * __hdd_set_mac_address() - set the user specified mac address
2864 * @dev: Pointer to the net device.
2865 * @addr: Pointer to the sockaddr.
2866 *
2867 * This function sets the user specified mac address using
2868 * the command ifconfig wlanX hw ether <mac adress>.
2869 *
2870 * Return: 0 for success, non zero for failure
2871 */
2872static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2873{
Jeff Johnson9d295242017-08-29 14:39:48 -07002874 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002875 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002876 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302877 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878 int ret;
2879
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002880 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002881
2882 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2883 ret = wlan_hdd_validate_context(hdd_ctx);
2884 if (0 != ret)
2885 return ret;
2886
2887 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2888 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2889
2890 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302891 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002892}
2893
2894/**
2895 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2896 * function from SSR
2897 * @dev: pointer to net_device structure
2898 * @addr: Pointer to the sockaddr
2899 *
2900 * This function sets the user specified mac address using
2901 * the command ifconfig wlanX hw ether <mac adress>.
2902 *
2903 * Return: 0 for success.
2904 */
2905static int hdd_set_mac_address(struct net_device *dev, void *addr)
2906{
2907 int ret;
2908
2909 cds_ssr_protect(__func__);
2910 ret = __hdd_set_mac_address(dev, addr);
2911 cds_ssr_unprotect(__func__);
2912
2913 return ret;
2914}
2915
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002916uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002917{
2918 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002919
Anurag Chouhan6d760662016-02-20 16:05:43 +05302920 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002921 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2922 break;
2923 }
2924
Anurag Chouhan6d760662016-02-20 16:05:43 +05302925 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926 return NULL;
2927
2928 hdd_ctx->config->intfAddrMask |= (1 << i);
2929 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2930}
2931
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07002932void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
2933 uint8_t *releaseAddr)
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 (!memcmp(releaseAddr,
2939 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2940 6)) {
2941 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2942 break;
2943 }
2944 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002945}
2946
2947#ifdef WLAN_FEATURE_PACKET_FILTERING
2948/**
2949 * __hdd_set_multicast_list() - set the multicast address list
2950 * @dev: Pointer to the WLAN device.
2951 * @skb: Pointer to OS packet (sk_buff).
2952 *
2953 * This funciton sets the multicast address list.
2954 *
2955 * Return: None
2956 */
2957static void __hdd_set_multicast_list(struct net_device *dev)
2958{
Jeff Johnson9d295242017-08-29 14:39:48 -07002959 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002960 int i = 0, status;
2961 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002962 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302963 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2964 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2965 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002966
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002967 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302968 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302969 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302970
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002971 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302972 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302973 goto out;
2974
Dustin Brownc788acb2017-08-01 17:43:51 -07002975 status = hdd_validate_adapter(adapter);
2976 if (status)
2977 goto out;
2978
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302979 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2980 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002981 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302982 goto out;
2983 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002984
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302985 /* Delete already configured multicast address list */
2986 if (adapter->mc_addr_list.mc_cnt > 0) {
2987 hdd_info("clear previously configured MC address list");
2988 hdd_disable_and_flush_mc_addr_list(adapter,
2989 pmo_mc_list_change_notify);
2990 }
2991
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002993 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302994 hdd_disable_and_flush_mc_addr_list(adapter,
2995 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002996 } else {
2997 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302998 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002999 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303000 pmo_ucfg_max_mc_addr_supported(psoc));
3001 hdd_disable_and_flush_mc_addr_list(adapter,
3002 pmo_mc_list_change_notify);
3003 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003004 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003005 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003006 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303007 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003008 if (i == mc_count)
3009 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303010 memset(&(mc_list_request->mc_addr[i].bytes),
3011 0, ETH_ALEN);
3012 memcpy(&(mc_list_request->mc_addr[i].bytes),
3013 ha->addr, ETH_ALEN);
3014 hdd_info("mlist[%d] = %pM", i,
3015 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003016 i++;
3017 }
3018 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303019
3020 mc_list_request->psoc = psoc;
3021 mc_list_request->vdev_id = adapter->sessionId;
3022 mc_list_request->count = mc_count;
3023 status = hdd_cache_mc_addr_list(mc_list_request);
3024 if (status == 0) {
3025 hdd_enable_mc_addr_filtering(adapter,
3026 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003027 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303028 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303030out:
3031 if (mc_list_request)
3032 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303033 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003034}
3035
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303036
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003037/**
3038 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3039 * @dev: pointer to net_device
3040 *
3041 * Return: none
3042 */
3043static void hdd_set_multicast_list(struct net_device *dev)
3044{
3045 cds_ssr_protect(__func__);
3046 __hdd_set_multicast_list(dev);
3047 cds_ssr_unprotect(__func__);
3048}
3049#endif
3050
3051/**
3052 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3053 * @dev: Pointer to the WLAN device.
3054 * @skb: Pointer to OS packet (sk_buff).
3055 *
3056 * This function is registered with the Linux OS for network
3057 * core to decide which queue to use first.
3058 *
3059 * Return: ac, Queue Index/access category corresponding to UP in IP header
3060 */
3061static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3062#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3063 , void *accel_priv
3064#endif
3065#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3066 , select_queue_fallback_t fallback
3067#endif
3068)
3069{
3070 return hdd_wmm_select_queue(dev, skb);
3071}
3072
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003073static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003074 .ndo_open = hdd_open,
3075 .ndo_stop = hdd_stop,
3076 .ndo_uninit = hdd_uninit,
3077 .ndo_start_xmit = hdd_hard_start_xmit,
3078 .ndo_tx_timeout = hdd_tx_timeout,
3079 .ndo_get_stats = hdd_get_stats,
3080 .ndo_do_ioctl = hdd_ioctl,
3081 .ndo_set_mac_address = hdd_set_mac_address,
3082 .ndo_select_queue = hdd_select_queue,
3083#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003084 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003085#endif
3086};
3087
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003088/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003089static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003090 .ndo_open = hdd_mon_open,
3091 .ndo_stop = hdd_stop,
3092 .ndo_get_stats = hdd_get_stats,
3093};
3094
3095/**
3096 * hdd_set_station_ops() - update net_device ops for monitor mode
3097 * @pWlanDev: Handle to struct net_device to be updated.
3098 * Return: None
3099 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003100void hdd_set_station_ops(struct net_device *pWlanDev)
3101{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003102 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
3103 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
3104 else
3105 pWlanDev->netdev_ops = &wlan_drv_ops;
3106}
3107
3108/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003109 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3110 * @hdd_ctx: global hdd context
3111 * @macAddr: mac address to assign to the interface
3112 * @name: User-visible name of the interface
3113 *
3114 * hdd adapter pointer would point to the netdev->priv space, this function
3115 * would retrive the pointer, and setup the hdd adapter configuration.
3116 *
3117 * Return: the pointer to hdd adapter, otherwise NULL
3118 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003119static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003120 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003121 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122 const char *name)
3123{
3124 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003125 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003126 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127 /*
3128 * cfg80211 initialization and registration....
3129 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003130 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003131#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3132 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003134 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3135 hdd_mon_mode_ether_setup : ether_setup),
3136 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137
3138 if (pWlanDev != NULL) {
3139
3140 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003141 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003142
Jeff Johnson9d295242017-08-29 14:39:48 -07003143 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303144 sta_ctx = &adapter->sessionCtx.station;
3145 qdf_mem_set(sta_ctx->conn_info.staId,
3146 sizeof(sta_ctx->conn_info.staId),
3147 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003149 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303151 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152
3153 init_completion(&adapter->session_open_comp_var);
3154 init_completion(&adapter->session_close_comp_var);
3155 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303156 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003157 init_completion(&adapter->linkup_event_var);
3158 init_completion(&adapter->cancel_rem_on_chan_var);
3159 init_completion(&adapter->rem_on_chan_ready_event);
3160 init_completion(&adapter->sta_authorized_event);
3161 init_completion(&adapter->offchannel_tx_event);
3162 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003163 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164 init_completion(&adapter->change_country_code);
3165
3166
3167 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303168 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169
3170 adapter->offloads_configured = false;
3171 adapter->isLinkUpSvcNeeded = false;
3172 adapter->higherDtimTransition = true;
3173 /* Init the net_device structure */
3174 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3175
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303176 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303178 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179 sizeof(tSirMacAddr));
3180 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181
3182 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3183 pWlanDev->features |=
3184 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3185 pWlanDev->features |= NETIF_F_RXCSUM;
3186
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003187 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3188
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003189 hdd_set_station_ops(adapter->dev);
3190
Dustin Brownc81dd412017-08-15 16:26:28 -07003191 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003193 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194 adapter->wdev.wiphy = hdd_ctx->wiphy;
3195 adapter->wdev.netdev = pWlanDev;
3196 /* set pWlanDev's parent to underlying device */
3197 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3198 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303199 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303201 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202 }
3203
3204 return adapter;
3205}
3206
Jeff Johnson9d295242017-08-29 14:39:48 -07003207static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003209 struct net_device *dev = adapter->dev;
3210 int ret;
3211
3212 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003213
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003214 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003215 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3216
3217 ret = dev_alloc_name(dev, dev->name);
3218 if (ret < 0) {
3219 hdd_err(
3220 "unable to get dev name: %s, err = 0x%x",
3221 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303222 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003223 }
3224 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003225
3226 ret = register_netdevice(dev);
3227 if (ret) {
3228 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3229 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303230 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003231 }
3232 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003233 ret = register_netdev(dev);
3234 if (ret) {
3235 hdd_err("register_netdev(%s) failed, err = 0x%x",
3236 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303237 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003238 }
3239 }
3240 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3241
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003242 EXIT();
3243
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303244 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003245}
3246
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003247QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003248{
Jeff Johnson9d295242017-08-29 14:39:48 -07003249 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250
3251 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003252 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303253 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003254 }
3255
3256 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003257 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303258 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003259 }
3260
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003261 /*
3262 * For NAN Data interface, the close session results in the final
3263 * indication to the userspace
3264 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003265 if (adapter->device_mode == QDF_NDI_MODE)
3266 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003267
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3269
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270 /*
3271 * We can be blocked while waiting for scheduled work to be
3272 * flushed, and the adapter structure can potentially be freed, in
3273 * which case the magic will have been reset. So make sure the
3274 * magic is still good, and hence the adapter structure is still
3275 * valid, before signaling completion
3276 */
3277 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3278 complete(&adapter->session_close_comp_var);
3279
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303280 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003281}
3282
Jeff Johnson9d295242017-08-29 14:39:48 -07003283int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003284{
Dustin Brownd28772b2017-03-17 14:16:07 -07003285 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286
Dustin Brownd28772b2017-03-17 14:16:07 -07003287 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003288 if (QDF_IS_STATUS_ERROR(status))
3289 return qdf_status_to_os_return(status);
3290
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003291 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003292 if (QDF_IS_STATUS_ERROR(status))
3293 return qdf_status_to_os_return(status);
3294
3295 if (wma_capability_enhanced_mcast_filter())
3296 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3297 else
3298 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003299
3300 return qdf_status_to_os_return(status);
3301}
3302
Jeff Johnson9d295242017-08-29 14:39:48 -07003303int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003304{
3305 QDF_STATUS status;
3306 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003307 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003308 unsigned long rc;
3309
3310 hdd_info("destroying vdev %d", adapter->sessionId);
3311
3312 /* vdev created sanity check */
3313 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3314 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3315 return -EINVAL;
3316 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003317 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003318 /*
3319 * In SSR case, there is no need to destroy vdev in firmware since
3320 * it has already asserted. vdev can be released directly.
3321 */
3322 if (cds_is_driver_recovering())
3323 goto release_vdev;
3324
Dustin Brownd28772b2017-03-17 14:16:07 -07003325 /* close sme session (destroy vdev in firmware via legacy API) */
3326 INIT_COMPLETION(adapter->session_close_comp_var);
3327 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3328 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3329 hdd_sme_close_session_callback, adapter);
3330 if (QDF_IS_STATUS_ERROR(status)) {
3331 hdd_err("failed to close sme session: %d", status);
3332 return qdf_status_to_os_return(status);
3333 }
3334
3335 /* block on a completion variable until sme session is closed */
3336 rc = wait_for_completion_timeout(
3337 &adapter->session_close_comp_var,
3338 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3339 if (!rc) {
3340 hdd_err("timed out waiting for close sme session: %ld", rc);
3341 if (adapter->device_mode == QDF_NDI_MODE)
3342 hdd_ndp_session_end_handler(adapter);
3343 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3344 return -ETIMEDOUT;
3345 }
Yue Maf9782842017-05-08 12:49:49 -07003346release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003347 /* do vdev logical destroy via objmgr */
3348 errno = hdd_objmgr_destroy_vdev(adapter);
3349 if (errno) {
3350 hdd_err("failed to destroy objmgr vdev: %d", errno);
3351 return errno;
3352 }
3353
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003354 /* now that sme session is closed, allow physical vdev destroy */
3355 errno = hdd_objmgr_release_vdev(adapter);
3356 if (errno) {
3357 hdd_err("failed to release objmgr vdev: %d", errno);
3358 return errno;
3359 }
3360
Dustin Brownd28772b2017-03-17 14:16:07 -07003361 hdd_info("vdev destroyed successfully");
3362
3363 return 0;
3364}
3365
Jeff Johnson9d295242017-08-29 14:39:48 -07003366int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003367{
3368 QDF_STATUS status;
3369 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003370 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003371 uint32_t type;
3372 uint32_t sub_type;
3373 unsigned long rc;
3374
3375 hdd_info("creating new vdev");
3376
3377 /* determine vdev (sub)type */
3378 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303379 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003380 hdd_err("failed to get vdev type: %d", status);
3381 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003382 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003383
3384 /* do vdev create via objmgr */
3385 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003386 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003387 if (errno) {
3388 hdd_err("failed to create objmgr vdev: %d", errno);
3389 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003390 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003391
3392 /* Open a SME session (prepare vdev in firmware via legacy API) */
3393 INIT_COMPLETION(adapter->session_open_comp_var);
3394 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3395 (uint8_t *)&adapter->macAddressCurrent,
3396 adapter->sessionId, type, sub_type);
3397 if (QDF_IS_STATUS_ERROR(status)) {
3398 hdd_err("failed to open sme session: %d", status);
3399 errno = qdf_status_to_os_return(status);
3400 goto objmgr_vdev_destroy;
3401 }
3402
3403 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 rc = wait_for_completion_timeout(
3405 &adapter->session_open_comp_var,
3406 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3407 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003408 hdd_err("timed out waiting for open sme session: %ld", rc);
3409 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303410 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3411 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003412 }
3413
3414 /* firmware ready for component communication, raise vdev_ready event */
3415 errno = hdd_vdev_ready(adapter);
3416 if (errno) {
3417 hdd_err("failed to dispatch vdev ready event: %d", errno);
3418 goto hdd_vdev_destroy;
3419 }
3420
3421 hdd_info("vdev %d created successfully", adapter->sessionId);
3422
3423 return 0;
3424
3425 /*
3426 * Due to legacy constraints, we need to destroy in the same order as
3427 * create. So, split error handling into 2 cases to accommodate.
3428 */
3429
3430objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003431 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003432
3433 return errno;
3434
3435hdd_vdev_destroy:
3436 QDF_BUG(!hdd_vdev_destroy(adapter));
3437
3438 return errno;
3439}
3440
Jeff Johnson9d295242017-08-29 14:39:48 -07003441QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003442{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003443 struct hdd_station_ctx *sta_ctx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003444 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003445 QDF_STATUS status;
3446 int ret_val;
3447
3448 ret_val = hdd_vdev_create(adapter);
3449 if (ret_val) {
3450 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303451 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 }
3453
Dustin Brownd28772b2017-03-17 14:16:07 -07003454 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3455 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3456 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003457 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003458
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003459 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003460 status = hdd_register_wext(adapter->dev);
3461 if (QDF_IS_STATUS_ERROR(status)) {
3462 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463 goto error_register_wext;
3464 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003465 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003466
Jeff Johnsond377dce2017-10-04 10:32:42 -07003467 qdf_mem_set(sta_ctx->conn_info.staId,
3468 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303469
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003470 /* set fast roaming capability in sme session */
3471 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3472 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003474 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475 hdd_ctx->config->OperatingChannel;
3476
3477 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003478 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479
3480 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303481 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003482 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483 status, status);
3484 goto error_init_txrx;
3485 }
3486
3487 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3488
3489 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303490 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003491 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492 status, status);
3493 goto error_wmm_init;
3494 }
3495
3496 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3497
Naveen Rawat247a8682017-06-05 15:00:31 -07003498 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499 WMI_PDEV_PARAM_BURST_ENABLE,
3500 hdd_ctx->config->enableSifsBurst,
3501 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003502 if (ret_val)
3503 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003505 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303506 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003508error_wmm_init:
3509 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3510 hdd_deinit_tx_rx(adapter);
3511error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003512 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003513error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003514 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003515
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516 return status;
3517}
3518
Jeff Johnson9d295242017-08-29 14:39:48 -07003519void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003520{
Wu Gao02bd75b2017-10-13 18:34:02 +08003521 hdd_debug("Cleanup action frame");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003522}
3523
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303524/**
3525 * hdd_station_adapter_deinit() - De-initialize the station adapter
3526 * @hdd_ctx: global hdd context
3527 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003528 * @rtnl_held: Used to indicate whether or not the caller is holding
3529 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303530 *
3531 * This function De-initializes the STA/P2P/OCB adapter.
3532 *
3533 * Return: None.
3534 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003535static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003536 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003537 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303538{
3539 ENTER_DEV(adapter->dev);
3540
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303541 if (adapter->dev) {
3542 if (rtnl_held)
3543 adapter->dev->wireless_handlers = NULL;
3544 else {
3545 rtnl_lock();
3546 adapter->dev->wireless_handlers = NULL;
3547 rtnl_unlock();
3548 }
3549 }
3550
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303551 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3552 hdd_deinit_tx_rx(adapter);
3553 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3554 }
3555
3556 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3557 hdd_wmm_adapter_close(adapter);
3558 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3559 }
3560
3561 hdd_cleanup_actionframe(hdd_ctx, adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303562
3563 EXIT();
3564}
3565
3566/**
3567 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3568 * @hdd_ctx: global hdd context
3569 * @adapter: HDD adapter
3570 * @rtnl_held: the rtnl lock hold flag
3571 * This function De-initializes the AP/P2PGo adapter.
3572 *
3573 * Return: None.
3574 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003575static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003576 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003577 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303578{
3579 ENTER_DEV(adapter->dev);
3580
3581 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3582 hdd_wmm_adapter_close(adapter);
3583 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3584 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003585 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303586
3587 hdd_cleanup_actionframe(hdd_ctx, adapter);
3588
3589 hdd_unregister_hostapd(adapter, rtnl_held);
3590
3591 EXIT();
3592}
3593
Jeff Johnson9d295242017-08-29 14:39:48 -07003594void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003595 bool rtnl_held)
3596{
3597 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303598
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003600 case QDF_STA_MODE:
3601 case QDF_P2P_CLIENT_MODE:
3602 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303604 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605 break;
3606 }
3607
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003608 case QDF_SAP_MODE:
3609 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610 {
3611
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303612 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003613 break;
3614 }
3615
3616 default:
3617 break;
3618 }
3619
3620 EXIT();
3621}
3622
Jeff Johnson9d295242017-08-29 14:39:48 -07003623static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003624 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625{
3626 struct net_device *pWlanDev = NULL;
3627
3628 if (adapter)
3629 pWlanDev = adapter->dev;
3630 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003631 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003632 return;
3633 }
3634
Rajeev Kumardca5f812016-02-04 17:28:06 -08003635 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303636
3637 if (adapter->scan_info.default_scan_ies) {
3638 qdf_mem_free(adapter->scan_info.default_scan_ies);
3639 adapter->scan_info.default_scan_ies = NULL;
3640 }
3641
Komal Seelama89be8d2016-09-29 11:09:26 +05303642 hdd_adapter_runtime_suspend_denit(adapter);
3643
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644 /*
3645 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3646 * the driver is almost closed and cannot handle either control
3647 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003648 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3649 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003650 * is not right. Setting this flag helps hdd_stop() to recognize that
3651 * the interface is closed and restricts any operations on that
3652 */
3653 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3654
3655 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003656 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003657 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003658 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003659 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 /*
3661 * Note that the adapter is no longer valid at this point
3662 * since the memory has been reclaimed
3663 */
3664 }
3665}
3666
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003667static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003668 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003669{
3670 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003671 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303672 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003673
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303675 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003676 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303678 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303680 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003681 }
3682 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3683 adapterNode = pNext;
3684 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303685 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003686}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003687
Arun Khandavalli2358d522016-05-16 18:05:37 +05303688#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3689/**
3690 * hdd_set_fw_log_params() - Set log parameters to FW
3691 * @hdd_ctx: HDD Context
3692 * @adapter: HDD Adapter
3693 *
3694 * This function set the FW Debug log level based on the INI.
3695 *
3696 * Return: None
3697 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003698static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003699 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303700{
3701 uint8_t count = 0, numentries = 0,
3702 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3703 uint32_t value = 0;
3704 int ret;
3705
Arun Khandavallifae92942016-08-01 13:31:08 +05303706 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3707 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003708 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303709 return;
3710 }
3711
Arun Khandavallifae92942016-08-01 13:31:08 +05303712 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303713 hdd_ctx->fw_log_settings.dl_type =
3714 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003715 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303716 WMI_DBGLOG_TYPE,
3717 hdd_ctx->config->enableFwLogType,
3718 DBG_CMD);
3719 if (ret != 0)
3720 hdd_err("Failed to enable FW log type ret %d",
3721 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303722
3723 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303724 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003725 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303726 WMI_DBGLOG_LOG_LEVEL,
3727 hdd_ctx->config->enableFwLogLevel,
3728 DBG_CMD);
3729 if (ret != 0)
3730 hdd_err("Failed to enable FW log level ret %d",
3731 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303732
3733 hdd_string_to_u8_array(
3734 hdd_ctx->config->enableFwModuleLogLevel,
3735 moduleloglevel,
3736 &numentries,
3737 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3738
3739 while (count < numentries) {
3740 /*
3741 * FW module log level input string looks like
3742 * below:
3743 * gFwDebugModuleLoglevel=<FW Module ID>,
3744 * <Log Level>,...
3745 * For example:
3746 * gFwDebugModuleLoglevel=
3747 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3748 * Above input string means :
3749 * For FW module ID 1 enable log level 0
3750 * For FW module ID 2 enable log level 1
3751 * For FW module ID 3 enable log level 2
3752 * For FW module ID 4 enable log level 3
3753 * For FW module ID 5 enable log level 4
3754 * For FW module ID 6 enable log level 5
3755 * For FW module ID 7 enable log level 6
3756 */
3757
Nishank Aggarwale239d962017-03-03 12:26:02 +05303758 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3759 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3760 hdd_err("Module id %d and dbglog level %d input length is more than max",
3761 moduleloglevel[count],
3762 moduleloglevel[count + 1]);
3763 return;
3764 }
3765
3766 value = moduleloglevel[count] << 16;
3767 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003768 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303769 WMI_DBGLOG_MOD_LOG_LEVEL,
3770 value, DBG_CMD);
3771 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303772 hdd_err("Failed to enable FW module log level %d ret %d",
3773 value, ret);
3774
3775 count += 2;
3776 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303777
Arun Khandavalli2358d522016-05-16 18:05:37 +05303778}
3779#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003780static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003781 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303782{
3783}
3784
3785#endif
3786
3787/**
3788 * hdd_set_fw_params() - Set parameters to firmware
3789 * @adapter: HDD adapter
3790 *
3791 * This function Sets various parameters to fw once the
3792 * adapter is started.
3793 *
3794 * Return: 0 on success or errno on failure
3795 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003796int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303797{
3798 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003799 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303800
3801 ENTER_DEV(adapter->dev);
3802
3803 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3804 if (!hdd_ctx)
3805 return -EINVAL;
3806
Dustin Brown732ab9c2017-06-15 13:24:09 -07003807 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3808 hdd_debug("FTM Mode is active; nothing to do");
3809 return 0;
3810 }
3811
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303812 ret = sme_cli_set_command(adapter->sessionId,
3813 WMI_PDEV_PARAM_DTIM_SYNTH,
3814 hdd_ctx->config->enable_lprx, PDEV_CMD);
3815 if (ret) {
3816 hdd_err("Failed to set LPRx");
3817 goto error;
3818 }
3819
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303820 if (adapter->device_mode == QDF_STA_MODE) {
3821 sme_set_smps_cfg(adapter->sessionId,
3822 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3823 hdd_ctx->config->upper_brssi_thresh);
3824
3825 sme_set_smps_cfg(adapter->sessionId,
3826 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3827 hdd_ctx->config->lower_brssi_thresh);
3828
3829 sme_set_smps_cfg(adapter->sessionId,
3830 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3831 hdd_ctx->config->enable_dtim_1chrx);
3832 }
3833
Dustin Brown732ab9c2017-06-15 13:24:09 -07003834 if (hdd_ctx->config->enable2x2) {
3835 hdd_debug("configuring 2x2 mode fw params");
3836
Naveen Rawat247a8682017-06-05 15:00:31 -07003837 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003838 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3839 hdd_ctx->config->enable_cck_tx_fir_override,
3840 PDEV_CMD);
3841 if (ret) {
3842 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3843 ret);
3844 goto error;
3845 }
3846 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303847#define HDD_DTIM_1CHAIN_RX_ID 0x5
3848#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003849 hdd_debug("configuring 1x1 mode fw params");
3850
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003851 /*
3852 * Disable DTIM 1 chain Rx when in 1x1,
3853 * we are passing two value
3854 * as param_id << 29 | param_value.
3855 * Below param_value = 0(disable)
3856 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003857 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003858 WMI_STA_SMPS_PARAM_CMDID,
3859 HDD_DTIM_1CHAIN_RX_ID <<
3860 HDD_SMPS_PARAM_VALUE_S,
3861 VDEV_CMD);
3862 if (ret) {
3863 hdd_err("DTIM 1 chain set failed %d", ret);
3864 goto error;
3865 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303866
Naveen Rawat247a8682017-06-05 15:00:31 -07003867 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003868 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3869 hdd_ctx->config->txchainmask1x1,
3870 PDEV_CMD);
3871 if (ret) {
3872 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3873 ret);
3874 goto error;
3875 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303876
Naveen Rawat247a8682017-06-05 15:00:31 -07003877 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003878 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3879 hdd_ctx->config->rxchainmask1x1,
3880 PDEV_CMD);
3881 if (ret) {
3882 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3883 ret);
3884 goto error;
3885 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303886#undef HDD_DTIM_1CHAIN_RX_ID
3887#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003888 }
3889
Naveen Rawat247a8682017-06-05 15:00:31 -07003890 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003891 WMI_PDEV_PARAM_HYST_EN,
3892 hdd_ctx->config->enableMemDeepSleep,
3893 PDEV_CMD);
3894 if (ret) {
3895 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3896 goto error;
3897 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303898
Naveen Rawat247a8682017-06-05 15:00:31 -07003899 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003900 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3901 hdd_ctx->config->rts_profile,
3902 VDEV_CMD);
3903 if (ret) {
3904 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3905 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303906 }
3907
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003908 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3909
3910 ret = wma_cli_set_command(adapter->sessionId,
3911 GEN_VDEV_PARAM_AMSDU,
3912 hdd_ctx->config->max_amsdu_num,
3913 GEN_CMD);
3914 if (ret != 0) {
3915 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3916 goto error;
3917 }
3918
Arun Khandavalli2358d522016-05-16 18:05:37 +05303919 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303920 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003921
Arun Khandavalli2358d522016-05-16 18:05:37 +05303922 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303923
Arun Khandavalli2358d522016-05-16 18:05:37 +05303924error:
3925 return -EINVAL;
3926}
3927
Ryan Hsu07495ea2016-01-21 15:25:39 -08003928/**
3929 * hdd_open_adapter() - open and setup the hdd adatper
3930 * @hdd_ctx: global hdd context
3931 * @session_type: type of the interface to be created
3932 * @iface_name: User-visible name of the interface
3933 * @macAddr: MAC address to assign to the interface
3934 * @name_assign_type: the name of assign type of the netdev
3935 * @rtnl_held: the rtnl lock hold flag
3936 *
3937 * This function open and setup the hdd adpater according to the device
3938 * type request, assign the name, the mac address assigned, and then prepared
3939 * the hdd related parameters, queue, lock and ready to start.
3940 *
3941 * Return: the pointer of hdd adapter, otherwise NULL.
3942 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003943struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003944 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003945 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003946 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947{
Jeff Johnson9d295242017-08-29 14:39:48 -07003948 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303950 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003951
3952 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3953 /*
3954 * Max limit reached on the number of vdevs configured by the
3955 * host. Return error
3956 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303957 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3958 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003959 return NULL;
3960 }
3961
3962 if (macAddr == NULL) {
3963 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303964 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003965 return NULL;
3966 }
3967 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303968 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303969 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3970 " already exists",
3971 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 return NULL;
3973 }
3974
3975 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003976 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003977 /* Reset locally administered bit if the device mode is STA */
3978 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303979 hdd_info("locally administered bit reset in sta mode: "
3980 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003982 case QDF_P2P_CLIENT_MODE:
3983 case QDF_P2P_DEVICE_MODE:
3984 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003985 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303986 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003987 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3988 name_assign_type,
3989 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990
3991 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303992 hdd_err("failed to allocate adapter for session %d",
3993 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994 return NULL;
3995 }
3996
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003997 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003999 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304001 else if (QDF_MONITOR_MODE == session_type)
4002 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004003 else
4004 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4005
4006 adapter->device_mode = session_type;
4007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004009 /*
4010 * Workqueue which gets scheduled in IPv4 notification
4011 * callback
4012 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4014 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015
4016#ifdef WLAN_NS_OFFLOAD
4017 /*
4018 * Workqueue which gets scheduled in IPv6
4019 * notification callback.
4020 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4022 hdd_ipv6_notifier_work_queue);
4023#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304025 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004026 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304027 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004028 }
4029
4030 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004031 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304033 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4034 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304035
Ravi Joshi1a292562017-05-18 16:28:54 -07004036 /* Initialize NAN Data Interface */
4037 if (QDF_NDI_MODE == session_type) {
4038 status = hdd_init_nan_data_mode(adapter);
4039 if (QDF_STATUS_SUCCESS != status)
4040 goto err_free_netdev;
4041 }
4042
4043 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004045 case QDF_P2P_GO_MODE:
4046 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004047 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4048 name_assign_type,
4049 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004051 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304052 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004053 return NULL;
4054 }
4055
4056 adapter->wdev.iftype =
4057 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004058 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004059 NL80211_IFTYPE_P2P_GO;
4060 adapter->device_mode = session_type;
4061
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004062 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304063 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004064 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4065 goto err_free_netdev;
4066 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004067 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304069 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4070 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304071
4072 /*
4073 * Workqueue which gets scheduled in IPv4 notification
4074 * callback
4075 */
4076 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4077 hdd_ipv4_notifier_work_queue);
4078
4079#ifdef WLAN_NS_OFFLOAD
4080 /*
4081 * Workqueue which gets scheduled in IPv6
4082 * notification callback.
4083 */
4084 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4085 hdd_ipv6_notifier_work_queue);
4086#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004087 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304088 case QDF_FTM_MODE:
4089 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4090 name_assign_type,
4091 "wlan0");
4092 if (NULL == adapter) {
4093 hdd_err("Failed to allocate adapter for FTM mode");
4094 return NULL;
4095 }
4096 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4097 adapter->device_mode = session_type;
4098 status = hdd_register_interface(adapter, rtnl_held);
4099 if (QDF_STATUS_SUCCESS != status) {
4100 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4101 goto err_free_netdev;
4102 }
4103 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004104 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304105 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304106 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4107 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304108 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004110 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304111 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 return NULL;
4113 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114
hqueaa33ee2017-05-04 17:56:35 +08004115 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4116
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304117 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004118 /* Add it to the hdd's session list. */
4119 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304120 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004121 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304122 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004124 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004125 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4126 }
4127 }
4128
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304129 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130 if (NULL != adapter) {
4131 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4132 adapter = NULL;
4133 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004134 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304135 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004136
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004137 return NULL;
4138 }
4139
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304140 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004141 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4142 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004143
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144 /* Adapter successfully added. Increment the vdev count */
4145 hdd_ctx->current_intf_count++;
4146
Jeff Johnson5880d792016-08-15 13:32:30 -07004147 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004148 hdd_ctx->current_intf_count);
4149
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004150 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004151 }
4152
Rajeev Kumardca5f812016-02-04 17:28:06 -08004153 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004154 hdd_err("Interface %s wow debug_fs init failed",
4155 netdev_name(adapter->dev));
4156
4157 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4158 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004159
4160 return adapter;
4161
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004162err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304164 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004165
4166 return NULL;
4167}
4168
Jeff Johnson9d295242017-08-29 14:39:48 -07004169QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004170 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004171{
4172 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304173 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004174
4175 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304176 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004177 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004178 status);
4179 return status;
4180 }
4181
Jeff Johnson57eb2732017-10-02 11:40:20 -07004182 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004183 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304184 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004185 break;
4186
4187 pCurrent = pNext;
4188 }
4189 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304190 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004191 /*
4192 * Here we are stopping global bus_bw timer & work per adapter.
4193 *
4194 * The reason is to fix one race condition between
4195 * bus bandwidth work and cleaning up an adapter.
4196 * Under some conditions, it is possible for the bus bandwidth
4197 * work to access a particularly destroyed adapter, leading to
4198 * use-after-free.
4199 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004200 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004201 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004202 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004203
4204 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004205 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4206 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004207 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004208 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304209 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210 adapterNode = NULL;
4211
Dustin Brown5ec6b552017-03-31 12:11:40 -07004212 /* conditionally restart the bw timer */
4213 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4214
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004215 /* Adapter removed. Decrement vdev count */
4216 if (hdd_ctx->current_intf_count != 0)
4217 hdd_ctx->current_intf_count--;
4218
4219 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304220 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304222
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304223 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004224}
4225
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004226/**
4227 * hdd_close_all_adapters - Close all open adapters
4228 * @hdd_ctx: Hdd context
4229 * rtnl_held: True if RTNL lock held
4230 *
4231 * Close all open adapters.
4232 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304233 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004234 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004235QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004236{
4237 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304238 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239
4240 ENTER();
4241
4242 do {
4243 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304244 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304245 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004246 pHddAdapterNode->adapter->macAddressCurrent.bytes);
4247 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004248 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304249 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304250 /* Adapter removed. Decrement vdev count */
4251 if (hdd_ctx->current_intf_count != 0)
4252 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004253 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304254 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004255
4256 EXIT();
4257
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304258 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259}
4260
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004261void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004262{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304263 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004265
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004266 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004267 case QDF_STA_MODE:
4268 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004270 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004271 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004272 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004273 break;
4274 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004275 case QDF_SAP_MODE:
4276 case QDF_P2P_GO_MODE:
4277 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004278 {
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004279 bssid = &adapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280 break;
4281 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004282 case QDF_FTM_MODE:
4283 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004284 default:
4285 /*
4286 * wlan_hdd_reset_prob_rspies should not have been called
4287 * for these kind of devices
4288 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004289 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004290 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291 return;
4292 }
4293
Anurag Chouhanc5548422016-02-24 18:33:27 +05304294 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004295 updateIE.smeSessionId = adapter->sessionId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004296 updateIE.ieBufferlength = 0;
4297 updateIE.pAdditionIEBuffer = NULL;
4298 updateIE.append = true;
4299 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004300 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004301 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304302 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004303 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 }
4305}
4306
Jeff Johnson9d295242017-08-29 14:39:48 -07004307QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308 const bool bCloseSession)
4309{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304310 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004311 struct hdd_wext_state *pWextState =
4312 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004313 union iwreq_data wrqu;
4314 tSirUpdateIE updateIE;
4315 unsigned long rc;
4316
4317 ENTER();
4318
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004319 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304320 wlan_hdd_netif_queue_control(adapter,
4321 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4322 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004323 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004324 case QDF_STA_MODE:
4325 case QDF_P2P_CLIENT_MODE:
4326 case QDF_IBSS_MODE:
4327 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004328 case QDF_NDI_MODE:
4329 if ((QDF_NDI_MODE == adapter->device_mode) ||
4330 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004331 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4332 hdd_is_connecting(
4333 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004334 INIT_COMPLETION(adapter->disconnect_comp_var);
4335 /*
4336 * For NDI do not use pWextState from sta_ctx, if needed
4337 * extract from ndi_ctx.
4338 */
4339 if (QDF_NDI_MODE == adapter->device_mode)
4340 qdf_ret_status = sme_roam_disconnect(
4341 hdd_ctx->hHal,
4342 adapter->sessionId,
4343 eCSR_DISCONNECT_REASON_NDI_DELETE);
4344 else if (pWextState->roamProfile.BSSType ==
4345 eCSR_BSS_TYPE_START_IBSS)
4346 qdf_ret_status = sme_roam_disconnect(
4347 hdd_ctx->hHal,
4348 adapter->sessionId,
4349 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004350 else if (QDF_STA_MODE == adapter->device_mode)
4351 qdf_ret_status =
4352 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004354 qdf_ret_status = sme_roam_disconnect(
4355 hdd_ctx->hHal,
4356 adapter->sessionId,
4357 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004358 /* success implies disconnect command got
4359 * queued up successfully
4360 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004361 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4362 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004363 rc = wait_for_completion_timeout(
4364 &adapter->disconnect_comp_var,
4365 msecs_to_jiffies
4366 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004367 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004368 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004370 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4371 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004372 memset(&wrqu, '\0', sizeof(wrqu));
4373 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4374 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4375 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4376 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304377 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004378 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004379
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304380 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304381 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004382
4383#ifdef WLAN_OPEN_SOURCE
4384 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4385#endif
4386
4387 hdd_deregister_tx_flow_control(adapter);
4388
4389#ifdef WLAN_NS_OFFLOAD
4390#ifdef WLAN_OPEN_SOURCE
4391 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4392#endif
4393#endif
4394
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304395 if (adapter->device_mode == QDF_STA_MODE)
4396 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4397 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 /*
4399 * It is possible that the caller of this function does not
4400 * wish to close the session
4401 */
Krunal Soni985b8132017-02-10 18:49:08 -08004402 if (true == bCloseSession) {
4403 if (0 != wlan_hdd_try_disconnect(adapter)) {
4404 hdd_err("Error: Can't disconnect adapter");
4405 return QDF_STATUS_E_FAILURE;
4406 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004407 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004408 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004409 break;
4410
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004411 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304412 /* Flush IPA exception path packets */
4413 hdd_ipa_flush(hdd_ctx);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004414
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004415 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004416 if (QDF_SAP_MODE == adapter->device_mode) {
4417 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4418 cds_flush_delayed_work(
4419 &adapter->acs_pending_work);
4420 clear_bit(ACS_PENDING, &adapter->event_flags);
4421 }
4422 }
Krunal Soni22208392017-09-29 18:10:34 -07004423 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004424
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004425 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004426 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004427 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004428 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4429
4430 hdd_deregister_tx_flow_control(adapter);
4431
Kapil Guptac1224bf2017-06-22 21:22:40 +05304432 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004433 mutex_lock(&hdd_ctx->sap_lock);
4434 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304435 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304436 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004437
4438 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004439 status = wlansap_stop_bss(
4440 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304442 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004443 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004444 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304445 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304446 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304447 qdf_status =
4448 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004449 qdf_stop_bss_event,
4450 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004451
Anurag Chouhance0dc992016-02-16 18:18:03 +05304452 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004453 hdd_err("failure waiting for wlansap_stop_bss %d",
4454 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004455 }
4456 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004457 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458 }
4459 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004460 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4461 adapter->device_mode,
4462 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004463
Anurag Chouhanc5548422016-02-24 18:33:27 +05304464 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004465 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466 updateIE.smeSessionId = adapter->sessionId;
4467 updateIE.ieBufferlength = 0;
4468 updateIE.pAdditionIEBuffer = NULL;
4469 updateIE.append = false;
4470 updateIE.notify = false;
4471 /* Probe bcn reset */
4472 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4473 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304474 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004475 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004476 }
4477 /* Assoc resp reset */
4478 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4479 &updateIE,
4480 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304481 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004482 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004483 }
4484 /* Reset WNI_CFG_PROBE_RSP Flags */
4485 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004487 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4488 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304489 /*
4490 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4491 */
4492 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4493 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4494
Peng Xu66162de2016-02-11 17:01:20 -08004495 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004496 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004497 mutex_unlock(&hdd_ctx->sap_lock);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304498
4499#ifdef WLAN_OPEN_SOURCE
4500 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4501#endif
4502
4503#ifdef WLAN_NS_OFFLOAD
4504#ifdef WLAN_OPEN_SOURCE
4505 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4506#endif
4507#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004508 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004509 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004510 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004511 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004512 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004513 break;
4514 default:
4515 break;
4516 }
4517
4518 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304519 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004520}
4521
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304522/**
4523 * hdd_deinit_all_adapters - deinit all adapters
4524 * @hdd_ctx: HDD context
4525 * @rtnl_held: True if RTNL lock held
4526 *
4527 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004528void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304529{
4530 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4531 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004532 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304533
4534 ENTER();
4535
4536 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4537
4538 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004539 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304540 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4541 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4542 adapter_node = next;
4543 }
4544
4545 EXIT();
4546}
4547
Dustin Brown27cd9942017-09-27 16:11:44 -07004548QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4549 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004550{
4551 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304552 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004553 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004554
4555 ENTER();
4556
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304557 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4558
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004559 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4560
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304561 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004562 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004563 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004564 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4565 adapterNode = pNext;
4566 }
4567
4568 EXIT();
4569
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304570 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571}
4572
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004573QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574{
4575 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304576 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004577 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004578 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004579 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004580
4581 ENTER();
4582
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304583 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4584
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004585 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4586
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304587 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004588 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004589 hdd_notice("Disabling queues for adapter type: %d",
4590 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304591
4592 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004593 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304594 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004595 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304596
Arun Khandavallicc544b32017-01-30 19:52:16 +05304597 if (hdd_ctx->config->sap_internal_restart &&
4598 adapter->device_mode == QDF_SAP_MODE) {
4599 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304600 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304601 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004602 if (test_bit(SOFTAP_BSS_STARTED,
4603 &adapter->event_flags)) {
4604 hdd_sap_indicate_disconnect_for_sta(adapter);
4605 hdd_cleanup_actionframe(hdd_ctx, adapter);
4606 hdd_sap_destroy_events(adapter);
4607 }
4608 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4609 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304610 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304611 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004612 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004613 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004614
Jeff Johnson690fe952017-10-25 11:48:39 -07004615 adapter->sessionCtx.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004616
4617 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004618 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4619 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004620 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4621 hdd_wmm_adapter_close(adapter);
4622 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4623 }
4624
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304625 if (adapter->device_mode == QDF_STA_MODE)
4626 hdd_clear_fils_connection_info(adapter);
4627
Wu Gao3545e642017-07-14 19:24:41 +08004628 if (adapter->device_mode == QDF_SAP_MODE) {
4629 /*
4630 * If adapter is SAP, set session ID to invalid
4631 * since SAP session will be cleanup during SSR.
4632 */
Wu Gao36717432016-11-21 15:09:48 +08004633 wlansap_set_invalid_session(
4634 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4635
Wu Gao3545e642017-07-14 19:24:41 +08004636 wlansap_cleanup_cac_timer(
4637 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4638 }
4639
Yue Mad5b4b9f2017-05-26 16:23:40 -07004640 /* Delete peers if any for STA and P2P client modes */
4641 if (adapter->device_mode == QDF_STA_MODE ||
4642 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004643 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004644 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004645 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004646
4647 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4648 peerMacAddr.bytes);
4649 }
4650
Yue Maf9782842017-05-08 12:49:49 -07004651 /* Destroy vdev which will be recreated during reinit. */
4652 hdd_vdev_destroy(adapter);
4653
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004654 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4655 adapterNode = pNext;
4656 }
4657
4658 EXIT();
4659
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304660 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004661}
4662
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004663bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304664{
4665 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4666 QDF_STATUS status;
4667 bool close_modules = true;
4668
Arun Khandavalliba479c42017-07-26 21:29:40 +05304669 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4670 hdd_info("FTM mode, don't close the module");
4671 return false;
4672 }
4673
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304674 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4675 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4676 if (test_bit(DEVICE_IFACE_OPENED,
Yeshwanth Sriram Guntuka4ce0a1b2017-10-17 17:55:45 +05304677 &adapter_node->adapter->event_flags) ||
4678 test_bit(SME_SESSION_OPENED,
4679 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004680 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304681 close_modules = false;
4682 break;
4683 }
4684 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4685 adapter_node = next;
4686 }
4687
4688 return close_modules;
4689}
4690
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304691bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304692{
4693 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4694 return true;
4695 else
4696 return false;
4697}
4698
Anurag Chouhanc4092922016-09-08 15:56:11 +05304699#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004700 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304701struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4702 struct ieee80211_channel *channel,
4703 const u8 *bssid, const u8 *ssid,
4704 size_t ssid_len)
4705{
4706 return cfg80211_get_bss(wiphy, channel, bssid,
4707 ssid, ssid_len,
4708 WLAN_CAPABILITY_ESS,
4709 WLAN_CAPABILITY_ESS);
4710}
4711#else
4712struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4713 struct ieee80211_channel *channel,
4714 const u8 *bssid, const u8 *ssid,
4715 size_t ssid_len)
4716{
4717 return cfg80211_get_bss(wiphy, channel, bssid,
4718 ssid, ssid_len,
4719 IEEE80211_BSS_TYPE_ESS,
4720 IEEE80211_PRIVACY_ANY);
4721}
4722#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304723
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304724#if defined CFG80211_CONNECT_BSS || \
4725 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304726#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304727 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304728/**
4729 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4730 * @timeout_reason: reason for connect timeout
4731 *
4732 * This function is used to convert host timeout
4733 * reason enum to kernel specific enum.
4734 *
4735 * Return: nl timeout enum
4736 */
4737static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4738 tSirResultCodes timeout_reason)
4739{
4740 switch (timeout_reason) {
4741 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4742 return NL80211_TIMEOUT_SCAN;
4743 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4744 return NL80211_TIMEOUT_AUTH;
4745 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4746 return NL80211_TIMEOUT_ASSOC;
4747 default:
4748 return NL80211_TIMEOUT_UNSPECIFIED;
4749 }
4750}
4751
4752/**
4753 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4754 * @dev: network device
4755 * @bssid: bssid to which we want to associate
4756 * @timeout_reason: reason for connect timeout
4757 *
4758 * This API is used to send connection timeout reason to supplicant
4759 *
4760 * Return: void
4761 */
4762static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4763 const u8 *bssid,
4764 tSirResultCodes timeout_reason)
4765{
4766 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004767
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304768 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4769
4770 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4771 nl_timeout_reason);
4772}
4773
4774/**
4775 * __hdd_connect_bss() - API to send connection status to supplicant
4776 * @dev: network device
4777 * @bssid: bssid to which we want to associate
4778 * @req_ie: Request Information Element
4779 * @req_ie_len: len of the req IE
4780 * @resp_ie: Response IE
4781 * @resp_ie_len: len of ht response IE
4782 * @status: status
4783 * @gfp: Kernel Flag
4784 * @timeout_reason: reason for connect timeout
4785 *
4786 * Return: void
4787 */
4788static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4789 struct cfg80211_bss *bss, const u8 *req_ie,
4790 size_t req_ie_len, const u8 *resp_ie,
4791 size_t resp_ie_len, int status, gfp_t gfp,
4792 tSirResultCodes timeout_reason)
4793{
4794 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004795
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304796 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4797
4798 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4799 resp_ie, resp_ie_len, status, gfp,
4800 nl_timeout_reason);
4801}
4802#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304803#if defined CFG80211_CONNECT_TIMEOUT || \
4804 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304805static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4806 const u8 *bssid,
4807 tSirResultCodes timeout_reason)
4808{
4809 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4810}
4811#endif
4812
4813static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4814 struct cfg80211_bss *bss, const u8 *req_ie,
4815 size_t req_ie_len, const u8 *resp_ie,
4816 size_t resp_ie_len, int status, gfp_t gfp,
4817 tSirResultCodes timeout_reason)
4818{
4819 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4820 resp_ie, resp_ie_len, status, gfp);
4821}
4822#endif
4823
Abhishek Singha84d3952016-09-13 13:45:05 +05304824/**
4825 * hdd_connect_bss() - API to send connection status to supplicant
4826 * @dev: network device
4827 * @bssid: bssid to which we want to associate
4828 * @req_ie: Request Information Element
4829 * @req_ie_len: len of the req IE
4830 * @resp_ie: Response IE
4831 * @resp_ie_len: len of ht response IE
4832 * @status: status
4833 * @gfp: Kernel Flag
4834 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304835 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304836 *
4837 * The API is a wrapper to send connection status to supplicant
4838 *
4839 * Return: Void
4840 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304841#if defined CFG80211_CONNECT_TIMEOUT || \
4842 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05304843static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4844 struct cfg80211_bss *bss, const u8 *req_ie,
4845 size_t req_ie_len, const u8 *resp_ie,
4846 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304847 bool connect_timeout,
4848 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304849{
4850 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304851 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304852 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304853 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4854 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304855}
4856#else
4857static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4858 struct cfg80211_bss *bss, const u8 *req_ie,
4859 size_t req_ie_len, const u8 *resp_ie,
4860 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304861 bool connect_timeout,
4862 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304863{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304864 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4865 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304866}
4867#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304868
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304869#if defined(WLAN_FEATURE_FILS_SK)
4870#if defined(CFG80211_CONNECT_DONE) || \
4871 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
4872#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
4873 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304874/**
4875 * hdd_populate_fils_params() - Populate FILS keys to connect response
4876 * @fils_params: connect response to supplicant
4877 * @fils_kek: FILS kek
4878 * @fils_kek_len: FILS kek length
4879 * @pmk: FILS PMK
4880 * @pmk_len: FILS PMK length
4881 * @pmkid: PMKID
4882 * @fils_seq_num: FILS Seq number
4883 *
4884 * Return: None
4885 */
4886static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4887 *fils_params, const uint8_t *fils_kek,
4888 size_t fils_kek_len, const uint8_t *pmk,
4889 size_t pmk_len, const uint8_t *pmkid,
4890 uint16_t fils_seq_num)
4891{
4892 /* Increament seq number to be used for next FILS */
4893 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4894 fils_params->update_erp_next_seq_num = true;
4895 fils_params->fils_kek = fils_kek;
4896 fils_params->fils_kek_len = fils_kek_len;
4897 fils_params->pmk = pmk;
4898 fils_params->pmk_len = pmk_len;
4899 fils_params->pmkid = pmkid;
4900}
4901#else
4902static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4903 *fils_params, const uint8_t
4904 *fils_kek, size_t fils_kek_len,
4905 const uint8_t *pmk, size_t pmk_len,
4906 const uint8_t *pmkid,
4907 uint16_t fils_seq_num)
4908{ }
4909#endif
4910
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304911void hdd_update_hlp_info(struct net_device *dev, tCsrRoamInfo *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304912{
4913 struct sk_buff *skb;
4914 uint16_t skb_len;
4915 struct llc_snap_hdr_t *llc_hdr;
4916 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304917 uint8_t *hlp_data;
4918 uint16_t hlp_data_len;
4919 struct fils_join_rsp_params *roam_fils_params
4920 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304921 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
4922
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304923 if (!roam_fils_params) {
4924 hdd_err("FILS Roam Param NULL");
4925 return;
4926 }
4927
4928 if (!roam_fils_params->hlp_data_len || !roam_fils_params->hlp_data) {
4929 hdd_err("FILS HLP Data NULL, len %d",
4930 roam_fils_params->hlp_data_len);
4931 return;
4932 }
4933
4934 hlp_data = roam_fils_params->hlp_data;
4935 hlp_data_len = roam_fils_params->hlp_data_len;
4936
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304937 /* Calculate skb length */
4938 skb_len = (2 * ETH_ALEN) + hlp_data_len;
4939 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
4940 if (skb == NULL) {
4941 hdd_err("HLP packet nbuf alloc fails");
4942 return;
4943 }
4944
4945 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
4946 QDF_MAC_ADDR_SIZE);
4947 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
4948 QDF_MAC_ADDR_SIZE);
4949
4950 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
4951 if (IS_SNAP(llc_hdr)) {
4952 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4953 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4954 }
4955
4956 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
4957
4958 /*
4959 * This HLP packet is formed from HLP info encapsulated
4960 * in assoc response frame which is AEAD encrypted.
4961 * Hence, this checksum validation can be set unnecessary.
4962 * i.e. network layer need not worry about checksum.
4963 */
4964 skb->ip_summed = CHECKSUM_UNNECESSARY;
4965
4966 status = hdd_rx_packet_cbk(padapter, skb);
4967 if (QDF_IS_STATUS_ERROR(status)) {
4968 hdd_err("Sending HLP packet fails");
4969 return;
4970 }
4971 hdd_debug("send HLP packet to netif successfully");
4972}
4973
4974/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304975 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4976 * @dev: network device
4977 * @bssid: bssid to which we want to associate
4978 * @bss: cfg80211 bss info
4979 * @roam_info: information about connected bss
4980 * @req_ie: Request Information Element
4981 * @req_ie_len: len of the req IE
4982 * @resp_ie: Response IE
4983 * @resp_ie_len: len of ht response IE
4984 * @status: status
4985 * @gfp: allocation flags
4986 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4987 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304988 *
4989 * This API is used as wrapper to send FILS key/sequence number
4990 * params etc. to supplicant in case of FILS connection
4991 *
4992 * Return: None
4993 */
4994static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4995 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4996 const u8 *req_ie, size_t req_ie_len,
4997 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004998 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304999 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305000{
5001 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305002 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5003 struct fils_join_rsp_params *roam_fils_params =
5004 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005005
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305006 qdf_mem_zero(&fils_params, sizeof(fils_params));
5007
5008 if (!roam_fils_params) {
5009 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5010 } else {
5011 fils_params.status = status;
5012 fils_params.bssid = bssid;
5013 fils_params.timeout_reason = timeout_reason;
5014 fils_params.req_ie = req_ie;
5015 fils_params.req_ie_len = req_ie_len;
5016 fils_params.resp_ie = resp_ie;
5017 fils_params.resp_ie_len = resp_ie_len;
5018 fils_params.bss = bss;
5019 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5020 roam_fils_params->kek_len,
5021 roam_fils_params->fils_pmk,
5022 roam_fils_params->fils_pmk_len,
5023 roam_fils_params->fils_pmkid,
5024 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305025 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305026 }
5027 hdd_debug("FILS indicate connect status %d seq no %d",
5028 fils_params.status,
5029 fils_params.fils_erp_next_seq_num);
5030
5031 cfg80211_connect_done(dev, &fils_params, gfp);
5032
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305033 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305034 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305035
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305036 /* Clear all the FILS key info */
5037 if (roam_fils_params && roam_fils_params->fils_pmk)
5038 qdf_mem_free(roam_fils_params->fils_pmk);
5039 if (roam_fils_params)
5040 qdf_mem_free(roam_fils_params);
5041 roam_info->fils_join_rsp = NULL;
5042}
5043#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005044static inline void
5045hdd_connect_done(struct net_device *dev, const u8 *bssid,
5046 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
5047 const u8 *req_ie, size_t req_ie_len,
5048 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5049 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305050 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305051{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305052#endif
5053#endif
5054
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305055#if defined(WLAN_FEATURE_FILS_SK) && \
5056 (defined(CFG80211_CONNECT_DONE) || \
5057 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305058/**
5059 * hdd_fils_update_connect_results() - API to send fils connection status to
5060 * supplicant.
5061 * @dev: network device
5062 * @bssid: bssid to which we want to associate
5063 * @bss: cfg80211 bss info
5064 * @roam_info: information about connected bss
5065 * @req_ie: Request Information Element
5066 * @req_ie_len: len of the req IE
5067 * @resp_ie: Response IE
5068 * @resp_ie_len: len of ht response IE
5069 * @status: status
5070 * @gfp: allocation flags
5071 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5072 * @timeout_reason: reason for connect timeout
5073 *
5074 * The API is a wrapper to send connection status to supplicant
5075 *
5076 * Return: 0 if success else failure
5077 */
5078static int hdd_fils_update_connect_results(struct net_device *dev,
5079 const u8 *bssid,
5080 struct cfg80211_bss *bss,
5081 tCsrRoamInfo *roam_info, const u8 *req_ie,
5082 size_t req_ie_len, const u8 *resp_ie,
5083 size_t resp_ie_len, u16 status, gfp_t gfp,
5084 bool connect_timeout,
5085 tSirResultCodes timeout_reason)
5086{
5087 ENTER();
5088 if (!roam_info || !roam_info->is_fils_connection)
5089 return -EINVAL;
5090
5091 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5092 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305093 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305094 return 0;
5095}
5096#else
5097static inline int hdd_fils_update_connect_results(struct net_device *dev,
5098 const u8 *bssid,
5099 struct cfg80211_bss *bss,
5100 tCsrRoamInfo *roam_info, const u8 *req_ie,
5101 size_t req_ie_len, const u8 *resp_ie,
5102 size_t resp_ie_len, u16 status, gfp_t gfp,
5103 bool connect_timeout,
5104 tSirResultCodes timeout_reason)
5105{
5106 return -EINVAL;
5107}
5108#endif
5109
Anurag Chouhanc4092922016-09-08 15:56:11 +05305110/**
5111 * hdd_connect_result() - API to send connection status to supplicant
5112 * @dev: network device
5113 * @bssid: bssid to which we want to associate
5114 * @roam_info: information about connected bss
5115 * @req_ie: Request Information Element
5116 * @req_ie_len: len of the req IE
5117 * @resp_ie: Response IE
5118 * @resp_ie_len: len of ht response IE
5119 * @status: status
5120 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305121 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305122 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305123 *
5124 * The API is a wrapper to send connection status to supplicant
5125 * and allow runtime suspend
5126 *
5127 * Return: Void
5128 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305129void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5130 tCsrRoamInfo *roam_info, const u8 *req_ie,
5131 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305132 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305133 bool connect_timeout,
5134 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305135{
Jeff Johnson9d295242017-08-29 14:39:48 -07005136 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305137 struct cfg80211_bss *bss = NULL;
5138
5139 if (WLAN_STATUS_SUCCESS == status) {
5140 struct ieee80211_channel *chan;
5141 int freq;
5142 int chan_no = roam_info->pBssDesc->channelId;
5143
5144 if (chan_no <= 14)
5145 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005146 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305147 else
5148 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005149 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305150
5151 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5152 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5153 roam_info->u.pConnectedProfile->SSID.ssId,
5154 roam_info->u.pConnectedProfile->SSID.length);
5155 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305156
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305157 if (hdd_fils_update_connect_results(dev, bssid, bss,
5158 roam_info, req_ie, req_ie_len, resp_ie,
5159 resp_ie_len, status, gfp, connect_timeout,
5160 timeout_reason) != 0) {
5161 hdd_connect_bss(dev, bssid, bss, req_ie,
5162 req_ie_len, resp_ie, resp_ie_len,
5163 status, gfp, connect_timeout, timeout_reason);
5164 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305165
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005166 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005167 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305168}
5169#else
5170void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5171 tCsrRoamInfo *roam_info, const u8 *req_ie,
5172 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305173 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305174 bool connect_timeout,
5175 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305176{
Jeff Johnson9d295242017-08-29 14:39:48 -07005177 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305178
Anurag Chouhanc4092922016-09-08 15:56:11 +05305179 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5180 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005181
5182 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005183 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305184}
5185#endif
5186
5187
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005188QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005189{
5190 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305191 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005192 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005193#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305194 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005195#endif
5196 eConnectionState connState;
5197
5198 ENTER();
5199
5200 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305201 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005202 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203
Arun Khandavallifae92942016-08-01 13:31:08 +05305204 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305205 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005207 hdd_wmm_init(adapter);
5208
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005209 adapter->scan_info.mScanPending = false;
5210
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005211 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005212 case QDF_STA_MODE:
5213 case QDF_P2P_CLIENT_MODE:
5214 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005215
5216 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5217 ->conn_info.connState;
5218
5219 hdd_init_station_mode(adapter);
5220 /* Open the gates for HDD to receive Wext commands */
5221 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005222
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005223 /* Indicate disconnect event to supplicant
5224 * if associated previously
5225 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005226 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005227 eConnectionState_IbssConnected == connState ||
5228 eConnectionState_NotConnected == connState ||
5229 eConnectionState_IbssDisconnected == connState ||
5230 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233 memset(&wrqu, '\0', sizeof(wrqu));
5234 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5235 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5236 wireless_send_event(adapter->dev, SIOCGIWAP,
5237 &wrqu, NULL);
5238 adapter->sessionCtx.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005239 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240
5241 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305242 wlan_hdd_cfg80211_indicate_disconnect(
5243 adapter->dev, false,
5244 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005245 } else if (eConnectionState_Connecting == connState) {
5246 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005247 * Indicate connect failure to supplicant if we
5248 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305250 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305251 NULL, 0, NULL, 0,
5252 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005253 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254 }
5255
5256 hdd_register_tx_flow_control(adapter,
5257 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005258 hdd_tx_resume_cb,
5259 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005260
5261 break;
5262
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005263 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005264 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305265 hdd_init_ap_mode(adapter, true);
5266
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005267 break;
5268
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005269 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005270#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005271 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005272 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5273#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005274 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005275 /* event supplicant to restart */
5276 cfg80211_del_sta(adapter->dev,
5277 (const u8 *)&bcastMac.bytes[0],
5278 GFP_KERNEL);
5279#endif
5280 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305281 case QDF_MONITOR_MODE:
5282 hdd_init_station_mode(adapter);
5283 hdd_set_mon_rx_cb(adapter->dev);
5284 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5285 adapter->mon_bandwidth);
5286 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 default:
5288 break;
5289 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005290 /*
5291 * Action frame registered in one adapter which will
5292 * applicable to all interfaces
5293 */
5294 wlan_hdd_cfg80211_register_frames(adapter);
5295
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305296get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005297 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5298 adapterNode = pNext;
5299 }
5300
5301 EXIT();
5302
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305303 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005304}
5305
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005306QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005307 hdd_adapter_list_node_t **padapterNode)
5308{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305309 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005310
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005311 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305312 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5313 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005314 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005315 return status;
5316}
5317
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005318QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319 hdd_adapter_list_node_t *adapterNode,
5320 hdd_adapter_list_node_t **pNextAdapterNode)
5321{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305322 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005323
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005324 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305325 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5326 (qdf_list_node_t *) adapterNode,
5327 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005328
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005329 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005330 return status;
5331}
5332
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005333QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005334 hdd_adapter_list_node_t *adapterNode)
5335{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305336 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005337
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005338 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305339 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005340 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005341 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005342 return status;
5343}
5344
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005345QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005346 hdd_adapter_list_node_t **padapterNode)
5347{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305348 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005349
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005350 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305351 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5352 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005353 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005354 return status;
5355}
5356
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005357QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005358 hdd_adapter_list_node_t *adapterNode)
5359{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305360 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005361
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005362 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305363 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5364 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005365 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005366 return status;
5367}
5368
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005369QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005370 hdd_adapter_list_node_t *adapterNode)
5371{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305372 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005373
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005374 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305375 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5376 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005377 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005378 return status;
5379}
5380
Jeff Johnson9d295242017-08-29 14:39:48 -07005381struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005382 tSirMacAddr macAddr)
5383{
5384 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005385 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305386 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005387
5388 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5389
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305390 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005391 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392
5393 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305394 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005395 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005396 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005397
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005398 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5399 adapterNode = pNext;
5400 }
5401
5402 return NULL;
5403
5404}
5405
Jeff Johnson9d295242017-08-29 14:39:48 -07005406struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005407 uint32_t vdev_id)
5408{
5409 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005410 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305411 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305413 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005414
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305415 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005416 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005417
5418 if (adapter->sessionId == vdev_id)
5419 return adapter;
5420
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305421 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005422 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5423 adapterNode = pNext;
5424 }
5425
Jeff Johnson5880d792016-08-15 13:32:30 -07005426 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005427
5428 return NULL;
5429}
5430
Abhishek Singh7996eb72015-12-30 17:24:02 +05305431/**
5432 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5433 * the sessionid
5434 * @hdd_ctx: hdd context.
5435 * @sme_session_id: sme session is for the adapter to get.
5436 *
5437 * This function is used to get the adapter with provided session id
5438 *
5439 * Return: adapter pointer if found
5440 *
5441 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005442struct hdd_adapter *
5443hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5444 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305445{
5446 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005447 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305448 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305449
5450
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305451 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305452
5453 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305454 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005455 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305456
5457 if (adapter &&
5458 adapter->sessionId == sme_session_id)
5459 return adapter;
5460
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305461 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305462 hdd_get_next_adapter(hdd_ctx,
5463 adapter_node, &next);
5464 adapter_node = next;
5465 }
5466 return NULL;
5467}
5468
Jeff Johnson9d295242017-08-29 14:39:48 -07005469struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005470 const char *iface_name)
5471{
5472 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005473 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005474 QDF_STATUS qdf_status;
5475
5476 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5477
5478 while ((NULL != adapter_node) &&
5479 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005480 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005481
5482 if (adapter &&
5483 !qdf_str_cmp(adapter->dev->name, iface_name))
5484 return adapter;
5485
5486 qdf_status =
5487 hdd_get_next_adapter(hdd_ctx,
5488 adapter_node, &next);
5489 adapter_node = next;
5490 }
5491 return NULL;
5492}
5493
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005494/**
5495 * hdd_get_adapter() - to get adapter matching the mode
5496 * @hdd_ctx: hdd context
5497 * @mode: adapter mode
5498 *
5499 * This routine will return the pointer to adapter matching
5500 * with the passed mode.
5501 *
5502 * Return: pointer to adapter or null
5503 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005504struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005505 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005506{
5507 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005508 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305509 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005510
5511 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5512
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305513 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005514 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005515
5516 if (adapter && (mode == adapter->device_mode))
5517 return adapter;
5518
5519 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5520 adapterNode = pNext;
5521 }
5522
5523 return NULL;
5524
5525}
5526
5527/**
5528 * hdd_get_operating_channel() - return operating channel of the device mode
5529 * @hdd_ctx: Pointer to the HDD context.
5530 * @mode: Device mode for which operating channel is required.
5531 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005532 * QDF_STA_MODE,
5533 * QDF_P2P_CLIENT_MODE,
5534 * QDF_SAP_MODE,
5535 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005536 *
5537 * This API returns the operating channel of the requested device mode
5538 *
5539 * Return: channel number. "0" id the requested device is not found OR it is
5540 * not connected.
5541 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005542uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005543 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005544{
5545 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305546 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005547 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005548 uint8_t operatingChannel = 0;
5549
5550 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5551
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305552 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005553 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005554
5555 if (mode == adapter->device_mode) {
5556 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005557 case QDF_STA_MODE:
5558 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005559 if (hdd_conn_is_connected
5560 (WLAN_HDD_GET_STATION_CTX_PTR
5561 (adapter))) {
5562 operatingChannel =
5563 (WLAN_HDD_GET_STATION_CTX_PTR
5564 (adapter))->conn_info.
5565 operationChannel;
5566 }
5567 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005568 case QDF_SAP_MODE:
5569 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005570 /* softap connection info */
5571 if (test_bit
5572 (SOFTAP_BSS_STARTED,
5573 &adapter->event_flags))
5574 operatingChannel =
5575 (WLAN_HDD_GET_AP_CTX_PTR
5576 (adapter))->operatingChannel;
5577 break;
5578 default:
5579 break;
5580 }
5581
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005582 /* Found the device of interest. break the loop */
5583 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005584 }
5585
5586 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5587 adapterNode = pNext;
5588 }
5589 return operatingChannel;
5590}
5591
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005592static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005593 hdd_ctx)
5594{
5595 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305596 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005597 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598
5599 ENTER();
5600
5601 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5602
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305603 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005604 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005605 if ((adapter->device_mode == QDF_STA_MODE) ||
5606 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5607 (adapter->device_mode == QDF_IBSS_MODE) ||
5608 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5609 (adapter->device_mode == QDF_SAP_MODE) ||
5610 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005611 wlan_hdd_cfg80211_deregister_frames(adapter);
5612 hdd_unregister_wext(adapter->dev);
5613 }
5614 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5615 adapterNode = pNext;
5616 }
5617
5618 EXIT();
5619
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305620 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005621}
5622
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005623QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005624{
5625 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305626 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005627 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005628
5629 ENTER();
5630
5631 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5632
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305633 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005634 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005635 if ((adapter->device_mode == QDF_STA_MODE) ||
5636 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5637 (adapter->device_mode == QDF_IBSS_MODE) ||
5638 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5639 (adapter->device_mode == QDF_SAP_MODE) ||
5640 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005641 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5642 adapter->sessionId, INVALID_SCAN_ID,
5643 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005644 }
5645 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5646 adapterNode = pNext;
5647 }
5648
5649 EXIT();
5650
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305651 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005652}
5653
Dustin Brownf27bce82016-11-03 12:52:27 -07005654/**
5655 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5656 * adapters
5657 * @hdd_ctx: The HDD context containing the adapters to operate on
5658 *
5659 * return: QDF_STATUS_SUCCESS
5660 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005661static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005662{
5663 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5664 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005665 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005666 int err;
5667
5668 ENTER();
5669
5670 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5671
5672 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005673 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005674 if ((adapter->device_mode == QDF_STA_MODE) ||
5675 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5676 (adapter->device_mode == QDF_IBSS_MODE) ||
5677 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5678 (adapter->device_mode == QDF_SAP_MODE) ||
5679 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5680 err = wlan_hdd_sched_scan_stop(adapter->dev);
5681 if (err)
5682 hdd_err("Unable to stop scheduled scan");
5683 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005684 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5685 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005686 adapter_node = next_node;
5687 }
5688
5689 EXIT();
5690
5691 return QDF_STATUS_SUCCESS;
5692}
5693
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005694#ifdef WLAN_NS_OFFLOAD
5695/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005696 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697 * @hdd_ctx: Pointer to hdd context
5698 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005699 * Unregister for IPv6 address change notifications.
5700 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005701 * Return: None
5702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005703static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005704{
5705 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005706}
5707
5708/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005709 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005710 * @hdd_ctx: Pointer to hdd context
5711 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005712 * Register for IPv6 address change notifications.
5713 *
5714 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005716static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005717{
5718 int ret;
5719
5720 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5721 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005722 if (ret) {
5723 hdd_err("Failed to register IPv6 notifier: %d", ret);
5724 goto out;
5725 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005726
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005727 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005728out:
5729 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005730}
5731#else
5732/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005733 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005734 * @hdd_ctx: Pointer to hdd context
5735 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005736 * Unregister for IPv6 address change notifications.
5737 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005738 * Return: None
5739 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005740static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005741{
5742}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005743
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005744/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005745 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005746 * @hdd_ctx: Pointer to hdd context
5747 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005748 * Register for IPv6 address change notifications.
5749 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005750 * Return: None
5751 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005752static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005753{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005754 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005755}
5756#endif
5757
5758/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005759 * hdd_register_notifiers - Register netdev notifiers.
5760 * @hdd_ctx: HDD context
5761 *
5762 * Register netdev notifiers like IPv4 and IPv6.
5763 *
5764 * Return: 0 on success and errno on failure
5765 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005766static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005767{
5768 int ret;
5769
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005770 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5771 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305772 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005773
5774 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5775 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5776 if (ret) {
5777 hdd_err("Failed to register IPv4 notifier: %d", ret);
5778 goto unregister_ip6_notifier;
5779 }
5780
5781 return 0;
5782
5783unregister_ip6_notifier:
5784 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005785out:
5786 return ret;
5787
5788}
5789
5790/**
5791 * hdd_unregister_notifiers - Unregister netdev notifiers.
5792 * @hdd_ctx: HDD context
5793 *
5794 * Unregister netdev notifiers like IPv4 and IPv6.
5795 *
5796 * Return: None.
5797 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005798void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005799{
5800 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5801
5802 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005803}
5804
5805/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005806 * hdd_exit_netlink_services - Exit netlink services
5807 * @hdd_ctx: HDD context
5808 *
5809 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5810 * nl service.
5811 *
5812 * Return: None.
5813 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005814static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005815{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005816 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005817 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005818 ptt_sock_deactivate_svc();
5819
5820 nl_srv_exit();
5821}
5822
5823/**
5824 * hdd_init_netlink_services- Init netlink services
5825 * @hdd_ctx: HDD context
5826 *
5827 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5828 * nl service.
5829 *
5830 * Return: 0 on success and errno on failure.
5831 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005832static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005833{
5834 int ret;
5835
Ryan Hsuceddceb2016-04-28 10:20:14 -07005836 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005837 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005838 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005839 goto out;
5840 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005841 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005842
Naveen Rawat910726a2017-03-06 11:42:51 -08005843 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005844 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005845 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005846 goto err_nl_srv;
5847 }
5848
5849 ret = ptt_sock_activate_svc();
5850 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005851 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005852 goto err_nl_srv;
5853 }
5854
5855 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005856 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005857 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005858
5859 ret = cnss_diag_activate_service();
5860 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005861 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005862 goto err_close_cesium;
5863 }
5864
5865 return 0;
5866
5867err_close_cesium:
5868 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005869 ptt_sock_deactivate_svc();
5870err_nl_srv:
5871 nl_srv_exit();
5872out:
5873 return ret;
5874}
5875
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005876/**
5877 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5878 * @hdd_ctx: HDD context.
5879 *
5880 * Destroy RX wakelock.
5881 *
5882 * Return: None.
5883 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005884static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005885{
5886 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5887}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005888
5889/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005890 * hdd_rx_wake_lock_create() - Create RX wakelock
5891 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005892 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005893 * Create RX wakelock.
5894 *
5895 * Return: None.
5896 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005897static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005898{
5899 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5900}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005901
5902/**
Houston Hoffman160db392016-10-10 17:37:51 -07005903 * hdd_context_deinit() - Deinitialize HDD context
5904 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005905 *
Houston Hoffman160db392016-10-10 17:37:51 -07005906 * Deinitialize HDD context along with all the feature specific contexts but
5907 * do not free hdd context itself. Caller of this API is supposed to free
5908 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005909 *
Houston Hoffman160db392016-10-10 17:37:51 -07005910 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005911 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005912static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005913{
Houston Hoffman160db392016-10-10 17:37:51 -07005914 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005915
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005916 hdd_sap_context_destroy(hdd_ctx);
5917
5918 hdd_rx_wake_lock_destroy(hdd_ctx);
5919
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005920 hdd_scan_context_destroy(hdd_ctx);
5921
5922 qdf_list_destroy(&hdd_ctx->hddAdapters);
5923
Houston Hoffman160db392016-10-10 17:37:51 -07005924 return 0;
5925}
5926
5927/**
5928 * hdd_context_destroy() - Destroy HDD context
5929 * @hdd_ctx: HDD context to be destroyed.
5930 *
5931 * Free config and HDD context as well as destroy all the resources.
5932 *
5933 * Return: None
5934 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005935static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005936{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005937 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305938
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305939 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5940
Houston Hoffman160db392016-10-10 17:37:51 -07005941 hdd_context_deinit(hdd_ctx);
5942
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305943 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005944 hdd_ctx->config = NULL;
5945
5946 wiphy_free(hdd_ctx->wiphy);
5947}
5948
5949/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305950 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5951 *
5952 * This function is used to destroy bug report lock
5953 *
5954 * Return: None
5955 */
5956static void wlan_destroy_bug_report_lock(void)
5957{
5958 p_cds_contextType p_cds_context;
5959
5960 p_cds_context = cds_get_global_context();
5961 if (!p_cds_context) {
5962 hdd_err("cds context is NULL");
5963 return;
5964 }
5965
5966 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5967}
5968
5969/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005970 * hdd_wlan_exit() - HDD WLAN exit function
5971 * @hdd_ctx: Pointer to the HDD Context
5972 *
5973 * This is the driver exit point (invoked during rmmod)
5974 *
5975 * Return: None
5976 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005977static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005978{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305979 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305981 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005982
5983 ENTER();
5984
Arun Khandavallifae92942016-08-01 13:31:08 +05305985 if (QDF_TIMER_STATE_RUNNING ==
5986 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005987 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305988 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005989 }
5990
Arun Khandavallifae92942016-08-01 13:31:08 +05305991 if (!QDF_IS_STATUS_SUCCESS
5992 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5993 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005994
Arun Khandavallifae92942016-08-01 13:31:08 +05305995
5996 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005997
Prashanth Bhattaab004382016-10-11 16:08:11 -07005998 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005999
6000#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306001 if (QDF_TIMER_STATE_RUNNING ==
6002 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6003 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006004 }
6005
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306006 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306007 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006008 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006009 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006010 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6011 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6012 hdd_ctx->last_acs_channel_list = NULL;
6013 hdd_ctx->num_of_channels = 0;
6014 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006016
Arun Khandavallifae92942016-08-01 13:31:08 +05306017 mutex_lock(&hdd_ctx->iface_change_lock);
6018 driver_status = hdd_ctx->driver_status;
6019 mutex_unlock(&hdd_ctx->iface_change_lock);
6020
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006021 /*
6022 * Powersave Offload Case
6023 * Disable Idle Power Save Mode
6024 */
6025 hdd_set_idle_ps_config(hdd_ctx, false);
6026
Arun Khandavallifae92942016-08-01 13:31:08 +05306027 if (driver_status != DRIVER_MODULES_CLOSED) {
6028 hdd_unregister_wext_all_adapters(hdd_ctx);
6029 /*
6030 * Cancel any outstanding scan requests. We are about to close
6031 * all of our adapters, but an adapter structure is what SME
6032 * passes back to our callback function. Hence if there
6033 * are any outstanding scan requests then there is a
6034 * race condition between when the adapter is closed and
6035 * when the callback is invoked. We try to resolve that
6036 * race condition here by canceling any outstanding scans
6037 * before we close the adapters.
6038 * Note that the scans may be cancelled in an asynchronous
6039 * manner, so ideally there needs to be some kind of
6040 * synchronization. Rather than introduce a new
6041 * synchronization here, we will utilize the fact that we are
6042 * about to Request Full Power, and since that is synchronized,
6043 * the expectation is that by the time Request Full Power has
6044 * completed, all scans will be cancelled
6045 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07006046 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05306047 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006048 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006049 hdd_stop_all_adapters(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006050 }
6051
6052 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306053 * Close the scheduler before calling cds_close to make sure
6054 * no thread is scheduled after the each module close is
6055 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006056 */
Jeff Johnson7d562272017-09-13 15:12:54 -07006057 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306058 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05306059 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306060 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006061 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006062
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306063 unregister_netdevice_notifier(&hdd_netdev_notifier);
6064
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006065 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306066
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306067 qdf_nbuf_deinit_replenish_timer();
6068
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306069 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6070 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6071 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6072
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006073 /*
6074 * Close CDS
6075 * This frees pMac(HAL) context. There should not be any call
6076 * that requires pMac access after this.
6077 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006078
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006079 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006080 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006081
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006082 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006083
6084 hdd_ipa_cleanup(hdd_ctx);
6085
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306086 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306087 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306088 /*
6089 * If there is re_init failure wiphy would have already de-registered
6090 * check the wiphy status before un-registering again
6091 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306092 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306093 wiphy_unregister(wiphy);
6094 wlan_hdd_cfg80211_deinit(wiphy);
6095 hdd_lpass_notify_stop(hdd_ctx);
6096 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006097
Arun Khandavallifae92942016-08-01 13:31:08 +05306098 hdd_exit_netlink_services(hdd_ctx);
6099 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306100#ifdef FEATURE_WLAN_CH_AVOID
6101 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6102#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306103
6104 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6105 if (driver_status)
6106 hdd_err("Pdev delete failed");
6107
6108 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6109 if (driver_status)
6110 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006111
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006112 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006113}
6114
6115void __hdd_wlan_exit(void)
6116{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006117 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006118
6119 ENTER();
6120
Anurag Chouhan6d760662016-02-20 16:05:43 +05306121 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006122 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006123 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006124 EXIT();
6125 return;
6126 }
6127
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006128 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306129 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006130
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006131 /* Do all the cleanup before deregistering the driver */
6132 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006134 EXIT();
6135}
6136
6137#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006138/**
6139 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006140 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006141 *
6142 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6143 * Then new ACS request will do a fresh scan without reusing the cached
6144 * scan information.
6145 *
6146 * Return: void
6147 */
Tang Yingying523322d2017-01-17 23:28:43 +08006148static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006149{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006150 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006151
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006152 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006153 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006154 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6155 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6156 hdd_ctx->last_acs_channel_list = NULL;
6157 hdd_ctx->num_of_channels = 0;
6158 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006159
6160 if (!hdd_ctx->hHal)
6161 return;
6162 sme_scan_flush_result(hdd_ctx->hHal);
6163}
6164#endif
6165
6166#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006167int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6168 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006169{
6170 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306171 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006172 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173
6174 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6175
6176 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306177 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006178 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306179
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006180 if (!hdd_ctx->hHal)
6181 return -EINVAL;
6182
Jeff Johnsone7672e72017-10-21 15:10:04 -07006183 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006184 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306185 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006186 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006187 return -EINVAL;
6188 }
6189
6190 return 0;
6191}
6192#endif
6193
6194/**
6195 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6196 * @state: state
6197 *
6198 * This function notifies FW with modem power status
6199 *
6200 * Return: 0 if successful, error number otherwise
6201 */
6202int hdd_wlan_notify_modem_power_state(int state)
6203{
6204 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306205 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006206 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006207
Anurag Chouhan6d760662016-02-20 16:05:43 +05306208 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306210 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306212
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006213 if (!hdd_ctx->hHal)
6214 return -EINVAL;
6215
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306216 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6217 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006218 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006219 state);
6220 return -EINVAL;
6221 }
6222 return 0;
6223}
6224
6225/**
6226 *
6227 * hdd_post_cds_enable_config() - HDD post cds start config helper
6228 * @adapter - Pointer to the HDD
6229 *
6230 * Return: None
6231 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006232QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006233{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306234 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006235
6236 /*
6237 * Send ready indication to the HDD. This will kick off the MAC
6238 * into a 'running' state and should kick off an initial scan.
6239 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306240 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6241 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006242 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6243 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306244 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006245 }
6246
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306247 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006248}
6249
6250/* wake lock APIs for HDD */
6251void hdd_prevent_suspend(uint32_t reason)
6252{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306253 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254}
6255
6256void hdd_allow_suspend(uint32_t reason)
6257{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306258 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006259}
6260
6261void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6262{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306263 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6264 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006265}
6266
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006267/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006268QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006269{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006270
Amar Singhal6f8592b2017-04-26 14:31:58 -07006271 return sme_init_chan_list(hdd_ctx->hHal,
6272 hdd_ctx->reg.alpha2,
6273 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006274}
6275
6276/**
6277 * hdd_is_5g_supported() - check if hardware supports 5GHz
6278 * @hdd_ctx: Pointer to the hdd context
6279 *
6280 * HDD function to know if hardware supports 5GHz
6281 *
6282 * Return: true if hardware supports 5GHz
6283 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006284bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006285{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006286 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006287 return true;
6288
Amar Singhal58b45ef2017-08-01 13:43:54 -07006289 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006290 return true;
6291 else
6292 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006293}
6294
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006295static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006296{
6297 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006298 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006299
6300 wiphy = hdd_ctx->wiphy;
6301
6302 /*
6303 * The channel information in
6304 * wiphy needs to be initialized before wiphy registration
6305 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006306 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6307 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006308 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006309 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006310 }
6311
6312#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6313 wiphy->wowlan = &wowlan_support_reg_init;
6314#else
6315 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6316 WIPHY_WOWLAN_MAGIC_PKT |
6317 WIPHY_WOWLAN_DISCONNECT |
6318 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6319 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6320 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6321 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6322 WIPHY_WOWLAN_RFKILL_RELEASE;
6323
6324 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6325 WOW_MAX_FILTERS_PER_LIST);
6326 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6327 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6328#endif
6329
6330 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006331 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306332 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006333 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306334 return ret_val;
6335 }
6336
Amar Singhal5cccafe2017-02-15 12:42:58 -08006337 if (!hdd_ctx->reg_offload)
6338 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006339
Amar Singhale4f28ee2015-10-21 14:36:56 -07006340 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006341}
6342
Ravi Joshie2331e82015-07-01 18:18:54 -07006343/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006344 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006345 * @hdd_ctx - handle to hdd context
6346 * @tx_packets - transmit packet count
6347 * @rx_packets - receive packet count
6348 *
6349 * The function controls the bus bandwidth and dynamic control of
6350 * tcp delayed ack configuration
6351 *
6352 * Returns: None
6353 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006354#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006355static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006356 const uint64_t tx_packets,
6357 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006358{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006359 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006360 uint64_t temp_rx = 0;
6361 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006362 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006363 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006364 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006365 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006366 uint16_t index = 0;
6367 bool vote_level_change = false;
6368 bool rx_level_change = false;
6369 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006370
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006371 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006372 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006373 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006374 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006375 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006376 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006377 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006378 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006379
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006380 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006381 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6382 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006383 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006384 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006385 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306386 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306387 if (hdd_ctx->hbw_requested) {
6388 pld_remove_pm_qos(hdd_ctx->parent_dev);
6389 hdd_ctx->hbw_requested = false;
6390 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306391 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006392 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006393 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306394 if (!hdd_ctx->hbw_requested) {
6395 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6396 hdd_ctx->hbw_requested = true;
6397 }
6398
Nirav Shah3bbfa512016-05-12 16:43:49 +05306399 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006400 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006401 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006402 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006403 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006404
Mohit Khannaf8f96822017-05-17 17:11:59 -07006405 qdf_dp_trace_throttle_live_mode(
6406 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6407
Mohit Khannae71e2262015-11-10 09:37:24 -08006408 /* fine-tuning parameters for RX Flows */
6409 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006411 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006412
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306413 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6414 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6415 else
6416 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6417
Ravi Joshifed83572016-10-07 16:20:37 -07006418 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6419 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6420 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6421 next_rx_level = WLAN_SVC_TP_HIGH;
6422 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006423 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006424 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006425 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006426 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006427
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006428 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006429 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006430 next_rx_level, temp_rx);
6431 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006432 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006433 /* Send throughput indication only if it is enabled.
6434 * Disabling tcp_del_ack will revert the tcp stack behavior
6435 * to default delayed ack. Note that this will disable the
6436 * dynamic delayed ack mechanism across the system
6437 */
6438 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306439 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6440 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006441 &next_rx_level,
6442 sizeof(next_rx_level));
6443 }
6444
Mohit Khannae71e2262015-11-10 09:37:24 -08006445 /* fine-tuning parameters for TX Flows */
6446 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6447 hdd_ctx->prev_tx = tx_packets;
6448 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6449 next_tx_level = WLAN_SVC_TP_HIGH;
6450 else
6451 next_tx_level = WLAN_SVC_TP_LOW;
6452
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006453 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006454 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6455 next_tx_level, temp_tx);
6456 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006457 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306458 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6459 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006460 &next_tx_level,
6461 sizeof(next_tx_level));
6462 }
6463
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006464 index = hdd_ctx->hdd_txrx_hist_idx;
6465
6466 if (vote_level_change || tx_level_change || rx_level_change) {
6467 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6468 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6469 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6470 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6471 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6472 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6473 hdd_ctx->hdd_txrx_hist_idx++;
6474 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6475 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006476}
6477
6478#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306479static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006480{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006481 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306482 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006483 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306484 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306485 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6486 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006487 uint64_t total_tx = 0, total_rx = 0;
6488 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306489 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306490 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006491 bool connected = false;
6492 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6493
Prashanth Bhattaab004382016-10-11 16:08:11 -07006494 if (wlan_hdd_validate_context(hdd_ctx))
6495 return;
6496
Jingxiang Gec64e1932017-08-22 14:38:59 +08006497 if (hdd_ctx->isWiphySuspended)
6498 goto restart_timer;
6499
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006500 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306501 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006502 status =
6503 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6504
Jeff Johnson57eb2732017-10-02 11:40:20 -07006505 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006507 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306508 /*
6509 * Validate magic so we don't end up accessing
6510 * an invalid adapter.
6511 */
6512 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6513 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006514
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006515 if ((adapter->device_mode == QDF_STA_MODE ||
6516 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006517 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6518 != eConnectionState_Associated) {
6519
6520 continue;
6521 }
6522
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006523 if ((adapter->device_mode == QDF_SAP_MODE ||
6524 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006525 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6526
6527 continue;
6528 }
6529
6530 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6531 adapter->prev_tx_packets);
6532 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6533 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306534
6535 if (adapter->device_mode == QDF_SAP_MODE ||
6536 adapter->device_mode == QDF_P2P_GO_MODE ||
6537 adapter->device_mode == QDF_IBSS_MODE) {
6538
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006539 ret = cdp_get_intra_bss_fwd_pkts_count(
6540 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306541 adapter->sessionId,
6542 &fwd_tx_packets, &fwd_rx_packets);
6543 if (ret == A_OK) {
6544 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6545 fwd_tx_packets,
6546 adapter->prev_fwd_tx_packets);
6547 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6548 fwd_tx_packets,
6549 adapter->prev_fwd_rx_packets);
6550 }
6551 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006552
6553 total_rx += adapter->stats.rx_packets;
6554 total_tx += adapter->stats.tx_packets;
6555
6556 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6557 adapter->prev_tx_packets = adapter->stats.tx_packets;
6558 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306559 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6560 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006561 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6562 connected = true;
6563 }
6564
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306565 /* add intra bss forwarded tx and rx packets */
6566 tx_packets += fwd_tx_packets_diff;
6567 rx_packets += fwd_rx_packets_diff;
6568
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006569 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6570 tx_packets += (uint64_t)ipa_tx_packets;
6571 rx_packets += (uint64_t)ipa_rx_packets;
6572
Yun Park2aa880c2017-08-22 10:58:10 -07006573 if (adapter) {
6574 adapter->stats.tx_packets += ipa_tx_packets;
6575 adapter->stats.rx_packets += ipa_rx_packets;
6576 }
6577
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006578 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006579 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006580 return;
6581 }
6582
Yuanyuan Liu13738502016-04-06 17:41:37 -07006583 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006584
6585 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6586 hdd_ipa_uc_stat_request(adapter, 2);
6587
Jingxiang Gec64e1932017-08-22 14:38:59 +08006588restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006589 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006590 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006591 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306592 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006593 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006594 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006595}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006596
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306597/**
6598 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6599 * @arg: Argument of timer function
6600 *
6601 * Schedule a workqueue in this function where all the processing is done.
6602 *
6603 * Return: None.
6604 */
6605static void __hdd_bus_bw_cbk(void *arg)
6606{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006607 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306608
6609 if (wlan_hdd_validate_context(hdd_ctx))
6610 return;
6611
6612 schedule_work(&hdd_ctx->bus_bw_work);
6613}
6614
6615/**
6616 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6617 * @arg: Argument of timer function
6618 *
6619 * Return: None.
6620 */
6621static void hdd_bus_bw_cbk(void *arg)
6622{
6623 cds_ssr_protect(__func__);
6624 __hdd_bus_bw_cbk(arg);
6625 cds_ssr_unprotect(__func__);
6626}
6627
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006628int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006629{
6630 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306631 INIT_WORK(&hdd_ctx->bus_bw_work,
6632 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006633 hdd_ctx->bus_bw_timer_running = false;
6634 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306635 qdf_timer_init(NULL,
6636 &hdd_ctx->bus_bw_timer,
6637 hdd_bus_bw_cbk, (void *)hdd_ctx,
6638 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006639
6640 return 0;
6641}
6642
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006643void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006644{
Dustin Brownfce08d12017-01-17 16:29:38 -08006645 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006646 hdd_reset_tcp_delack(hdd_ctx);
6647
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006648 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306649 cancel_work_sync(&hdd_ctx->bus_bw_work);
6650 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006651 hdd_ctx->bus_bw_timer_running = false;
6652 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006653}
Lin Baic5c06882017-09-21 13:58:43 +08006654
6655void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6656{
6657 if (hdd_ctx)
6658 cancel_work_sync(&hdd_ctx->bus_bw_work);
6659}
jiadcdaf9bd2017-10-26 12:20:21 +08006660
6661void hdd_send_wlan_tp_ind(struct hdd_context *hdd_ctx)
6662{
6663 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6664 WLAN_SVC_WLAN_TP_IND, &hdd_ctx->cur_rx_level,
6665 sizeof(hdd_ctx->cur_rx_level));
6666}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006667#endif
6668
6669/**
Nirav Shahed34b212016-04-25 10:59:16 +05306670 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6671 * @hdd_ctx: hdd context
6672 *
6673 * Return: 0 for success or error code
6674 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006675static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306676{
6677 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6678 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6679 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006680 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306681 return -ENOMEM;
6682 }
6683 return 0;
6684}
6685
6686/**
6687 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6688 * @hdd_ctx: hdd context
6689 *
6690 * Return: none
6691 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006692void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306693{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306694 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6695 return;
6696
6697 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6698 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306699}
6700
Nirav Shahda008342016-05-17 18:50:40 +05306701static uint8_t *convert_level_to_string(uint32_t level)
6702{
6703 switch (level) {
6704 /* initialize the wlan sub system */
6705 case WLAN_SVC_TP_NONE:
6706 return "NONE";
6707 case WLAN_SVC_TP_LOW:
6708 return "LOW";
6709 case WLAN_SVC_TP_MEDIUM:
6710 return "MED";
6711 case WLAN_SVC_TP_HIGH:
6712 return "HIGH";
6713 default:
6714 return "INVAL";
6715 }
6716}
6717
Nirav Shahed34b212016-04-25 10:59:16 +05306718
6719/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006720 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6721 * @hdd_ctx: hdd context
6722 *
6723 * Return: none
6724 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006725void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006726{
6727 int i;
6728
6729#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006730 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306731 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006732 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006733 hdd_ctx->config->busBandwidthHighThreshold,
6734 hdd_ctx->config->busBandwidthMediumThreshold,
6735 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006736 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306737 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006738 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006739 hdd_ctx->config->tcpDelackThresholdHigh,
6740 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006741 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306742 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006743#endif
6744
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006745 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306746 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6747
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006748 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006749
6750 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006751 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006752 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006753 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006754 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6755 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006756 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006757 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6758 convert_level_to_string(
6759 hdd_ctx->hdd_txrx_hist[i].
6760 next_vote_level),
6761 convert_level_to_string(
6762 hdd_ctx->hdd_txrx_hist[i].
6763 next_rx_level),
6764 convert_level_to_string(
6765 hdd_ctx->hdd_txrx_hist[i].
6766 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006767 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006768}
6769
6770/**
6771 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6772 * @hdd_ctx: hdd context
6773 *
6774 * Return: none
6775 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006776void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006777{
6778 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306779 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6780 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006781}
6782
6783/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006784 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006785 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006786 *
6787 * Return: none
6788 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006789void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006790{
6791
Jeff Johnson9d295242017-08-29 14:39:48 -07006792 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006793 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306794 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006795 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306796 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006797
6798 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306799 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006800 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006801
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006802 hdd_debug("Netif queue operation statistics:");
6803 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306804 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006805 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306806 curr_time = qdf_system_ticks();
6807 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306808 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306809 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306810 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306811 unpause = adapter->total_unpause_time;
6812 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306813 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306814 pause = adapter->total_pause_time;
6815 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006816 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306817 qdf_system_ticks_to_msecs(total),
6818 qdf_system_ticks_to_msecs(pause),
6819 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006820 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006821
Nirav Shahda008342016-05-17 18:50:40 +05306822 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6823 qdf_time_t pause_delta = 0;
6824
6825 if (adapter->pause_map & (1 << i))
6826 pause_delta = delta;
6827
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006828 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006829 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006830 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006831 hdd_reason_type_to_string(i),
6832 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306833 adapter->queue_oper_stats[i].unpause_count,
6834 qdf_system_ticks_to_msecs(
6835 adapter->queue_oper_stats[i].total_pause_time +
6836 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006837 }
6838
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006839 hdd_debug("Netif queue operation history:");
6840 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306841 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6842
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006843 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006844
6845 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006846 /* using hdd_log to avoid printing function name */
6847 if (adapter->queue_oper_history[i].time == 0)
6848 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006849 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006850 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306851 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006852 adapter->queue_oper_history[i].time),
6853 hdd_action_type_to_string(
6854 adapter->queue_oper_history[i].netif_action),
6855 hdd_reason_type_to_string(
6856 adapter->queue_oper_history[i].netif_reason),
6857 adapter->queue_oper_history[i].pause_map);
6858 }
6859
6860 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6861 adapter_node = next;
6862 }
6863
6864
6865}
6866
6867/**
6868 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6869 * @hdd_ctx: hdd context
6870 *
6871 * Return: none
6872 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006873void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006874{
Jeff Johnson9d295242017-08-29 14:39:48 -07006875 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006876 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306877 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006878
6879 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306880 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006881 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306883 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006884 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306885 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006886 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306887 adapter->history_index = 0;
6888 adapter->start_time = adapter->last_time = qdf_system_ticks();
6889 adapter->total_pause_time = 0;
6890 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006891 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6892 adapter_node = next;
6893 }
6894}
6895
6896/**
6897 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6898 * @halHandle: Hal handle
6899 * @pContext: Pointer to the context
6900 * @sessionId: Session ID
6901 * @scanId: Scan ID
6902 * @status: Status
6903 *
6904 * This is the callback to be executed when 11d scan is completed to flush out
6905 * the scan results
6906 *
6907 * 11d scan is done during driver load and is a passive scan on all
6908 * channels supported by the device, 11d scans may find some APs on
6909 * frequencies which are forbidden to be used in the regulatory domain
6910 * the device is operating in. If these APs are notified to the supplicant
6911 * it may try to connect to these APs, thus flush out all the scan results
6912 * which are present in SME after 11d scan is done.
6913 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306914 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006915 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306916static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006917 uint8_t sessionId, uint32_t scanId,
6918 eCsrScanStatus status)
6919{
6920 ENTER();
6921
6922 sme_scan_flush_result(halHandle);
6923
6924 EXIT();
6925
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306926 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006927}
6928
6929#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6930/**
6931 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6932 * @hdd_ctx: hdd global context
6933 *
6934 * Return: none
6935 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006936static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006937{
6938 uint8_t i;
6939
6940 mutex_init(&hdd_ctx->op_ctx.op_lock);
6941 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6942 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6943 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6944 }
6945}
6946#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006947static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006948{
6949}
6950#endif
6951
Yingying Tang95409972016-10-20 15:16:15 +08006952#ifdef WLAN_FEATURE_WOW_PULSE
6953/**
6954 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006955 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006956 * @enable: enable or disable this behaviour
6957 *
6958 * Return: int
6959 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006960static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006961{
6962 struct hdd_config *pcfg_ini = phddctx->config;
6963 struct wow_pulse_mode wow_pulse_set_info;
6964 QDF_STATUS status;
6965
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006966 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006967
6968 if (false == phddctx->config->wow_pulse_support)
6969 return 0;
6970
6971 /* prepare the request to send to SME */
6972 if (enable == true) {
6973 wow_pulse_set_info.wow_pulse_enable = true;
6974 wow_pulse_set_info.wow_pulse_pin =
6975 pcfg_ini->wow_pulse_pin;
6976 wow_pulse_set_info.wow_pulse_interval_low =
6977 pcfg_ini->wow_pulse_interval_low;
6978 wow_pulse_set_info.wow_pulse_interval_high =
6979 pcfg_ini->wow_pulse_interval_high;
6980 } else {
6981 wow_pulse_set_info.wow_pulse_enable = false;
6982 wow_pulse_set_info.wow_pulse_pin = 0;
6983 wow_pulse_set_info.wow_pulse_interval_low = 0;
6984 wow_pulse_set_info.wow_pulse_interval_high = 0;
6985 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006986 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006987 wow_pulse_set_info.wow_pulse_enable,
6988 wow_pulse_set_info.wow_pulse_pin,
6989 wow_pulse_set_info.wow_pulse_interval_low,
6990 wow_pulse_set_info.wow_pulse_interval_high);
6991
6992 status = sme_set_wow_pulse(&wow_pulse_set_info);
6993 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006994 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006995 return -EIO;
6996 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006997 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006998 return 0;
6999}
7000#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007001static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007002{
7003 return 0;
7004}
7005#endif
7006
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007007#ifdef WLAN_FEATURE_FASTPATH
7008/**
7009 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7010 * @hdd_cfg: hdd config
7011 * @context: lower layer context
7012 *
7013 * Return: none
7014 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307015void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007016 void *context)
7017{
7018 if (hdd_cfg->fastpath_enable)
7019 hif_enable_fastpath(context);
7020}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007021#endif
7022
Yuanyuan Liu13738502016-04-06 17:41:37 -07007023#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007024/**
7025 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007026 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007027 * @level: thermal level
7028 *
7029 * Change IPA data path to SW path when the thermal throttle level greater
7030 * than 0, and restore the original data path when throttle level is 0
7031 *
7032 * Return: none
7033 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007034static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007035{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007036 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007037
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007038 /* Change IPA to SW path when throttle level greater than 0 */
7039 if (level > THROTTLE_LEVEL_0)
7040 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7041 else
7042 /* restore original concurrency mode */
7043 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7044}
7045
7046/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307047 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7048 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307049 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007050 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307051 * Get a safe channel to restart SAP. PCL already takes into account the
7052 * unsafe channels. So, the PCL is validated with the ACS range to provide
7053 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007054 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307055 * Return: Channel number to restart SAP in case of success. In case of any
7056 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007057 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307058static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007059 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007060{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307061 struct sir_pcl_list pcl;
7062 QDF_STATUS status;
7063 uint32_t i, j;
7064 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007065 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307066 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007067
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307068 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7069 if (!hdd_ctx) {
7070 hdd_err("invalid HDD context");
7071 return INVALID_CHANNEL_ID;
7072 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007073
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307074 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7075 if (!hal_handle) {
7076 hdd_err("invalid HAL handle");
7077 return INVALID_CHANNEL_ID;
7078 }
7079
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007080 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7081 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007082 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7083 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307084 if (QDF_IS_STATUS_ERROR(status)) {
7085 hdd_err("Get PCL failed");
7086 return INVALID_CHANNEL_ID;
7087 }
7088
Frank Liudc2cefb2017-06-21 15:38:18 +08007089 /*
7090 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7091 * channel is unsafe channel, the pcl may be empty, instead of return,
7092 * try to choose a safe channel from acs range.
7093 */
7094 if (!pcl.pcl_len)
7095 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307096
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007097 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307098 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7099 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7100
7101 /* PCL already takes unsafe channel into account */
7102 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007103 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307104 if ((pcl.pcl_list[i] >=
7105 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7106 (pcl.pcl_list[i] <=
7107 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007108 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307109 return pcl.pcl_list[i];
7110 }
7111 }
7112
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007113 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307114
7115 /* Try for safe channel from all valid channel */
7116 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007117 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307118 &pcl.pcl_len);
7119 if (QDF_IS_STATUS_ERROR(status)) {
7120 hdd_err("error in getting valid channel list");
7121 return INVALID_CHANNEL_ID;
7122 }
7123
7124 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007125 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307126 found = false;
7127 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007128 if (pcl.pcl_list[i] ==
7129 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007130 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307131 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007132 break;
7133 }
7134 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307135
7136 if (found)
7137 continue;
7138
7139 if ((pcl.pcl_list[i] >=
7140 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7141 (pcl.pcl_list[i] <=
7142 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007143 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307144 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007145 }
7146 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307147
7148 return INVALID_CHANNEL_ID;
7149}
7150
7151/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007152 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307153 * @adapter: AP adapter
7154 * @channel: Channel
7155 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007156 * Moves the SAP interface by invoking the function which
7157 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307158 *
7159 * Return: None
7160 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007161void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307162{
Jeff Johnson87251032017-08-29 13:31:11 -07007163 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307164 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007165 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307166
7167 if (!adapter) {
7168 hdd_err("invalid adapter");
7169 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007170 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307171
7172 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7173
7174 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7175 if (!hal_handle) {
7176 hdd_err("invalid HAL handle");
7177 return;
7178 }
7179
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007180 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7181
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307182 hdd_ap_ctx->sapConfig.channel = channel;
7183 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7184 hdd_ap_ctx->sapConfig.ch_width_orig;
7185
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007186 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307187 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7188
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007189 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7190 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307191 hdd_ap_ctx->sapConfig.sec_ch,
7192 &hdd_ap_ctx->sapConfig.ch_params);
7193
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007194 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7195 adapter->sessionId, channel,
7196 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007197}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307198
Jeff Johnson9d295242017-08-29 14:39:48 -07007199int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307200{
7201 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307202 int status;
7203 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307204
7205 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7206
7207 if (QDF_TIMER_STATE_RUNNING ==
7208 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7209 ap.vendor_acs_timer)) {
7210 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7211 }
7212 timer_context = (struct hdd_external_acs_timer_context *)
7213 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7214 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307215 qdf_status =
7216 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7217 WLAN_VENDOR_ACS_WAIT_TIME);
7218 if (qdf_status != QDF_STATUS_SUCCESS) {
7219 hdd_err("failed to start external acs timer");
7220 return -ENOSPC;
7221 }
7222 /* Update config to application */
7223 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307224 hdd_notice("Updated ACS config to nl with reason %d", reason);
7225
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307226 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307227}
7228
Agrawal Ashish467dde42016-09-08 18:44:22 +05307229/**
7230 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7231 * @hdd_ctx: hdd context pointer
7232 *
7233 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7234 * and if ACS is enabled, driver will ask userspace to restart the
7235 * sap. User space on LTE coex indication restart driver.
7236 *
7237 * Return - none
7238 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007239void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307240{
7241 QDF_STATUS status;
7242 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007243 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307244 uint32_t i;
7245 bool found = false;
7246 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007247
Agrawal Ashish467dde42016-09-08 18:44:22 +05307248 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7249 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007250 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307251
7252 if (!adapter_temp) {
7253 hdd_err("adapter is NULL, moving to next one");
7254 goto next_adapater;
7255 }
7256
7257 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7258 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007259 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307260 adapter_temp->device_mode,
7261 adapter_temp->sessionCtx.ap.sapConfig.
7262 acs_cfg.acs_mode);
7263 goto next_adapater;
7264 }
7265
7266 found = false;
7267 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007268 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307269 hdd_ctxt->unsafe_channel_list[i]) {
7270 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007271 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307272 adapter_temp->sessionCtx.ap.operatingChannel);
7273 break;
7274 }
7275 }
7276
7277 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007278 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307279 adapter_temp->sessionCtx.ap.operatingChannel);
7280 goto next_adapater;
7281 }
7282
Kapil Gupta8878ad92017-02-13 11:56:04 +05307283 if (hdd_ctxt->config->vendor_acs_support &&
7284 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7285 hdd_update_acs_timer_reason(adapter_temp,
7286 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7287 goto next_adapater;
7288 } else
7289 restart_chan =
7290 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307291 adapter_temp);
7292 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007293 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307294 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007295 /*
7296 * SAP restart due to unsafe channel. While
7297 * restarting the SAP, make sure to clear
7298 * acs_channel, channel to reset to
7299 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307300 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007301 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307302 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7303 adapter_temp->sessionCtx.ap.sapConfig.channel =
7304 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007305 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307306 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7307 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007308 hdd_debug("driver to start sap: %d",
7309 hdd_ctxt->config->sap_internal_restart);
7310 if (hdd_ctxt->config->sap_internal_restart)
7311 hdd_switch_sap_channel(adapter_temp, restart_chan);
7312 else
7313 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307314 }
7315
7316next_adapater:
7317 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7318 adapter_node = next;
7319 }
7320}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307321
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007322/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007323 * hdd_init_channel_avoidance() - Initialize channel avoidance
7324 * @hdd_ctx: HDD global context
7325 *
7326 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007327 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007328 * down to the lower layers. Then subscribe to subsequent channel
7329 * avoidance events.
7330 *
7331 * Return: None
7332 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007333static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007334{
7335 uint16_t unsafe_channel_count;
7336 int index;
7337
Yuanyuan Liu13738502016-04-06 17:41:37 -07007338 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7339 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007340 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007341 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007342
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007343 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007344 hdd_ctx->unsafe_channel_count);
7345
Anurag Chouhan6d760662016-02-20 16:05:43 +05307346 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007347 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007348
7349 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007350 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007351 hdd_ctx->unsafe_channel_list[index]);
7352
7353 }
7354
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007355}
Dustin Brown676a2322017-08-15 13:16:13 -07007356
Jeff Johnson9d295242017-08-29 14:39:48 -07007357static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007358 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007359{
7360 uint8_t restart_chan;
7361
7362 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7363 if (!restart_chan) {
7364 hdd_alert("fail to restart SAP");
7365 return;
7366 }
7367
7368 /* SAP restart due to unsafe channel. While restarting
7369 * the SAP, make sure to clear acs_channel, channel to
7370 * reset to 0. Otherwise these settings will override
7371 * the ACS while restart.
7372 */
7373 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7374 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7375
7376 hdd_debug("sending coex indication");
7377
7378 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7379 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7380 hdd_switch_sap_channel(adapter, restart_chan);
7381}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007382
7383int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7384 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7385{
7386 uint32_t size;
7387 uint16_t *unsafe_list;
7388 uint16_t chan_count;
7389
7390 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7391 return -EINVAL;
7392
7393 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7394 NUM_CHANNELS);
7395 if (chan_count) {
7396 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7397 unsafe_list = qdf_mem_malloc(size);
7398 if (!unsafe_list) {
7399 hdd_err("No memory for unsafe chan list size%d",
7400 size);
7401 return -ENOMEM;
7402 }
7403 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7404 } else {
7405 unsafe_list = NULL;
7406 }
7407
7408 *local_unsafe_list = unsafe_list;
7409 *local_unsafe_list_count = chan_count;
7410
7411 return 0;
7412}
7413
7414bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7415 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7416{
7417 int i, j;
7418
7419 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7420 return true;
7421 if (local_unsafe_list_count == 0)
7422 return false;
7423 for (i = 0; i < local_unsafe_list_count; i++) {
7424 for (j = 0; j < local_unsafe_list_count; j++)
7425 if (local_unsafe_list[i] ==
7426 hdd_ctx->unsafe_channel_list[j])
7427 break;
7428 if (j >= local_unsafe_list_count)
7429 break;
7430 }
7431 if (i >= local_unsafe_list_count) {
7432 hdd_info("unsafe chan list same");
7433 return false;
7434 }
7435
7436 return true;
7437}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007438#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007439static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007440{
7441}
Dustin Brown676a2322017-08-15 13:16:13 -07007442
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007443static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007444{
7445}
Dustin Brown676a2322017-08-15 13:16:13 -07007446
Jeff Johnson9d295242017-08-29 14:39:48 -07007447static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007448 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007449{
7450 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7451}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007452#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007453
7454/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007455 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7456 * user space
7457 * @frame_ind: Management frame data to be informed.
7458 *
7459 * This function is used to indicate management frame to
7460 * user space
7461 *
7462 * Return: None
7463 *
7464 */
7465void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7466{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007467 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007468 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007469 int i;
7470
Rajeev Kumard004abc2016-02-17 12:09:56 -08007471 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007472 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007473
7474 if (0 != wlan_hdd_validate_context(hdd_ctx))
7475 return;
7476
7477 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7478 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7479 adapter =
7480 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7481 if (adapter)
7482 break;
7483 }
7484 } else {
7485 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7486 frame_ind->sessionId);
7487 }
7488
7489 if ((NULL != adapter) &&
7490 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7491 __hdd_indicate_mgmt_frame(adapter,
7492 frame_ind->frame_len,
7493 frame_ind->frameBuf,
7494 frame_ind->frameType,
7495 frame_ind->rxChan,
7496 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007497}
7498
Kapil Gupta8878ad92017-02-13 11:56:04 +05307499void hdd_acs_response_timeout_handler(void *context)
7500{
7501 struct hdd_external_acs_timer_context *timer_context =
7502 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007503 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007504 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307505 uint8_t reason;
7506
7507 ENTER();
7508 if (!timer_context) {
7509 hdd_err("invlaid timer context");
7510 return;
7511 }
7512 adapter = timer_context->adapter;
7513 reason = timer_context->reason;
7514
7515
7516 if ((!adapter) ||
7517 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7518 hdd_err("invalid adapter or adapter has invalid magic");
7519 return;
7520 }
7521 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7522 if (wlan_hdd_validate_context(hdd_ctx))
7523 return;
7524
7525 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7526 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7527 else
7528 return;
7529
7530 hdd_err("ACS timeout happened for %s reason %d",
7531 adapter->dev->name, reason);
7532 switch (reason) {
7533 /* SAP init case */
7534 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7535 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7536 false);
7537 wlan_hdd_cfg80211_start_acs(adapter);
7538 break;
7539 /* DFS detected on current channel */
7540 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7541 wlan_sap_update_next_channel(
7542 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7543 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7544 adapter->sessionId);
7545 break;
7546 /* LTE coex event on current channel */
7547 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7548 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7549 break;
7550 default:
7551 hdd_info("invalid reason for timer invoke");
7552
7553 }
7554}
7555
Rajeev Kumard004abc2016-02-17 12:09:56 -08007556/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007557 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7558 * @hdd_ctx: HDD context
7559 *
7560 * Disables all the dual mac features like DBS, Agile DFS etc.
7561 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307562 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007563 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007564static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007565{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007566 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307567 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007568
7569 if (!hdd_ctx) {
7570 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307571 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007572 }
7573
7574 cfg.scan_config = 0;
7575 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007576 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007577
7578 hdd_debug("Disabling all dual mac features...");
7579
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007580 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307581 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007582 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7583 return status;
7584 }
7585
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307586 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007587}
7588
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007589static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007590wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007591{
7592 struct policy_mgr_dual_mac_config cfg = {0};
7593 QDF_STATUS status;
7594
7595 if (!hdd_ctx) {
7596 hdd_err("HDD context is NULL");
7597 return QDF_STATUS_E_FAILURE;
7598 }
7599
7600 cfg.scan_config = 0;
7601 cfg.fw_mode_config = 0;
7602 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7603 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7604 hdd_ctx->hdd_psoc, &cfg.scan_config,
7605 &cfg.fw_mode_config,
7606 hdd_ctx->config->dual_mac_feature_disable);
7607
7608 if (status != QDF_STATUS_SUCCESS) {
7609 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7610 status);
7611 return status;
7612 }
7613
7614 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7615 cfg.scan_config, cfg.fw_mode_config);
7616
7617 status = sme_soc_set_dual_mac_config(cfg);
7618 if (status != QDF_STATUS_SUCCESS) {
7619 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7620 return status;
7621 }
7622
7623 return QDF_STATUS_SUCCESS;
7624}
7625
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007626/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007627 * hdd_override_ini_config - Override INI config
7628 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007629 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007630 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007631 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007632 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007633 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007634static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007635{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007636
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007637 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7638 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007639 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007640 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007641 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007642 if (0 == enable_11d || 1 == enable_11d) {
7643 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007644 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007645 }
Leo Chang11545d62016-10-17 14:53:50 -07007646
7647 if (!hdd_ipa_is_present(hdd_ctx))
7648 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007649}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007650
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007651/**
7652 * hdd_set_trace_level_for_each - Set trace level for each INI config
7653 * @hdd_ctx - HDD context
7654 *
7655 * Set trace level for each module based on INI config.
7656 *
7657 * Return: None
7658 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007659static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007660{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307661 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7662 hdd_ctx->config->qdf_trace_enable_wdi);
7663 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7664 hdd_ctx->config->qdf_trace_enable_hdd);
7665 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7666 hdd_ctx->config->qdf_trace_enable_sme);
7667 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7668 hdd_ctx->config->qdf_trace_enable_pe);
7669 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7670 hdd_ctx->config->qdf_trace_enable_wma);
7671 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7672 hdd_ctx->config->qdf_trace_enable_sys);
7673 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7674 hdd_ctx->config->qdf_trace_enable_qdf);
7675 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7676 hdd_ctx->config->qdf_trace_enable_sap);
7677 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7678 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7679 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7680 hdd_ctx->config->qdf_trace_enable_bmi);
7681 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7682 hdd_ctx->config->qdf_trace_enable_cfg);
7683 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7684 hdd_ctx->config->qdf_trace_enable_epping);
7685 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7686 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7687 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007688 hdd_ctx->config->qdf_trace_enable_txrx);
7689 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7690 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307691 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7692 hdd_ctx->config->qdf_trace_enable_htc);
7693 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7694 hdd_ctx->config->qdf_trace_enable_hif);
7695 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7696 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7697 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7698 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007699 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7700 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007701 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7702 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007703 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7704 hdd_ctx->config->qdf_trace_enable_regulatory);
7705
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007706 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007707}
7708
7709/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007710 * hdd_context_init() - Initialize HDD context
7711 * @hdd_ctx: HDD context.
7712 *
7713 * Initialize HDD context along with all the feature specific contexts.
7714 *
7715 * return: 0 on success and errno on failure.
7716 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007717static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007718{
7719 int ret;
7720
7721 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7722 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7723
7724 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307725 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007726
7727 init_completion(&hdd_ctx->mc_sus_event_var);
7728 init_completion(&hdd_ctx->ready_to_suspend);
7729
7730 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307731 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007732 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307733
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007734 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7735
7736 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7737
7738 ret = hdd_scan_context_init(hdd_ctx);
7739 if (ret)
7740 goto list_destroy;
7741
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007742 hdd_rx_wake_lock_create(hdd_ctx);
7743
7744 ret = hdd_sap_context_init(hdd_ctx);
7745 if (ret)
7746 goto scan_destroy;
7747
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007748 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7749
7750 hdd_init_offloaded_packets_ctx(hdd_ctx);
7751
7752 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7753 hdd_ctx->config);
7754 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08007755 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007756
7757 return 0;
7758
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007759sap_destroy:
7760 hdd_sap_context_destroy(hdd_ctx);
7761
7762scan_destroy:
7763 hdd_scan_context_destroy(hdd_ctx);
7764 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007765list_destroy:
7766 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007767
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007768 return ret;
7769}
7770
7771/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307772 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7773 * @hdd_ctx: pointer to hdd context
7774 *
7775 * Return: status of initialization
7776 * 0 - success
7777 * negative value - failure
7778 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007779static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307780{
7781 int ret;
7782
7783 if (!hdd_ctx->config->probe_req_ie_whitelist)
7784 return 0;
7785
7786 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7787 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7788 hdd_ctx->config->probe_req_ie_whitelist = false;
7789 return -EINVAL;
7790 }
7791
7792 /* parse ini string probe req oui */
7793 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7794 if (ret) {
7795 hdd_err("parsing error: disable ie whitelisting");
7796 hdd_ctx->config->probe_req_ie_whitelist = false;
7797 }
7798
7799 return ret;
7800}
7801
7802/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007803 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307804 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007805 *
7806 * Allocate and initialize HDD context. HDD context is allocated as part of
7807 * wiphy allocation and then context is initialized.
7808 *
7809 * Return: HDD context on success and ERR_PTR on failure
7810 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007811static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007812{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307813 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007814 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007815 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007816
7817 ENTER();
7818
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007819 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007820 if (hdd_ctx == NULL) {
7821 ret = -ENOMEM;
7822 goto err_out;
7823 }
7824
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007825 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307826 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007827
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307828 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007829 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007830 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007831 ret = -ENOMEM;
7832 goto err_free_hdd_context;
7833 }
7834
7835 /* Read and parse the qcom_cfg.ini file */
7836 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307837 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307838 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007839 WLAN_INI_FILE);
7840 ret = -EINVAL;
7841 goto err_free_config;
7842 }
7843
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307844 ie_whitelist_attrs_init(hdd_ctx);
7845
Dustin Brown7f939932017-05-18 15:02:17 -07007846 hdd_debug("setting timer multiplier: %u",
7847 hdd_ctx->config->timer_multiplier);
7848 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7849
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007850
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307851 if (hdd_ctx->config->fhostNSOffload)
7852 hdd_ctx->ns_offload_enable = true;
7853
Abhishek Singh5ea86532016-04-27 14:10:53 +05307854 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7855
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007856 hdd_override_ini_config(hdd_ctx);
7857
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007858 ret = hdd_context_init(hdd_ctx);
7859
7860 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007861 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007862
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007863 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307864 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007865
Anurag Chouhan6d760662016-02-20 16:05:43 +05307866 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007867 goto skip_multicast_logging;
7868
7869 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7870
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007871 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7872 if (ret)
7873 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307874
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007875 ret = hdd_init_netlink_services(hdd_ctx);
7876 if (ret)
7877 goto err_deinit_txrx_histogram;
7878
Dustin Brown7b3dea22017-07-10 13:02:47 -07007879 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7880 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307881
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007882skip_multicast_logging:
7883 hdd_set_trace_level_for_each(hdd_ctx);
7884
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007885 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7886
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007887 EXIT();
7888
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007889 return hdd_ctx;
7890
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007891err_deinit_txrx_histogram:
7892 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7893
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007894err_deinit_hdd_context:
7895 hdd_context_deinit(hdd_ctx);
7896
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007897err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307898 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007899
7900err_free_hdd_context:
7901 wiphy_free(hdd_ctx->wiphy);
7902
7903err_out:
7904 return ERR_PTR(ret);
7905}
7906
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007907#ifdef WLAN_OPEN_P2P_INTERFACE
7908/**
7909 * hdd_open_p2p_interface - Open P2P interface
7910 * @hdd_ctx: HDD context
7911 * @rtnl_held: True if RTNL lock held
7912 *
7913 * Open P2P interface during probe. This function called to open the P2P
7914 * interface at probe along with STA interface.
7915 *
7916 * Return: 0 on success and errno on failure
7917 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007918static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007919{
Jeff Johnson9d295242017-08-29 14:39:48 -07007920 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007921 uint8_t *p2p_dev_addr;
7922
7923 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7924 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307925 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007926 hdd_ctx->config->intfMacAddr[0].bytes,
7927 sizeof(tSirMacAddr));
7928
7929 /*
7930 * Generate the P2P Device Address. This consists of
7931 * the device's primary MAC address with the locally
7932 * administered bit set.
7933 */
7934 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7935 } else {
7936 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7937 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007938 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007939 return -ENOSPC;
7940 }
7941
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307942 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307943 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007944 }
7945
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007946 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007947 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007948 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007949
7950 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007951 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007952 return -ENOSPC;
7953 }
7954
7955 return 0;
7956}
7957#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007958static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007959 bool rtnl_held)
7960{
7961 return 0;
7962}
7963#endif
7964
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007965static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007966{
Jeff Johnson9d295242017-08-29 14:39:48 -07007967 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007968 int ret = 0;
7969
7970 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7971 wlan_hdd_get_intf_addr(hdd_ctx),
7972 NET_NAME_UNKNOWN, rtnl_held);
7973 if (adapter == NULL) {
7974 hdd_err("Failed to open 802.11p interface");
7975 ret = -ENOSPC;
7976 }
7977
7978 return ret;
7979}
7980
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007981/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307982 * hdd_start_station_adapter()- Start the Station Adapter
7983 * @adapter: HDD adapter
7984 *
7985 * This function initializes the adapter for the station mode.
7986 *
7987 * Return: 0 on success or errno on failure.
7988 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007989int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307990{
7991 QDF_STATUS status;
7992
7993 ENTER_DEV(adapter->dev);
7994
7995 status = hdd_init_station_mode(adapter);
7996
7997 if (QDF_STATUS_SUCCESS != status) {
7998 hdd_err("Error Initializing station mode: %d", status);
7999 return qdf_status_to_os_return(status);
8000 }
8001
Arun Khandavallifae92942016-08-01 13:31:08 +05308002 hdd_register_tx_flow_control(adapter,
8003 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008004 hdd_tx_resume_cb,
8005 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308006
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308007 EXIT();
8008 return 0;
8009}
8010
8011/**
8012 * hdd_start_ap_adapter()- Start AP Adapter
8013 * @adapter: HDD adapter
8014 *
8015 * This function initializes the adapter for the AP mode.
8016 *
8017 * Return: 0 on success errno on failure.
8018 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008019int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308020{
8021 QDF_STATUS status;
8022
8023 ENTER();
8024
Arun Khandavallicc544b32017-01-30 19:52:16 +05308025 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308026
8027 if (QDF_STATUS_SUCCESS != status) {
8028 hdd_err("Error Initializing the AP mode: %d", status);
8029 return qdf_status_to_os_return(status);
8030 }
8031
Arun Khandavallifae92942016-08-01 13:31:08 +05308032 hdd_register_tx_flow_control(adapter,
8033 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008034 hdd_softap_tx_resume_cb,
8035 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308036
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308037 EXIT();
8038 return 0;
8039}
8040
8041/**
8042 * hdd_start_ftm_adapter()- Start FTM adapter
8043 * @adapter: HDD adapter
8044 *
8045 * This function initializes the adapter for the FTM mode.
8046 *
8047 * Return: 0 on success or errno on failure.
8048 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008049int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308050{
8051 QDF_STATUS qdf_status;
8052
8053 ENTER_DEV(adapter->dev);
8054
8055 qdf_status = hdd_init_tx_rx(adapter);
8056
8057 if (QDF_STATUS_SUCCESS != qdf_status) {
8058 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8059 return qdf_status_to_os_return(qdf_status);
8060 }
8061
8062 return 0;
8063 EXIT();
8064}
8065
8066/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008067 * hdd_open_interfaces - Open all required interfaces
8068 * hdd_ctx: HDD context
8069 * rtnl_held: True if RTNL lock is held
8070 *
8071 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8072 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008073 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008074 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008075static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008076{
Jeff Johnson9d295242017-08-29 14:39:48 -07008077 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008078 int ret;
8079
Ravi Joshia307f632017-07-17 23:41:41 -07008080 /* open monitor mode adapter if con_mode is monitor mode */
8081 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8082 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8083 wlan_hdd_get_intf_addr(hdd_ctx),
8084 NET_NAME_UNKNOWN, rtnl_held);
8085 if (!adapter) {
8086 hdd_err("open adapter failed");
8087 return -ENOSPC;
8088 }
8089 return 0;
8090 }
8091
Jeff Johnson957bc272017-02-02 08:54:48 -08008092 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308093 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008094 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008095
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008096 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008097 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008098 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008099
8100 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008101 return -ENOSPC;
8102
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008103 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8104 adapter->fast_roaming_allowed = true;
8105
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008106 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8107 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008108 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008109
8110 /* Open 802.11p Interface */
8111 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008112 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8113 if (ret)
8114 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008115 }
8116
Jeff Johnson957bc272017-02-02 08:54:48 -08008117 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008118
Jeff Johnson957bc272017-02-02 08:54:48 -08008119err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008120 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008121 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008122}
8123
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008124/**
8125 * hdd_update_country_code - Update country code
8126 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008127 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008128 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008129 *
8130 * Return: 0 on success and errno on failure
8131 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008132static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008133{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008134 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008135 return 0;
8136
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008137 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008138}
8139
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308140#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8141/**
8142 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8143 * @cds_cfg: CDS Configuration
8144 * @hdd_ctx: Pointer to hdd context
8145 *
8146 * Return: none
8147 */
8148static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8149 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008150 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308151{
8152 cds_cfg->tx_flow_stop_queue_th =
8153 hdd_ctx->config->TxFlowStopQueueThreshold;
8154 cds_cfg->tx_flow_start_queue_offset =
8155 hdd_ctx->config->TxFlowStartQueueOffset;
8156}
8157#else
8158static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8159 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008160 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308161{
8162}
8163#endif
8164
8165#ifdef FEATURE_WLAN_RA_FILTERING
8166/**
8167 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8168 * @cds_cfg: CDS Configuration
8169 * @hdd_ctx: Pointer to hdd context
8170 *
8171 * Return: none
8172 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308173static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008174 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308175{
8176 cds_cfg->ra_ratelimit_interval =
8177 hdd_ctx->config->RArateLimitInterval;
8178 cds_cfg->is_ra_ratelimit_enabled =
8179 hdd_ctx->config->IsRArateLimitEnabled;
8180}
8181#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308182static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008183 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308184{
8185}
8186#endif
8187
8188/**
8189 * hdd_update_cds_config() - API to update cds configuration parameters
8190 * @hdd_ctx: HDD Context
8191 *
8192 * Return: 0 for Success, errno on failure
8193 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008194static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308195{
8196 struct cds_config_info *cds_cfg;
8197
8198 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8199 if (!cds_cfg) {
8200 hdd_err("failed to allocate cds config");
8201 return -ENOMEM;
8202 }
8203
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008204 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008205 if (!hdd_ctx->config->nMaxPsPoll ||
8206 !hdd_ctx->config->enablePowersaveOffload) {
8207 cds_cfg->powersave_offload_enabled =
8208 hdd_ctx->config->enablePowersaveOffload;
8209 } else {
8210 if ((hdd_ctx->config->enablePowersaveOffload ==
8211 PS_QPOWER_NODEEPSLEEP) ||
8212 (hdd_ctx->config->enablePowersaveOffload ==
8213 PS_LEGACY_NODEEPSLEEP))
8214 cds_cfg->powersave_offload_enabled =
8215 PS_LEGACY_NODEEPSLEEP;
8216 else
8217 cds_cfg->powersave_offload_enabled =
8218 PS_LEGACY_DEEPSLEEP;
8219 hdd_info("Qpower disabled in cds config, %d",
8220 cds_cfg->powersave_offload_enabled);
8221 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308222 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8223 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8224 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8225 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8226 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8227
8228 /* Here ol_ini_info is used to store ini status of arp offload
8229 * ns offload and others. Currently 1st bit is used for arp
8230 * off load and 2nd bit for ns offload currently, rest bits are unused
8231 */
8232 if (hdd_ctx->config->fhostArpOffload)
8233 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8234 if (hdd_ctx->config->fhostNSOffload)
8235 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8236
8237 /*
8238 * Copy the DFS Phyerr Filtering Offload status.
8239 * This parameter reflects the value of the
8240 * dfs_phyerr_filter_offload flag as set in the ini.
8241 */
8242 cds_cfg->dfs_phyerr_filter_offload =
8243 hdd_ctx->config->fDfsPhyerrFilterOffload;
8244 if (hdd_ctx->config->ssdp)
8245 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8246
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308247 cds_cfg->force_target_assert_enabled =
8248 hdd_ctx->config->crash_inject_enabled;
8249
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308250 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8251 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8252
8253 cds_cfg->ap_maxoffload_reorderbuffs =
8254 hdd_ctx->config->apMaxOffloadReorderBuffs;
8255
8256 cds_cfg->ap_disable_intrabss_fwd =
8257 hdd_ctx->config->apDisableIntraBssFwd;
8258
8259 cds_cfg->dfs_pri_multiplier =
8260 hdd_ctx->config->dfsRadarPriMultiplier;
8261 cds_cfg->reorder_offload =
8262 hdd_ctx->config->reorderOffloadSupport;
8263
8264 /* IPA micro controller data path offload resource config item */
8265 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008266 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8267 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008268 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008269 hdd_ctx->config->IpaUcTxBufCount);
8270 hdd_ctx->config->IpaUcTxBufCount =
8271 rounddown_pow_of_two(
8272 hdd_ctx->config->IpaUcTxBufCount);
8273 if (!hdd_ctx->config->IpaUcTxBufCount) {
8274 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308275 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008276 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008277 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008278 hdd_ctx->config->IpaUcTxBufCount);
8279 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308280 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8281 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008282 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8283 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008284 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008285 hdd_ctx->config->IpaUcRxIndRingCount);
8286 hdd_ctx->config->IpaUcRxIndRingCount =
8287 rounddown_pow_of_two(
8288 hdd_ctx->config->IpaUcRxIndRingCount);
8289 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8290 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308291 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008292 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008293 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008294 hdd_ctx->config->IpaUcRxIndRingCount);
8295 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308296 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008297 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308298 cds_cfg->uc_tx_partition_base =
8299 hdd_ctx->config->IpaUcTxPartitionBase;
8300 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8301
8302 cds_cfg->ip_tcp_udp_checksum_offload =
8303 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308304 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308305 cds_cfg->ce_classify_enabled =
8306 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008307 cds_cfg->bpf_packet_filter_enable =
8308 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308309 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8310 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8311 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008312 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008313 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008314 cds_cfg->max_msdus_per_rxinorderind =
8315 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008316 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008317 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308318 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8319 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308320 cds_cfg->auto_power_save_fail_mode =
8321 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308322
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308323 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008324 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308325
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308326 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8327 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8328 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008329 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308330 cds_init_ini_config(cds_cfg);
8331 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308332
8333exit:
8334 qdf_mem_free(cds_cfg);
8335 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308336}
8337
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008338/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008339 * hdd_update_user_config() - API to update user configuration
8340 * parameters to obj mgr which are used by multiple components
8341 * @hdd_ctx: HDD Context
8342 *
8343 * Return: 0 for Success, errno on failure
8344 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008345static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008346{
8347 struct wlan_objmgr_psoc_user_config *user_config;
8348
8349 user_config = qdf_mem_malloc(sizeof(*user_config));
8350 if (user_config == NULL) {
8351 hdd_alert("Failed to alloc memory for user_config!");
8352 return -ENOMEM;
8353 }
8354
8355 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8356 user_config->dual_mac_feature_disable =
8357 hdd_ctx->config->dual_mac_feature_disable;
8358 user_config->indoor_channel_support =
8359 hdd_ctx->config->indoor_channel_support;
8360 user_config->is_11d_support_enabled =
8361 hdd_ctx->config->Is11dSupportEnabled;
8362 user_config->is_11h_support_enabled =
8363 hdd_ctx->config->Is11hSupportEnabled;
8364 user_config->optimize_chan_avoid_event =
8365 hdd_ctx->config->goptimize_chan_avoid_event;
8366 user_config->skip_dfs_chnl_in_p2p_search =
8367 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008368 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008369 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8370
8371 qdf_mem_free(user_config);
8372 return 0;
8373}
8374
8375/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008376 * hdd_init_thermal_info - Initialize thermal level
8377 * @hdd_ctx: HDD context
8378 *
8379 * Initialize thermal level at SME layer and set the thermal level callback
8380 * which would be called when a configured thermal threshold is hit.
8381 *
8382 * Return: 0 on success and errno on failure
8383 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008384static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008385{
8386 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308387 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008388
8389 thermal_param.smeThermalMgmtEnabled =
8390 hdd_ctx->config->thermalMitigationEnable;
8391 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8392
Poddar, Siddarth83905022016-04-16 17:56:08 -07008393 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8394 hdd_ctx->config->throttle_dutycycle_level0;
8395 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8396 hdd_ctx->config->throttle_dutycycle_level1;
8397 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8398 hdd_ctx->config->throttle_dutycycle_level2;
8399 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8400 hdd_ctx->config->throttle_dutycycle_level3;
8401
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008402 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8403 hdd_ctx->config->thermalTempMinLevel0;
8404 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8405 hdd_ctx->config->thermalTempMaxLevel0;
8406 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8407 hdd_ctx->config->thermalTempMinLevel1;
8408 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8409 hdd_ctx->config->thermalTempMaxLevel1;
8410 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8411 hdd_ctx->config->thermalTempMinLevel2;
8412 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8413 hdd_ctx->config->thermalTempMaxLevel2;
8414 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8415 hdd_ctx->config->thermalTempMinLevel3;
8416 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8417 hdd_ctx->config->thermalTempMaxLevel3;
8418
8419 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8420
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308421 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308422 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008423
8424 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8425 hdd_set_thermal_level_cb);
8426
8427 return 0;
8428
8429}
8430
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008431#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8432/**
8433 * hdd_hold_rtnl_lock - Hold RTNL lock
8434 *
8435 * Hold RTNL lock
8436 *
8437 * Return: True if held and false otherwise
8438 */
8439static inline bool hdd_hold_rtnl_lock(void)
8440{
8441 rtnl_lock();
8442 return true;
8443}
8444
8445/**
8446 * hdd_release_rtnl_lock - Release RTNL lock
8447 *
8448 * Release RTNL lock
8449 *
8450 * Return: None
8451 */
8452static inline void hdd_release_rtnl_lock(void)
8453{
8454 rtnl_unlock();
8455}
8456#else
8457static inline bool hdd_hold_rtnl_lock(void) { return false; }
8458static inline void hdd_release_rtnl_lock(void) { }
8459#endif
8460
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008461#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008462
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308463/* MAX iwpriv command support */
8464#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308465#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308466#define MAX_PKTLOG_SIZE 16
8467
8468/**
8469 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8470 * @hdd_ctx: hdd context
8471 * @set_value2: pktlog buffer size value
8472 *
8473 *
8474 * Return: 0 for success or error.
8475 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008476static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308477{
8478 struct sir_wifi_start_log start_log = { 0 };
8479 QDF_STATUS status;
8480
8481 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8482 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8483 start_log.ini_triggered = cds_is_packet_log_enabled();
8484 start_log.user_triggered = 1;
8485 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308486 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308487
8488 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8489 if (!QDF_IS_STATUS_SUCCESS(status)) {
8490 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8491 EXIT();
8492 return -EINVAL;
8493 }
8494
8495 return 0;
8496}
8497
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008498/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308499 * hdd_pktlog_clear_buff() - clear pktlog buffer
8500 * @hdd_ctx: hdd context
8501 *
8502 * Return: 0 for success or error.
8503 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008504static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308505{
8506 struct sir_wifi_start_log start_log;
8507 QDF_STATUS status;
8508
8509 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8510 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8511 start_log.ini_triggered = cds_is_packet_log_enabled();
8512 start_log.user_triggered = 1;
8513 start_log.size = 0;
8514 start_log.is_pktlog_buff_clear = true;
8515
8516 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8517 if (!QDF_IS_STATUS_SUCCESS(status)) {
8518 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8519 EXIT();
8520 return -EINVAL;
8521 }
8522
8523 return 0;
8524}
8525
8526
8527/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008528 * hdd_process_pktlog_command() - process pktlog command
8529 * @hdd_ctx: hdd context
8530 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308531 * @set_value2: pktlog buffer size value
8532 *
8533 * This function process pktlog command.
8534 * set_value2 only matters when set_value is 3 (set buff size)
8535 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008536 *
8537 * Return: 0 for success or error.
8538 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008539int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308540 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008541{
8542 int ret;
8543 bool enable;
8544 uint8_t user_triggered = 0;
8545
8546 ret = wlan_hdd_validate_context(hdd_ctx);
8547 if (0 != ret)
8548 return ret;
8549
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008550 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008551
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308552 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008553 hdd_err("invalid pktlog value %d", set_value);
8554 return -EINVAL;
8555 }
8556
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308557 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8558 if (set_value2 <= 0) {
8559 hdd_err("invalid pktlog size %d", set_value2);
8560 return -EINVAL;
8561 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8562 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8563 return -EINVAL;
8564 }
8565 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308566 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8567 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308568 }
8569
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008570 /*
8571 * set_value = 0 then disable packetlog
8572 * set_value = 1 enable packetlog forcefully
8573 * set_vlaue = 2 then disable packetlog if disabled through ini or
8574 * enable packetlog with AUTO type.
8575 */
8576 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8577 true : false;
8578
8579 if (1 == set_value) {
8580 enable = true;
8581 user_triggered = 1;
8582 }
8583
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308584 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008585}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008586
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008587/**
8588 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8589 * @hdd_ctx: HDD context
8590 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308591 * @user_triggered: triggered through iwpriv
8592 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008593 *
8594 * Return: 0 on success; error number otherwise
8595 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008596int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308597 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008598{
8599 struct sir_wifi_start_log start_log;
8600 QDF_STATUS status;
8601
8602 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8603 start_log.verbose_level =
8604 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008605 start_log.ini_triggered = cds_is_packet_log_enabled();
8606 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308607 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308608 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308609 /*
8610 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8611 * commands. Host uses this flag to decide whether to send pktlog
8612 * disable command to fw without sending pktlog enable command
8613 * previously. For eg, If vendor sends pktlog disable command without
8614 * sending pktlog enable command, then host discards the packet
8615 * but for iwpriv command, host will send it to fw.
8616 */
8617 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008618 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8619 if (!QDF_IS_STATUS_SUCCESS(status)) {
8620 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8621 EXIT();
8622 return -EINVAL;
8623 }
8624
8625 return 0;
8626}
8627#endif /* REMOVE_PKT_LOG */
8628
Komal Seelam92fff912016-03-24 11:51:41 +05308629/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008630 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8631 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308632 * @dev: Device Pointer
8633 * @num: Number of Valid Mac address
8634 *
8635 * Return: Pointer to MAC address buffer
8636 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008637static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8638 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308639{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008640 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308641}
Komal Seelam92fff912016-03-24 11:51:41 +05308642
8643/**
8644 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8645 * @hdd_ctx: HDD Context
8646 * @num: Number of random mac addresses needed
8647 *
8648 * Generate random addresses using bit manipulation on the base mac address
8649 *
8650 * Return: None
8651 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008652void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308653{
8654 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8655 uint32_t iter;
8656 struct hdd_config *ini = hdd_ctx->config;
8657 uint8_t *buf = NULL;
8658 uint8_t macaddr_b3, tmp_br3;
8659 uint8_t *src = ini->intfMacAddr[0].bytes;
8660
8661 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8662 buf = ini->intfMacAddr[iter].bytes;
8663 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8664 macaddr_b3 = buf[3];
8665 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8666 INTF_MACADDR_MASK;
8667 macaddr_b3 += tmp_br3;
8668 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8669 buf[0] |= 0x02;
8670 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008671 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308672 }
8673}
8674
8675/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008676 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308677 * @hdd_ctx: HDD Context
8678 *
8679 * API to get mac addresses from platform driver and update the driver
8680 * structures and configure FW with the base mac address.
8681 * Return: int
8682 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008683static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308684{
8685 uint32_t no_of_mac_addr, iter;
8686 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8687 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8688 uint8_t *addr, *buf;
8689 struct device *dev = hdd_ctx->parent_dev;
8690 struct hdd_config *ini = hdd_ctx->config;
8691 tSirMacAddr mac_addr;
8692 QDF_STATUS status;
8693
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008694 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308695
8696 if (no_of_mac_addr == 0 || !addr) {
8697 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8698 return -EINVAL;
8699 }
8700
8701 if (no_of_mac_addr > max_mac_addr)
8702 no_of_mac_addr = max_mac_addr;
8703
8704 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8705
8706 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8707 buf = ini->intfMacAddr[iter].bytes;
8708 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008709 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308710 }
8711
8712 status = sme_set_custom_mac_addr(mac_addr);
8713
8714 if (!QDF_IS_STATUS_SUCCESS(status))
8715 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008716
Komal Seelam92fff912016-03-24 11:51:41 +05308717 if (no_of_mac_addr < max_mac_addr)
8718 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8719 no_of_mac_addr);
8720 return 0;
8721}
8722
8723/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008724 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8725 * @hdd_ctx: HDD Context
8726 *
8727 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8728 * will generate its own MAC and update it to FW.
8729 *
8730 * Return: 0 for success
8731 * Non-zero error code for failure
8732 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008733static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008734{
8735 tSirMacAddr customMacAddr;
8736 QDF_STATUS status;
8737
8738 qdf_mem_copy(&customMacAddr,
8739 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8740 sizeof(tSirMacAddr));
8741 status = sme_set_custom_mac_addr(customMacAddr);
8742 if (!QDF_IS_STATUS_SUCCESS(status))
8743 return -EAGAIN;
8744 return 0;
8745}
8746
8747/**
Komal Seelam92fff912016-03-24 11:51:41 +05308748 * hdd_initialize_mac_address() - API to get wlan mac addresses
8749 * @hdd_ctx: HDD Context
8750 *
8751 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8752 * is provisioned with mac addresses, driver uses it, else it will use
8753 * wlan_mac.bin to update HW MAC addresses.
8754 *
8755 * Return: None
8756 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008757static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308758{
8759 QDF_STATUS status;
8760 int ret;
8761
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008762 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308763 if (ret == 0)
8764 return;
8765
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008766 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8767 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308768
8769 status = hdd_update_mac_config(hdd_ctx);
8770
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008771 if (QDF_IS_STATUS_SUCCESS(status))
8772 return;
8773
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008774 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8775 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008776
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008777 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008778 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008779 if (ret != 0) {
8780 hdd_err("MAC address out-of-sync, ret:%d", ret);
8781 QDF_ASSERT(ret);
8782 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008783 }
Komal Seelam92fff912016-03-24 11:51:41 +05308784}
8785
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008786static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008787{
8788 int vdev_id = 0;
8789 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8790 int value = hdd_ctx->config->smart_chainmask_enabled;
8791 int vpdev = PDEV_CMD;
8792 int ret;
8793
Naveen Rawat247a8682017-06-05 15:00:31 -07008794 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008795 if (ret)
8796 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8797
8798 return ret;
8799}
8800
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008801static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008802{
8803 int vdev_id = 0;
8804 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8805 int value = hdd_ctx->config->alternative_chainmask_enabled;
8806 int vpdev = PDEV_CMD;
8807 int ret;
8808
Naveen Rawat247a8682017-06-05 15:00:31 -07008809 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008810 if (ret)
8811 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8812 ret);
8813
8814 return ret;
8815}
8816
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008817static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008818{
8819 int vdev_id = 0;
8820 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8821 int value = hdd_ctx->config->ani_enabled;
8822 int vpdev = PDEV_CMD;
8823 int ret;
8824
Naveen Rawat247a8682017-06-05 15:00:31 -07008825 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008826 if (ret)
8827 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8828
8829 return ret;
8830}
8831
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008832/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008833 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8834 * @hdd_ctx: HDD context
8835 *
8836 * Pre configurations to be done at lower layer before calling cds enable.
8837 *
8838 * Return: 0 on success and errno on failure.
8839 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008840static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008841{
8842 int ret;
8843 QDF_STATUS status;
8844 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008845 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008846
Leo Changfdb45c32016-10-28 11:09:23 -07008847 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008848 /*
8849 * Set 802.11p config
8850 * TODO-OCB: This has been temporarily added here to ensure this
8851 * parameter is set in CSR when we init the channel list. This should
8852 * be removed once the 5.9 GHz channels are added to the regulatory
8853 * domain.
8854 */
8855 hdd_set_dot11p_config(hdd_ctx);
8856
8857 /*
8858 * Note that the cds_pre_enable() sequence triggers the cfg download.
8859 * The cfg download must occur before we update the SME config
8860 * since the SME config operation must access the cfg database
8861 */
8862 status = hdd_set_sme_config(hdd_ctx);
8863
8864 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008865 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008866 ret = qdf_status_to_os_return(status);
8867 goto out;
8868 }
8869
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008870 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8871 if (QDF_STATUS_SUCCESS != status) {
8872 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8873 ret = qdf_status_to_os_return(status);
8874 goto out;
8875 }
8876
Naveen Rawat247a8682017-06-05 15:00:31 -07008877 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008878 hdd_ctx->config->tx_chain_mask_1ss,
8879 PDEV_CMD);
8880 if (0 != ret) {
8881 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8882 goto out;
8883 }
8884
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008885 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8886 if (ret)
8887 goto out;
8888
8889 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8890 if (ret)
8891 goto out;
8892
Jeff Johnson12a744b2017-04-04 08:19:37 -07008893 ret = hdd_set_ani_enabled(hdd_ctx);
8894 if (ret)
8895 goto out;
8896
Naveen Rawat247a8682017-06-05 15:00:31 -07008897 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008898 hdd_ctx->config->arp_ac_category,
8899 PDEV_CMD);
8900 if (0 != ret) {
8901 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8902 hdd_ctx->config->arp_ac_category, ret);
8903 goto out;
8904 }
8905
8906
Prashanth Bhatta07998752016-04-28 12:35:33 -07008907 status = hdd_set_sme_chan_list(hdd_ctx);
8908 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008909 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008910 ret = qdf_status_to_os_return(status);
8911 goto out;
8912 }
8913
8914 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008915 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008916 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008917 ret = -EINVAL;
8918 goto out;
8919 }
8920
Prashanth Bhatta07998752016-04-28 12:35:33 -07008921 /*
8922 * Set the MAC Address Currently this is used by HAL to add self sta.
8923 * Remove this once self sta is added as part of session open.
8924 */
8925 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8926 hdd_ctx->config->intfMacAddr[0].bytes,
8927 sizeof(hdd_ctx->config->intfMacAddr[0]));
8928
8929 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8930 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8931 hal_status, hal_status);
8932 ret = -EINVAL;
8933 goto out;
8934 }
8935
8936 hdd_init_channel_avoidance(hdd_ctx);
8937
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308938 /* update enable sap mandatory chan list */
8939 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8940 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008941out:
8942 return ret;
8943}
8944
8945/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008946 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8947 * @context_ptr - hdd context pointer
8948 * @event_ptr - event structure pointer
8949 *
8950 * This is the p2p listen offload stop event handler, it sends vendor
8951 * event back to supplicant to notify the stop reason.
8952 *
8953 * Return: None
8954 */
8955static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8956 void *event_ptr)
8957{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008958 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008959 struct sir_p2p_lo_event *evt = event_ptr;
8960 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008961 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008962
8963 ENTER();
8964
8965 if (hdd_ctx == NULL) {
8966 hdd_err("Invalid HDD context pointer");
8967 return;
8968 }
8969
Peng Xu5c682812017-08-06 07:39:13 -07008970 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8971 if (!adapter) {
8972 hdd_err("Cannot find adapter by vdev_id = %d",
8973 evt->vdev_id);
8974 return;
8975 }
8976
Peng Xu8fdaa492016-06-22 10:20:47 -07008977 vendor_event =
8978 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008979 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008980 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8981 GFP_KERNEL);
8982
8983 if (!vendor_event) {
8984 hdd_err("cfg80211_vendor_event_alloc failed");
8985 return;
8986 }
8987
8988 if (nla_put_u32(vendor_event,
8989 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8990 evt->reason_code)) {
8991 hdd_err("nla put failed");
8992 kfree_skb(vendor_event);
8993 return;
8994 }
8995
8996 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008997 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8998 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008999}
9000
9001/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309002 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9003 * @hdd_ctx: HDD context
9004 *
9005 * This function sends the adaptive dwell time config configuration to the
9006 * firmware via WMA
9007 *
9008 * Return: 0 - success, < 0 - failure
9009 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009010static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309011{
9012 QDF_STATUS status;
9013 struct adaptive_dwelltime_params dwelltime_params;
9014
9015 dwelltime_params.is_enabled =
9016 hdd_ctx->config->adaptive_dwell_mode_enabled;
9017 dwelltime_params.dwelltime_mode =
9018 hdd_ctx->config->global_adapt_dwelltime_mode;
9019 dwelltime_params.lpf_weight =
9020 hdd_ctx->config->adapt_dwell_lpf_weight;
9021 dwelltime_params.passive_mon_intval =
9022 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9023 dwelltime_params.wifi_act_threshold =
9024 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9025
9026 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9027 &dwelltime_params);
9028
9029 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9030 if (!QDF_IS_STATUS_SUCCESS(status)) {
9031 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9032 return -EAGAIN;
9033 }
9034 return 0;
9035}
9036
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009037int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309038{
9039 QDF_STATUS status;
9040 struct wmi_dbs_scan_sel_params dbs_scan_params;
9041 uint32_t i = 0;
9042 uint8_t count = 0, numentries = 0;
9043 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9044 * CDS_DBS_SCAN_CLIENTS_MAX];
9045
9046 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009047 if (hdd_ctx->config->dual_mac_feature_disable ==
9048 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309049 return -EINVAL;
9050
9051 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9052 dbs_scan_config, &numentries,
9053 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9054 * CDS_DBS_SCAN_CLIENTS_MAX));
9055
9056 hdd_info("numentries %hu", numentries);
9057 if (!numentries) {
9058 hdd_info("Donot send scan_selection_config");
9059 return 0;
9060 }
9061
9062 /* hdd_set_fw_log_params */
9063 dbs_scan_params.num_clients = 0;
9064 while (count < (numentries - 2)) {
9065 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9066 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9067 dbs_scan_params.num_non_dbs_scans[i] =
9068 dbs_scan_config[count + 2];
9069 dbs_scan_params.num_clients++;
9070 hdd_debug("module:%d NDS:%d NNDS:%d",
9071 dbs_scan_params.module_id[i],
9072 dbs_scan_params.num_dbs_scans[i],
9073 dbs_scan_params.num_non_dbs_scans[i]);
9074 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9075 i++;
9076 }
9077
9078 dbs_scan_params.pdev_id = 0;
9079
9080 hdd_debug("clients:%d pdev:%d",
9081 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9082
9083 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9084 &dbs_scan_params);
9085 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9086 if (!QDF_IS_STATUS_SUCCESS(status)) {
9087 hdd_err("Failed to send DBS Scan selection configuration!");
9088 return -EAGAIN;
9089 }
9090 return 0;
9091}
9092
Arun Khandavallid4349a92016-07-25 11:10:43 +05309093#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9094/**
9095 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9096 * @hdd_ctx: HDD context
9097 *
9098 * Set auto shutdown callback to get indications from firmware to indicate
9099 * userspace to shutdown WLAN after a configured amount of inactivity.
9100 *
9101 * Return: 0 on success and errno on failure.
9102 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009103static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309104{
9105 QDF_STATUS status;
9106
9107 if (!hdd_ctx->config->WlanAutoShutdown)
9108 return 0;
9109
9110 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9111 wlan_hdd_auto_shutdown_cb);
9112 if (status != QDF_STATUS_SUCCESS)
9113 hdd_err("Auto shutdown feature could not be enabled: %d",
9114 status);
9115
9116 return qdf_status_to_os_return(status);
9117}
9118#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009119static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309120{
9121 return 0;
9122}
9123#endif
9124
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009125static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009126{
9127 QDF_STATUS status = QDF_STATUS_SUCCESS;
9128
9129 switch (hdd_ctx->config->dual_mac_feature_disable) {
9130 case DISABLE_DBS_CXN_AND_SCAN:
9131 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9132 if (status != QDF_STATUS_SUCCESS)
9133 hdd_err("Failed to disable dual mac features");
9134 break;
9135 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9136 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9137 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9138 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9139 if (status != QDF_STATUS_SUCCESS)
9140 hdd_err("Failed to set dbs scan and fw mode config");
9141 break;
9142 default:
9143 break;
9144 }
9145
9146 return status;
9147}
9148
Arun Khandavallid4349a92016-07-25 11:10:43 +05309149/**
9150 * hdd_features_init() - Init features
9151 * @hdd_ctx: HDD context
9152 * @adapter: Primary adapter context
9153 *
9154 * Initialize features and their feature context after WLAN firmware is up.
9155 *
9156 * Return: 0 on success and errno on failure.
9157 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009158static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309159{
9160 tSirTxPowerLimit hddtxlimit;
9161 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309162 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309163 int ret;
9164
9165 ENTER();
9166
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009167 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309168 if (ret) {
9169 hdd_err("Failed to update country code: %d", ret);
9170 goto out;
9171 }
9172
9173 /* FW capabilities received, Set the Dot11 mode */
9174 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009175 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9176 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309177
Arun Khandavallid4349a92016-07-25 11:10:43 +05309178
9179 if (hdd_ctx->config->fIsImpsEnabled)
9180 hdd_set_idle_ps_config(hdd_ctx, true);
9181 else
9182 hdd_set_idle_ps_config(hdd_ctx, false);
9183
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309184 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009185 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309186
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309187 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9188 hdd_warn("Error in setting Voltage Corner mode config to FW");
9189
Arun Khandavallid4349a92016-07-25 11:10:43 +05309190 if (hdd_lro_init(hdd_ctx))
9191 hdd_err("Unable to initialize LRO in fw");
9192
9193 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9194 hdd_err("Unable to send adaptive dwelltime setting to FW");
9195
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309196 if (hdd_dbs_scan_selection_init(hdd_ctx))
9197 hdd_err("Unable to send DBS scan selection setting to FW");
9198
Arun Khandavallid4349a92016-07-25 11:10:43 +05309199 ret = hdd_init_thermal_info(hdd_ctx);
9200 if (ret) {
9201 hdd_err("Error while initializing thermal information");
9202 goto deregister_frames;
9203 }
9204
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309205 if (cds_is_packet_log_enabled())
9206 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9207
Arun Khandavallid4349a92016-07-25 11:10:43 +05309208 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9209 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9210 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9211 if (!QDF_IS_STATUS_SUCCESS(status))
9212 hdd_err("Error setting txlimit in sme: %d", status);
9213
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009214 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309215
Arun Khandavallid4349a92016-07-25 11:10:43 +05309216 ret = hdd_register_cb(hdd_ctx);
9217 if (ret) {
9218 hdd_err("Failed to register HDD callbacks!");
9219 goto deregister_frames;
9220 }
9221
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009222 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9223 if (!QDF_IS_STATUS_SUCCESS(status)) {
9224 hdd_err("Failed to set dbs scan and fw mode cfg");
9225 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309226 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009227
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309228 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9229 status = sme_enable_disable_chanavoidind_event(
9230 hdd_ctx->hHal, 0);
9231 if (!QDF_IS_STATUS_SUCCESS(status)) {
9232 hdd_err("Failed to disable Chan Avoidance Indication");
9233 goto deregister_cb;
9234 }
9235 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309236
Manjeet Singha9cae432017-02-28 11:58:22 +05309237 if (hdd_ctx->config->enable_5g_band_pref) {
9238 band_pref_params.rssi_boost_threshold_5g =
9239 hdd_ctx->config->rssi_boost_threshold_5g;
9240 band_pref_params.rssi_boost_factor_5g =
9241 hdd_ctx->config->rssi_boost_factor_5g;
9242 band_pref_params.max_rssi_boost_5g =
9243 hdd_ctx->config->max_rssi_boost_5g;
9244 band_pref_params.rssi_penalize_threshold_5g =
9245 hdd_ctx->config->rssi_penalize_threshold_5g;
9246 band_pref_params.rssi_penalize_factor_5g =
9247 hdd_ctx->config->rssi_penalize_factor_5g;
9248 band_pref_params.max_rssi_penalize_5g =
9249 hdd_ctx->config->max_rssi_penalize_5g;
9250 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9251 }
9252
Arun Khandavallid4349a92016-07-25 11:10:43 +05309253 /* register P2P Listen Offload event callback */
9254 if (wma_is_p2p_lo_capable())
9255 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9256 wlan_hdd_p2p_lo_event_callback);
9257
9258 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9259
9260 if (ret)
9261 goto deregister_cb;
9262
9263 EXIT();
9264 return 0;
9265
9266deregister_cb:
9267 hdd_deregister_cb(hdd_ctx);
9268deregister_frames:
9269 wlan_hdd_cfg80211_deregister_frames(adapter);
9270out:
9271 return -EINVAL;
9272
9273}
9274
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009275/**
9276 * hdd_features_deinit() - Deinit features
9277 * @hdd_ctx: HDD context
9278 *
9279 * De-Initialize features and their feature context.
9280 *
9281 * Return: none.
9282 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009283static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009284{
9285 wlan_hdd_tsf_deinit(hdd_ctx);
9286}
9287
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309288/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009289 * hdd_register_bcn_cb() - register scan beacon callback
9290 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309291 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009292 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309293 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009294static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309295{
9296 QDF_STATUS status;
9297
9298 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9299 wlan_cfg80211_inform_bss_frame,
9300 SCAN_CB_TYPE_INFORM_BCN);
9301 if (!QDF_IS_STATUS_SUCCESS(status)) {
9302 hdd_err("failed with status code %08d [x%08x]",
9303 status, status);
9304 return status;
9305 }
9306
9307 return QDF_STATUS_SUCCESS;
9308}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309309
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309310/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309311 * hdd_configure_cds() - Configure cds modules
9312 * @hdd_ctx: HDD context
9313 * @adapter: Primary adapter context
9314 *
9315 * Enable Cds modules after WLAN firmware is up.
9316 *
9317 * Return: 0 on success and errno on failure.
9318 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009319int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309320{
9321 int ret;
9322 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309323 int set_value;
9324 uint32_t num_abg_tx_chains = 0;
9325 uint32_t num_11b_tx_chains = 0;
9326 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009327 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309328
9329 if (hdd_ctx->config->sifs_burst_duration) {
9330 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9331 hdd_ctx->config->sifs_burst_duration;
9332
9333 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9334 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9335 set_value, PDEV_CMD);
9336 }
9337
9338 if (hdd_ctx->config->is_force_1x1)
9339 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9340 1, PDEV_CMD);
9341 /* set chip power save failure detected callback */
9342 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9343 hdd_chip_pwr_save_fail_detected_cb);
9344
9345 if (hdd_ctx->config->max_mpdus_inampdu) {
9346 set_value = hdd_ctx->config->max_mpdus_inampdu;
9347 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9348 set_value, PDEV_CMD);
9349 }
9350
9351 if (hdd_ctx->config->enable_rts_sifsbursting) {
9352 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9353 sme_cli_set_command(0,
9354 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9355 set_value, PDEV_CMD);
9356 }
9357
9358 if (hdd_ctx->config->sap_get_peer_info) {
9359 set_value = hdd_ctx->config->sap_get_peer_info;
9360 sme_cli_set_command(0,
9361 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9362 set_value, PDEV_CMD);
9363 }
9364
9365 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9366 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9367 if (!hdd_ctx->config->enable2x2) {
9368 if (num_11b_tx_chains > 1)
9369 num_11b_tx_chains = 1;
9370 if (num_11ag_tx_chains > 1)
9371 num_11ag_tx_chains = 1;
9372 }
9373 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9374 num_11b_tx_chains);
9375 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9376 num_11ag_tx_chains);
9377 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9378 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309379
9380 ret = hdd_pre_enable_configure(hdd_ctx);
9381 if (ret) {
9382 hdd_err("Failed to pre-configure cds");
9383 goto out;
9384 }
9385
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009386 /* Always get latest IPA resources allocated from cds_open and configure
9387 * IPA module before configuring them to FW. Sequence required as crash
9388 * observed otherwise.
9389 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009390 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9391 hdd_err("Failed to setup pipes");
9392 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009393 }
9394
Arun Khandavallifae92942016-08-01 13:31:08 +05309395 /*
9396 * Start CDS which starts up the SME/MAC/HAL modules and everything
9397 * else
9398 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009399 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309400
9401 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009402 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309403 goto out;
9404 }
9405
9406 status = hdd_post_cds_enable_config(hdd_ctx);
9407 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009408 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009409 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309410 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309411 status = hdd_register_bcn_cb(hdd_ctx);
9412 if (!QDF_IS_STATUS_SUCCESS(status)) {
9413 hdd_alert("hdd_post_cds_enable_config failed");
9414 goto cds_disable;
9415 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309416
9417 ret = hdd_features_init(hdd_ctx, adapter);
9418 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009419 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309420
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009421 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009422 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009423 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9424 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009425 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009426 goto cds_disable;
9427 }
9428
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309429 if (hdd_enable_egap(hdd_ctx))
9430 hdd_debug("enhance green ap is not enabled");
9431
Nachiket Kukadedd302662017-07-13 17:31:44 +05309432 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9433 hdd_debug("Failed to set wow pulse");
9434
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309435 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9436 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9437
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309438
9439 if (hdd_ctx->config->enable_phy_reg_retention)
9440 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9441 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9442
Arun Khandavallifae92942016-08-01 13:31:08 +05309443 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009444
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009445cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009446 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009447
Arun Khandavallifae92942016-08-01 13:31:08 +05309448out:
9449 return -EINVAL;
9450}
9451
9452/**
9453 * hdd_deconfigure_cds() -De-Configure cds
9454 * @hdd_ctx: HDD context
9455 *
9456 * Deconfigure Cds modules before WLAN firmware is down.
9457 *
9458 * Return: 0 on success and errno on failure.
9459 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009460static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309461{
9462 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009463 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309464
9465 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009466
9467 /* De-init features */
9468 hdd_features_deinit(hdd_ctx);
9469
Arun Khandavallifae92942016-08-01 13:31:08 +05309470 /* De-register the SME callbacks */
9471 hdd_deregister_cb(hdd_ctx);
9472
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009473 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309474 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9475 hdd_err("Failed to Disable the CDS Modules! :%d",
9476 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009477 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309478 }
9479
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309480 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9481 hdd_err("Failed to disconnect pipes");
9482 ret = -EINVAL;
9483 }
9484
Arun Khandavallifae92942016-08-01 13:31:08 +05309485 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009486 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309487}
9488
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009489#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9490static void hdd_deregister_policy_manager_callback(
9491 struct wlan_objmgr_psoc *psoc)
9492{
9493 if (QDF_STATUS_SUCCESS !=
9494 policy_mgr_deregister_hdd_cb(psoc)) {
9495 hdd_err("HDD callback deregister with policy manager failed");
9496 }
9497}
9498#else
9499static void hdd_deregister_policy_manager_callback(
9500 struct wlan_objmgr_psoc *psoc)
9501{
9502}
9503#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309504
9505/**
9506 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9507 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009508 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309509 *
9510 * This function maintains the driver state machine it will be invoked from
9511 * exit, shutdown and con_mode change handler. Depending on the driver state
9512 * shall perform the stopping/closing of the modules.
9513 *
9514 * Return: 0 for success; non-zero for failure
9515 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009516int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309517{
9518 void *hif_ctx;
9519 qdf_device_t qdf_ctx;
9520 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309521 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009522 bool is_idle_stop = !cds_is_driver_unloading() &&
9523 !cds_is_driver_recovering();
9524 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309525
9526 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009527 hdd_alert("stop WLAN module: entering driver status=%d",
9528 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309529
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009530 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9531
Arun Khandavallifae92942016-08-01 13:31:08 +05309532 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9533 if (!qdf_ctx) {
9534 hdd_err("QDF device context NULL");
9535 return -EINVAL;
9536 }
9537
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309538 mutex_lock(&hdd_ctx->iface_change_lock);
9539 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009540 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +05309541
Dustin Brown70111822017-03-30 15:31:40 -07009542 active_threads = cds_return_external_threads_count();
9543 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009544 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009545 active_threads, hdd_ctx->isWiphySuspended);
9546
9547 cds_print_external_threads();
9548
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009549 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009550 mutex_unlock(&hdd_ctx->iface_change_lock);
9551 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009552 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309553 hdd_prevent_suspend_timeout(
9554 hdd_ctx->config->iface_change_wait_time,
9555 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009556 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009557 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -07009558 return 0;
9559 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009560 }
9561
Arun Khandavallifae92942016-08-01 13:31:08 +05309562 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9563
9564 switch (hdd_ctx->driver_status) {
9565 case DRIVER_MODULES_UNINITIALIZED:
9566 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309567 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309568 case DRIVER_MODULES_CLOSED:
9569 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309570 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309571 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309572 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309573 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009574 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309575 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309576 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309577 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009578 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309579 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9580 break;
9581 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009582 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309583 break;
9584 default:
9585 hdd_err("Trying to stop wlan in a wrong state: %d",
9586 hdd_ctx->driver_status);
9587 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309588 ret = -EINVAL;
9589 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309590 }
9591
Rajeev Kumarbe021242017-02-16 16:12:23 -08009592 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309593 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9594 hdd_err("Failed to process post CDS disable Modules! :%d",
9595 qdf_status);
9596 ret = -EINVAL;
9597 QDF_ASSERT(0);
9598 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07009599
9600 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
9601 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9602 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
9603 ret = -EINVAL;
9604 QDF_ASSERT(0);
9605 }
9606
Jeff Johnsone4b14592017-09-13 14:23:33 -07009607 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309608 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009609 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309610 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309611 QDF_ASSERT(0);
9612 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009613
Arun Khandavallifae92942016-08-01 13:31:08 +05309614 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9615 if (!hif_ctx) {
9616 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309617 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309618 }
9619
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309620 hdd_runtime_suspend_context_deinit(hdd_ctx);
9621
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309622 if (hdd_ctx->target_hw_name) {
9623 qdf_mem_free(hdd_ctx->target_hw_name);
9624 hdd_ctx->target_hw_name = NULL;
9625 }
9626
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309627 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309628
9629 ol_cds_free();
9630
Dustin Brown70111822017-03-30 15:31:40 -07009631 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309632 ret = pld_power_off(qdf_ctx->dev);
9633 if (ret)
9634 hdd_err("CNSS power down failed put device into Low power mode:%d",
9635 ret);
9636 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309637
9638 /* Once the firmware sequence is completed reset this flag */
9639 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309640 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009641 /*
9642 * Reset total mac phy during module stop such that during
9643 * next module start same psoc is used to populate new service
9644 * ready data
9645 */
9646 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309647
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309648done:
9649 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009650 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309651 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07009652 hdd_alert("stop WLAN module: exit driver status=%d",
9653 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309654 EXIT();
9655
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309656 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309657
9658}
9659
9660/**
9661 * hdd_iface_change_callback() - Function invoked when stop modules expires
9662 * @priv: pointer to hdd context
9663 *
9664 * This function is invoked when the timer waiting for the interface change
9665 * expires, it shall cut-down the power to wlan and stop all the modules.
9666 *
9667 * Return: void
9668 */
9669static void hdd_iface_change_callback(void *priv)
9670{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009671 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309672 int ret;
9673 int status = wlan_hdd_validate_context(hdd_ctx);
9674
9675 if (status)
9676 return;
9677
9678 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009679 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009680 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309681 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009682 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309683 EXIT();
9684}
9685
9686/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309687 * hdd_state_info_dump() - prints state information of hdd layer
9688 * @buf: buffer pointer
9689 * @size: size of buffer to be filled
9690 *
9691 * This function is used to dump state information of hdd layer
9692 *
9693 * Return: None
9694 */
9695static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9696{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009697 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309698 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9699 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009700 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009701 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309702 uint16_t len = 0;
9703 char *buf = *buf_ptr;
9704
9705 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9706 if (!hdd_ctx) {
9707 hdd_err("Failed to get hdd context ");
9708 return;
9709 }
9710
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009711 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309712
9713 len += scnprintf(buf + len, *size - len,
9714 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9715 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009716 "\n is_scheduler_suspended %d",
9717 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309718
9719 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9720
9721 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009722 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309723 if (adapter->dev)
9724 len += scnprintf(buf + len, *size - len,
9725 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009726 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309727 "\n device_mode: %d", adapter->device_mode);
9728 switch (adapter->device_mode) {
9729 case QDF_STA_MODE:
9730 case QDF_P2P_CLIENT_MODE:
9731 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9732 len += scnprintf(buf + len, *size - len,
9733 "\n connState: %d",
9734 hdd_sta_ctx->conn_info.connState);
9735 break;
9736
9737 default:
9738 break;
9739 }
9740 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9741 adapter_node = next;
9742 }
9743
9744 *size -= len;
9745 *buf_ptr += len;
9746}
9747
9748/**
9749 * hdd_register_debug_callback() - registration function for hdd layer
9750 * to print hdd state information
9751 *
9752 * Return: None
9753 */
9754static void hdd_register_debug_callback(void)
9755{
9756 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9757}
9758
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309759/*
9760 * wlan_init_bug_report_lock() - Initialize bug report lock
9761 *
9762 * This function is used to create bug report lock
9763 *
9764 * Return: None
9765 */
9766static void wlan_init_bug_report_lock(void)
9767{
9768 p_cds_contextType p_cds_context;
9769
9770 p_cds_context = cds_get_global_context();
9771 if (!p_cds_context) {
9772 hdd_err("cds context is NULL");
9773 return;
9774 }
9775
9776 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9777}
9778
Mohit Khannaf8f96822017-05-17 17:11:59 -07009779void hdd_dp_trace_init(struct hdd_config *config)
9780{
9781
9782 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9783 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9784 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9785 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9786 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9787 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9788 uint8_t num_entries = 0;
9789
9790 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9791 &num_entries, sizeof(config_params));
9792
9793 /* calculating, num bw timer intervals in a second (1000ms) */
9794 if (config->busBandwidthComputeInterval)
9795 thresh_time_limit =
9796 (1000 / config->busBandwidthComputeInterval);
9797 else
9798 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9799
9800 switch (num_entries) {
9801 case 4:
9802 proto_bitmap = config_params[3];
9803 case 3:
9804 verbosity = config_params[2];
9805 case 2:
9806 thresh = config_params[1];
9807 case 1:
9808 live_mode = config_params[0];
9809 default:
9810 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9811 live_mode, thresh, thresh_time_limit,
9812 verbosity, proto_bitmap);
9813 };
9814
9815 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9816 verbosity, proto_bitmap);
9817
9818}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309819/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009820 * hdd_wlan_startup() - HDD init function
9821 * @dev: Pointer to the underlying device
9822 *
9823 * This is the driver startup code executed once a WLAN device has been detected
9824 *
9825 * Return: 0 for success, < 0 for failure
9826 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309827int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009828{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309829 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009830 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009831 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009832 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009833
9834 ENTER();
9835
Arun Khandavallifae92942016-08-01 13:31:08 +05309836 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009837
9838 if (IS_ERR(hdd_ctx))
9839 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009840
Abhishek Singhe9068f12017-03-31 14:14:52 +05309841 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9842 DEFAULT_PSOC_ID);
9843 if (ret) {
9844 hdd_err("Psoc creation fails!");
9845 QDF_BUG(0);
9846 goto err_hdd_free_context;
9847 }
9848
Arun Khandavallifae92942016-08-01 13:31:08 +05309849 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9850 hdd_iface_change_callback, (void *)hdd_ctx);
9851
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309852 qdf_nbuf_init_replenish_timer();
9853
Arun Khandavallifae92942016-08-01 13:31:08 +05309854 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309855#ifdef FEATURE_WLAN_CH_AVOID
9856 mutex_init(&hdd_ctx->avoid_freq_lock);
9857#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309858
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009859 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009860 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309861
Jeff Johnson957bc272017-02-02 08:54:48 -08009862 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309863 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009864 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009865 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009866 }
9867
Yingying Tang80e15f32016-09-27 18:23:01 +08009868 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009869
Anurag Chouhan6d760662016-02-20 16:05:43 +05309870 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009871
9872 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009873 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309874 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009875 }
9876
Prashanth Bhatta07998752016-04-28 12:35:33 -07009877 ret = hdd_wiphy_init(hdd_ctx);
9878 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009879 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309880 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009881 }
9882
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309883 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009884 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309885
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309886 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009887 goto err_wiphy_unregister;
9888
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309889 wlan_hdd_init_chan_info(hdd_ctx);
9890
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009891 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009892
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309893 ret = hdd_register_notifiers(hdd_ctx);
9894 if (ret)
9895 goto err_ipa_cleanup;
9896
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009897 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009898
Jeff Johnson957bc272017-02-02 08:54:48 -08009899 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9900 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009901 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009902 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009903 }
9904
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009905 hdd_release_rtnl_lock();
9906 rtnl_held = false;
9907
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009908 wlan_hdd_update_11n_mode(hdd_ctx->config);
9909
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009910#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309911 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309912 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009913 hdd_skip_acs_scan_timer_handler,
9914 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309915 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009916 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009917 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009918#endif
9919
Prashanth Bhattaab004382016-10-11 16:08:11 -07009920 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009921
Jeff Johnson9afc5012016-09-23 13:56:27 -07009922 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009923
Nirav Shahbd36b062016-07-18 11:12:59 +05309924 if (hdd_ctx->rps)
9925 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009926
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309927 status = wlansap_global_init();
9928 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009929 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009930
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009931 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309932 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009933
Arun Khandavallifae92942016-08-01 13:31:08 +05309934 if (hdd_ctx->config->fIsImpsEnabled)
9935 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -07009936 else
9937 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309938
Mukul Sharma07bd8752017-10-10 16:58:14 +05309939 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309940 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309941 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309942 hdd_prevent_suspend_timeout(
9943 hdd_ctx->config->iface_change_wait_time,
9944 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
9945 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309946
Sachin Ahujadddd2632017-03-07 19:07:24 +05309947 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009948 goto success;
9949
Jeff Johnson957bc272017-02-02 08:54:48 -08009950err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009951 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009952
Jeff Johnson46bde382017-02-01 15:31:16 -08009953err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309954 if (rtnl_held)
9955 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009956
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309957 unregister_netdevice_notifier(&hdd_netdev_notifier);
9958
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309959err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309960 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009961
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009962err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009963 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009964
Arun Khandavallifae92942016-08-01 13:31:08 +05309965err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009966 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309967
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009968err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309969 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009970 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309971 if (!QDF_IS_STATUS_SUCCESS(status)) {
9972 hdd_err("Failed to close CDS Scheduler");
9973 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9974 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009975 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009976
Houston Hoffman47a4a052016-11-14 23:22:44 -08009977 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009978 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009979 hdd_exit_netlink_services(hdd_ctx);
9980
Dustin Brown20912462017-06-07 13:48:25 -07009981 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9982
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009983err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309984 if (cds_is_fw_down())
9985 hdd_err("Not setting the complete event as fw is down");
9986 else
9987 hdd_start_complete(ret);
9988
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309989 qdf_nbuf_deinit_replenish_timer();
Arun Khandavallifae92942016-08-01 13:31:08 +05309990 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9991 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009992 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07009993 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009994
9995success:
9996 EXIT();
9997 return 0;
9998}
9999
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010000/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010001 * hdd_wlan_update_target_info() - update target type info
10002 * @hdd_ctx: HDD context
10003 * @context: hif context
10004 *
10005 * Update target info received from firmware in hdd context
10006 * Return:None
10007 */
10008
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010009void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010010{
10011 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10012
10013 if (!tgt_info) {
10014 hdd_err("Target info is Null");
10015 return;
10016 }
10017
10018 hdd_ctx->target_type = tgt_info->target_type;
10019}
10020
10021/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010022 * hdd_get_nud_stats_cb() - callback api to update the stats
10023 * received from the firmware
10024 * @data: pointer to adapter.
10025 * @rsp: pointer to data received from FW.
10026 *
10027 * This is called when wlan driver received response event for
10028 * get arp stats to firmware.
10029 *
10030 * Return: None
10031 */
10032static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10033{
10034 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10035 struct hdd_nud_stats_context *context;
10036 int status;
10037 struct hdd_adapter *adapter = NULL;
10038
10039 ENTER();
10040
10041 if (!rsp) {
10042 hdd_err("data is null");
10043 return;
10044 }
10045
10046 status = wlan_hdd_validate_context(hdd_ctx);
10047 if (0 != status)
10048 return;
10049
10050 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10051 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10052 hdd_err("Invalid adapter or adapter has invalid magic");
10053 return;
10054 }
10055
10056 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10057 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10058 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10059 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10060 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10061 rsp->out_of_order_arp_rsp_drop_cnt);
10062 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10063 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10064 hdd_notice("rsp->ba_session_establishment_status :%x",
10065 rsp->ba_session_establishment_status);
10066
10067 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10068 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10069 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10070 adapter->dad |= rsp->dad_detected;
10071 adapter->con_status = rsp->connect_status;
10072
10073 spin_lock(&hdd_context_lock);
10074 context = &hdd_ctx->nud_stats_context;
10075 complete(&context->response_event);
10076 spin_unlock(&hdd_context_lock);
10077
10078 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010079}
10080
10081/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010082 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010083 * @hdd_ctx: HDD context
10084 *
10085 * Register the HDD callbacks to CDS/SME.
10086 *
10087 * Return: 0 for success or Error code for failure
10088 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010089int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010090{
10091 QDF_STATUS status;
10092 int ret = 0;
10093
10094 ENTER();
10095
10096 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10097
10098 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10099 hdd_send_oem_data_rsp_msg);
10100
10101 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10102 wlan_hdd_cfg80211_fw_mem_dump_cb);
10103 if (!QDF_IS_STATUS_SUCCESS(status)) {
10104 hdd_err("Failed to register memdump callback");
10105 ret = -EINVAL;
10106 return ret;
10107 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010108 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10109 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010110 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10111 sme_nan_register_callback(hdd_ctx->hHal,
10112 wlan_hdd_cfg80211_nan_callback);
10113 sme_stats_ext_register_callback(hdd_ctx->hHal,
10114 wlan_hdd_cfg80211_stats_ext_callback);
10115
10116 sme_ext_scan_register_callback(hdd_ctx->hHal,
10117 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010118 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10119 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010120
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010121 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10122 hdd_rssi_threshold_breached);
10123
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010124 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10125
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010126 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10127 wlan_hdd_cfg80211_link_layer_stats_callback);
10128
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010129 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10130
Zhang Qianca38fb12016-12-23 11:10:48 +080010131 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10132 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10133
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010134 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10135 hdd_lost_link_info_cb);
10136 /* print error and not block the startup process */
10137 if (!QDF_IS_STATUS_SUCCESS(status))
10138 hdd_err("set lost link info callback failed");
10139
Poddar, Siddarth34872782017-08-10 14:08:51 +053010140 ret = hdd_register_data_stall_detect_cb();
10141 if (ret) {
10142 hdd_err("Register data stall detect detect callback failed.");
10143 return ret;
10144 }
10145
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010146 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10147
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010148 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010149 hdd_set_connection_in_progress,
10150 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010151
10152 status = sme_congestion_register_callback(hdd_ctx->hHal,
10153 hdd_update_cca_info_cb);
10154 if (!QDF_IS_STATUS_SUCCESS(status))
10155 hdd_err("set congestion callback failed");
10156
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010157 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10158 hdd_bt_activity_cb);
10159 if (!QDF_IS_STATUS_SUCCESS(status))
10160 hdd_err("set bt activity info callback failed");
10161
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010162 EXIT();
10163
10164 return ret;
10165}
10166
10167/**
10168 * hdd_deregister_cb() - De-Register HDD callbacks.
10169 * @hdd_ctx: HDD context
10170 *
10171 * De-Register the HDD callbacks to CDS/SME.
10172 *
10173 * Return: void
10174 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010175void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010176{
10177 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010178 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010179
10180 ENTER();
10181
10182 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10183 if (!QDF_IS_STATUS_SUCCESS(status))
10184 hdd_err("De-register of dcc stats callback failed: %d",
10185 status);
10186
10187 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010188 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10189
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010190 sme_stats_ext_register_callback(hdd_ctx->hHal,
10191 wlan_hdd_cfg80211_stats_ext_callback);
10192
10193 sme_nan_deregister_callback(hdd_ctx->hHal);
10194 status = sme_reset_tsfcb(hdd_ctx->hHal);
10195 if (!QDF_IS_STATUS_SUCCESS(status))
10196 hdd_err("Failed to de-register tsfcb the callback:%d",
10197 status);
10198 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10199 if (!QDF_IS_STATUS_SUCCESS(status))
10200 hdd_err("Failed to de-register the fw mem dump callback: %d",
10201 status);
10202
Poddar, Siddarth34872782017-08-10 14:08:51 +053010203 ret = hdd_deregister_data_stall_detect_cb();
10204 if (ret)
10205 hdd_err("Failed to de-register data stall detect event callback");
10206
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010207 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10208 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10209
10210 EXIT();
10211}
10212
10213/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010214 * hdd_softap_sta_deauth() - handle deauth req from HDD
10215 * @adapter: Pointer to the HDD
10216 * @enable: bool value
10217 *
10218 * This to take counter measure to handle deauth req from HDD
10219 *
10220 * Return: None
10221 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010222QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010223 struct tagCsrDelStaParams *pDelStaParams)
10224{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010225 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010226
10227 ENTER();
10228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010229 /* Ignore request to deauth bcmc station */
10230 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010231 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010232
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010233 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010234 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10235 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010236
10237 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010238 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010239}
10240
10241/**
10242 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10243 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010244 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010245 *
10246 * This to take counter measure to handle deauth req from HDD
10247 *
10248 * Return: None
10249 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010250void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010251 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010252{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010253 ENTER();
10254
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010255 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010256 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010257 return;
10258
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010259 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010260 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010261}
10262
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010263/**
10264 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10265 * @hdd_ctx: HDD Context
10266 *
10267 * API to find if there is any STA or P2P-Client is connected
10268 *
10269 * Return: true if connected; false otherwise
10270 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010271QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010272{
10273 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10274}
10275
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010276/**
10277 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10278 * @adapter: HDD adapter pointer
10279 *
10280 * This function loop through each adapter and disable roaming on each STA
10281 * device mode except the input adapter.
10282 *
10283 * Note: On the input adapter roaming is not enabled yet hence no need to
10284 * disable.
10285 *
10286 * Return: None
10287 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010288void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010289{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010290 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010291 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010292 hdd_adapter_list_node_t *adapterNode = NULL;
10293 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010294 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010295
10296 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010297 hdd_ctx->config->isRoamOffloadScanEnabled &&
10298 QDF_STA_MODE == adapter->device_mode &&
10299 policy_mgr_is_sta_active_connection_exists(
10300 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010301 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010302 adapter->sessionId);
10303 /*
10304 * Loop through adapter and disable roaming for each STA device
10305 * mode except the input adapter.
10306 */
10307 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10308
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010309 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010310 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010311
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010312 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010313 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010314 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010315 adapterIdx->sessionId);
10316 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10317 (adapterIdx),
10318 adapterIdx->sessionId, 0);
10319 }
10320
10321 status = hdd_get_next_adapter(hdd_ctx,
10322 adapterNode,
10323 &pNext);
10324 adapterNode = pNext;
10325 }
10326 }
10327}
10328
10329/**
10330 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10331 * @adapter: HDD adapter pointer
10332 *
10333 * This function loop through each adapter and enable roaming on each STA
10334 * device mode except the input adapter.
10335 * Note: On the input adapter no need to enable roaming because link got
10336 * disconnected on this.
10337 *
10338 * Return: None
10339 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010340void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010341{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010342 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010343 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010344 hdd_adapter_list_node_t *adapterNode = NULL;
10345 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010346 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010347
10348 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010349 hdd_ctx->config->isRoamOffloadScanEnabled &&
10350 QDF_STA_MODE == adapter->device_mode &&
10351 policy_mgr_is_sta_active_connection_exists(
10352 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010353 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010354 adapter->sessionId);
10355 /*
10356 * Loop through adapter and enable roaming for each STA device
10357 * mode except the input adapter.
10358 */
10359 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10360
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010361 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010362 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010363
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010364 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010365 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010366 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010367 adapterIdx->sessionId);
10368 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10369 (adapterIdx),
10370 adapterIdx->sessionId,
10371 REASON_CONNECT);
10372 }
10373
10374 status = hdd_get_next_adapter(hdd_ctx,
10375 adapterNode,
10376 &pNext);
10377 adapterNode = pNext;
10378 }
10379 }
10380}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010381
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010382/**
10383 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10384 * @skb: sk buffer pointer
10385 *
10386 * Sends the bcast message to SVC multicast group with generic nl socket
10387 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10388 *
10389 * Return: None
10390 */
10391static void nl_srv_bcast_svc(struct sk_buff *skb)
10392{
10393#ifdef CNSS_GENL
10394 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10395#else
10396 nl_srv_bcast(skb);
10397#endif
10398}
10399
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010400void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010401{
10402 struct sk_buff *skb;
10403 struct nlmsghdr *nlh;
10404 tAniMsgHdr *ani_hdr;
10405 void *nl_data = NULL;
10406 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010407 struct radio_index_tlv *radio_info;
10408 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010409
10410 if (in_interrupt() || irqs_disabled() || in_atomic())
10411 flags = GFP_ATOMIC;
10412
10413 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10414
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010415 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010416 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010417
10418 nlh = (struct nlmsghdr *)skb->data;
10419 nlh->nlmsg_pid = 0; /* from kernel */
10420 nlh->nlmsg_flags = 0;
10421 nlh->nlmsg_seq = 0;
10422 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10423
10424 ani_hdr = NLMSG_DATA(nlh);
10425 ani_hdr->type = type;
10426
10427 switch (type) {
10428 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010429 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010430 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010431 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010432 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010433 ani_hdr->length = 0;
10434 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010435 break;
10436 case WLAN_SVC_WLAN_STATUS_IND:
10437 case WLAN_SVC_WLAN_VERSION_IND:
10438 case WLAN_SVC_DFS_CAC_START_IND:
10439 case WLAN_SVC_DFS_CAC_END_IND:
10440 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10441 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10442 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010443 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010444 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010445 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010446 ani_hdr->length = len;
10447 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10448 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10449 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010450 break;
10451
10452 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010453 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010454 type);
10455 kfree_skb(skb);
10456 return;
10457 }
10458
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010459 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010460 * Add radio index at the end of the svc event in TLV format
10461 * to maintain the backward compatibility with userspace
10462 * applications.
10463 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010464
10465 tlv_len = 0;
10466
10467 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10468 < WLAN_NL_MAX_PAYLOAD) {
10469 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10470 sizeof(*ani_hdr) + len);
10471 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10472 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10473 radio_info->radio = radio;
10474 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010475 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010476 "Added radio index tlv - radio index %d",
10477 radio_info->radio);
10478 }
10479
10480 nlh->nlmsg_len += tlv_len;
10481 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10482
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010483 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010484}
10485
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010486#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10487void wlan_hdd_auto_shutdown_cb(void)
10488{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010489 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010490
10491 if (!hdd_ctx)
10492 return;
10493
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010494 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010495 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10496 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010497}
10498
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010499void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010500{
10501 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010502 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010503 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010504 bool ap_connected = false, sta_connected = false;
10505 tHalHandle hal_handle;
10506
10507 hal_handle = hdd_ctx->hHal;
10508 if (hal_handle == NULL)
10509 return;
10510
10511 if (hdd_ctx->config->WlanAutoShutdown == 0)
10512 return;
10513
10514 if (enable == false) {
10515 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010516 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010517 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010518 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010519 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010520 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010521 return;
10522 }
10523
10524 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010525 if (policy_mgr_concurrent_open_sessions_running(
10526 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010527 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10528
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010529 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010530 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010531 if (adapter
10532 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010533 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010534 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10535 conn_info.connState ==
10536 eConnectionState_Associated) {
10537 sta_connected = true;
10538 break;
10539 }
10540 }
10541 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010542 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010543 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10544 bApActive == true) {
10545 ap_connected = true;
10546 break;
10547 }
10548 }
10549 status = hdd_get_next_adapter(hdd_ctx,
10550 adapterNode,
10551 &pNext);
10552 adapterNode = pNext;
10553 }
10554 }
10555
10556 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010557 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010558 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010559 }
Jeff Johnson68755312017-02-10 11:46:55 -080010560
10561 if (sme_set_auto_shutdown_timer(hal_handle,
10562 hdd_ctx->config->WlanAutoShutdown)
10563 != QDF_STATUS_SUCCESS)
10564 hdd_err("Failed to start wlan auto shutdown timer");
10565 else
10566 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10567 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010568}
10569#endif
10570
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010571struct hdd_adapter *
10572hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10573 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010574{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010575 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010576 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010577 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010578 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10579
10580 con_sap_adapter = NULL;
10581
10582 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010583 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010584 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010585 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10586 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010587 adapter != this_sap_adapter) {
10588 if (check_start_bss) {
10589 if (test_bit(SOFTAP_BSS_STARTED,
10590 &adapter->event_flags)) {
10591 con_sap_adapter = adapter;
10592 break;
10593 }
10594 } else {
10595 con_sap_adapter = adapter;
10596 break;
10597 }
10598 }
10599 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10600 adapterNode = pNext;
10601 }
10602
10603 return con_sap_adapter;
10604}
10605
10606#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010607static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010608{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010609 return adapter->device_mode == QDF_STA_MODE ||
10610 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010611}
10612
Jeff Johnson9d295242017-08-29 14:39:48 -070010613static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010614{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010615 return adapter->device_mode == QDF_SAP_MODE ||
10616 adapter->device_mode == QDF_P2P_GO_MODE;
10617}
10618
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010619static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010620{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010621 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010622 hdd_adapter_list_node_t *node;
10623
10624 status = hdd_get_front_adapter(hdd_ctx, &node);
10625 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010626 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010627
10628 if (adapter &&
10629 hdd_adapter_is_sta(adapter) &&
10630 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10631 conn_info.connState == eConnectionState_Associated) {
10632 return true;
10633 }
10634
10635 if (adapter &&
10636 hdd_adapter_is_ap(adapter) &&
10637 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10638 return true;
10639 }
10640
10641 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10642 }
10643
10644 return false;
10645}
10646
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010647static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010648{
10649 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010650
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010651 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010652 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010653 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010654
Dustin Brown5ec6b552017-03-31 12:11:40 -070010655 return is_running;
10656}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010657
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010658static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010659{
10660 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10661 hdd_ctx->bus_bw_timer_running = true;
10662 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10663 hdd_ctx->config->busBandwidthComputeInterval);
10664 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10665}
10666
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010667void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010668{
10669 ENTER();
10670
10671 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10672 hdd_debug("Bandwidth compute timer already started");
10673 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010674 }
10675
Dustin Brown5ec6b552017-03-31 12:11:40 -070010676 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10677
10678 EXIT();
10679}
10680
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010681void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010682{
10683 ENTER();
10684
10685 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10686 hdd_debug("Bandwidth compute timer already started");
10687 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010688 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010689
10690 if (hdd_any_adapter_is_assoc(hdd_ctx))
10691 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10692
10693 EXIT();
10694}
10695
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010696static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010697{
10698 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10699
10700 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10701 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10702 hdd_ctx->bus_bw_timer_running = false;
10703 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10704
10705 hdd_reset_tcp_delack(hdd_ctx);
10706}
10707
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010708void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010709{
10710 ENTER();
10711
10712 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10713 hdd_debug("Bandwidth compute timer already stopped");
10714 return;
10715 }
10716
10717 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10718
10719 EXIT();
10720}
10721
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010722void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010723{
10724 ENTER();
10725
10726 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10727 hdd_debug("Bandwidth compute timer already stopped");
10728 return;
10729 }
10730
10731 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10732 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10733
10734 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010735}
10736#endif
10737
10738/**
10739 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10740 * and sta's operating channel.
10741 * @sta_adapter: Describe the first argument to foobar.
10742 * @ap_adapter: Describe the second argument to foobar.
10743 * @roam_profile: Roam profile of AP to which STA wants to connect.
10744 * @concurrent_chnl_same: If both SAP and STA channels are same then
10745 * set this flag to true else false.
10746 *
10747 * This function checks the sap's operating channel and sta's operating channel.
10748 * if both are same then it will return false else it will restart the sap in
10749 * sta's channel and return true.
10750 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010751 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010752 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010753QDF_STATUS
10754wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10755 struct hdd_adapter *ap_adapter,
10756 tCsrRoamProfile *roam_profile,
10757 tScanResultHandle *scan_cache,
10758 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010759{
Jeff Johnson87251032017-08-29 13:31:11 -070010760 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010761 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010762 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010763 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010764 *concurrent_chnl_same = true;
10765
10766 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10767 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010768 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010769 scan_cache,
10770 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010771 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010772 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010773 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10774 if (hdd_ap_ctx->operatingChannel != channel_id) {
10775 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010776 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010777 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010778 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010779 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10780 if (hdd_ap_ctx->operatingChannel != channel_id) {
10781 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010782 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010783 }
10784 }
10785 } else {
10786 /*
10787 * Lets handle worst case scenario here, Scan cache lookup is
10788 * failed so we have to stop the SAP to avoid any channel
10789 * discrepancy between SAP's channel and STA's channel.
10790 * Return the status as failure so caller function could know
10791 * that scan look up is failed.
10792 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010793 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010794 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010795 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010796 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010797}
10798
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010799/**
10800 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10801 * @ap_adapter: SAP adapter
10802 *
10803 * This function will process the stopping of sap adapter.
10804 *
10805 * Return: None
10806 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010807void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010808{
Jeff Johnson87251032017-08-29 13:31:11 -070010809 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010810 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010811 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010812 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010813
10814 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010815 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010816 return;
10817 }
10818
10819 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10820 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010821 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010822 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010823
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010824 mutex_lock(&hdd_ctx->sap_lock);
10825 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010826 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010827 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10828 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010829 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010830 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010831 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010832 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010833 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010834 qdf_stop_bss_event,
10835 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010836 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010837 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010838 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010839 return;
10840 }
10841 }
10842 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010843 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10844 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010845 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010846 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010847 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010848 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010849 }
10850 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010851}
10852
10853/**
10854 * wlan_hdd_start_sap() - this function starts bss of SAP.
10855 * @ap_adapter: SAP adapter
10856 *
10857 * This function will process the starting of sap adapter.
10858 *
10859 * Return: None
10860 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010861void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010862{
Jeff Johnson87251032017-08-29 13:31:11 -070010863 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010864 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010865 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010866 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010867 tsap_Config_t *sap_config;
10868
10869 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010870 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010871 return;
10872 }
10873
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010874 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010875 hdd_err("SoftAp role has not been enabled");
10876 return;
10877 }
10878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010879 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10880 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10881 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10882 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10883
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010884 mutex_lock(&hdd_ctx->sap_lock);
10885 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10886 goto end;
10887
10888 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010889 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010890 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10891 goto end;
10892 }
10893
Wei Song2f76f642016-11-18 16:32:53 +080010894 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010895 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10896 &hdd_ap_ctx->sapConfig,
10897 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010898 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010899 goto end;
10900
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010901 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010902 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010903 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010904 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010905 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010906 goto end;
10907 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010908 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010909 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010910 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010911 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10912 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010913 ap_adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010914end:
10915 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010916 /* SAP context and beacon cleanup will happen during driver unload
10917 * in hdd_stop_adapter
10918 */
10919 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10920
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010921}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010922
10923/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010924 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10925 * mac scan config
10926 * @status: Status of set antenna mode
10927 *
10928 * Callback on setting the dual mac configuration
10929 *
10930 * Return: None
10931 */
10932void wlan_hdd_soc_set_antenna_mode_cb(
10933 enum set_antenna_mode_status status)
10934{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010935 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010936
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010937 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010938
10939 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10940 if (0 != wlan_hdd_validate_context(hdd_ctx))
10941 return;
10942
10943 /* Signal the completion of set dual mac config */
10944 complete(&hdd_ctx->set_antenna_mode_cmpl);
10945}
10946
10947/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010948 * hdd_get_fw_version() - Get FW version
10949 * @hdd_ctx: pointer to HDD context.
10950 * @major_spid: FW version - major spid.
10951 * @minor_spid: FW version - minor spid
10952 * @ssid: FW version - ssid
10953 * @crmid: FW version - crmid
10954 *
10955 * This function is called to get the firmware build version stored
10956 * as part of the HDD context
10957 *
10958 * Return: None
10959 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010960void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010961 uint32_t *major_spid, uint32_t *minor_spid,
10962 uint32_t *siid, uint32_t *crmid)
10963{
10964 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10965 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10966 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10967 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10968}
10969
10970#ifdef QCA_CONFIG_SMP
10971/**
10972 * wlan_hdd_get_cpu() - get cpu_index
10973 *
10974 * Return: cpu_index
10975 */
10976int wlan_hdd_get_cpu(void)
10977{
10978 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010979
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010980 put_cpu();
10981 return cpu_index;
10982}
10983#endif
10984
10985/**
10986 * hdd_get_fwpath() - get framework path
10987 *
10988 * This function is used to get the string written by
10989 * userspace to start the wlan driver
10990 *
10991 * Return: string
10992 */
10993const char *hdd_get_fwpath(void)
10994{
10995 return fwpath.string;
10996}
10997
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010998static int hdd_qdf_print_init(void)
10999{
11000 int qdf_print_idx;
11001 QDF_STATUS status;
11002
11003 status = qdf_print_setup();
11004 if (status != QDF_STATUS_SUCCESS) {
11005 pr_err("qdf_print_setup failed\n");
11006 return -EINVAL;
11007 }
11008
11009 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11010
11011 if (qdf_print_idx < 0) {
11012 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11013 qdf_print_idx);
11014 return -EINVAL;
11015 }
11016
11017 qdf_set_pidx(qdf_print_idx);
11018
11019 return 0;
11020}
11021
11022static void hdd_qdf_print_deinit(void)
11023{
11024 int qdf_print_idx;
11025
11026 qdf_print_idx = qdf_get_pidx();
11027 qdf_print_ctrl_cleanup(qdf_print_idx);
11028}
11029
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011030/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011031 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011032 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011033 * This function initilizes CDS global context with the help of cds_init. This
11034 * has to be the first function called after probe to get a valid global
11035 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011036 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011037 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011038 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011039int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011040{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011041 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011042 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011043
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011044 status = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011045
11046 wlan_init_bug_report_lock();
11047
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011048#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11049 wlan_logging_sock_init_svc();
11050#endif
11051
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011052 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011053 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011054 ret = -ENOMEM;
11055 goto err_out;
11056 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011057
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011058 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11059 (void *)hdd_drv_ops_inactivity_handler, NULL,
11060 QDF_TIMER_TYPE_SW);
11061
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011062 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011063 hdd_qdf_print_init();
11064
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011065 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011066
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011067err_out:
11068 return ret;
11069}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011070
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011071/**
11072 * hdd_deinit() - Deinitialize Driver
11073 *
11074 * This function frees CDS global context with the help of cds_deinit. This
11075 * has to be the last function call in remove callback to free the global
11076 * context.
11077 */
11078void hdd_deinit(void)
11079{
Dustin Brownedce4a52017-05-10 11:59:15 -070011080 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011081 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011082
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011083 wlan_destroy_bug_report_lock();
11084 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011085
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011086 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011087#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11088 wlan_logging_sock_deinit_svc();
11089#endif
11090}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011091
Yue Ma6e7b1a02017-04-03 14:17:46 -070011092#ifdef QCA_WIFI_NAPIER_EMULATION
11093#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11094#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011095#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011096#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011097
Sachin Ahujadddd2632017-03-07 19:07:24 +053011098static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11099 struct file *file)
11100{
11101 return 0;
11102}
11103
11104static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11105 const char __user *user_buf,
11106 size_t count,
11107 loff_t *f_pos)
11108{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011109 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011110 static const char wlan_off_str[] = "OFF";
11111 static const char wlan_on_str[] = "ON";
11112 int ret;
11113 unsigned long rc;
11114
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011115 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011116 pr_err("Failed to read buffer\n");
11117 return -EINVAL;
11118 }
11119
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011120 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011121 pr_debug("Wifi turning off from UI\n");
11122 goto exit;
11123 }
11124
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011125 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011126 pr_err("Invalid value received from framework");
11127 goto exit;
11128 }
11129
11130 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011131 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011132 rc = wait_for_completion_timeout(&wlan_start_comp,
11133 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11134 if (!rc) {
11135 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11136 ret = -EINVAL;
11137 hdd_start_complete(ret);
11138 return ret;
11139 }
11140
11141 hdd_start_complete(0);
11142 }
11143
11144exit:
11145 return count;
11146}
11147
11148
11149const struct file_operations wlan_hdd_state_fops = {
11150 .owner = THIS_MODULE,
11151 .open = wlan_hdd_state_ctrl_param_open,
11152 .write = wlan_hdd_state_ctrl_param_write,
11153};
11154
11155static int wlan_hdd_state_ctrl_param_create(void)
11156{
11157 unsigned int wlan_hdd_state_major = 0;
11158 int ret;
11159 struct device *dev;
11160
11161 device = MKDEV(wlan_hdd_state_major, 0);
11162
11163 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11164 if (ret) {
11165 pr_err("Failed to register qcwlanstate");
11166 goto dev_alloc_err;
11167 }
11168 wlan_hdd_state_major = MAJOR(device);
11169
11170 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11171 if (IS_ERR(class)) {
11172 pr_err("wlan_hdd_state class_create error");
11173 goto class_err;
11174 }
11175
11176 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11177 if (IS_ERR(dev)) {
11178 pr_err("wlan_hdd_statedevice_create error");
11179 goto err_class_destroy;
11180 }
11181
11182 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11183 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11184 if (ret) {
11185 pr_err("Failed to add cdev error");
11186 goto cdev_add_err;
11187 }
11188
11189 pr_info("wlan_hdd_state %s major(%d) initialized",
11190 WLAN_MODULE_NAME, wlan_hdd_state_major);
11191
11192 return 0;
11193
11194cdev_add_err:
11195 device_destroy(class, device);
11196err_class_destroy:
11197 class_destroy(class);
11198class_err:
11199 unregister_chrdev_region(device, dev_num);
11200dev_alloc_err:
11201 return -ENODEV;
11202}
11203
11204static void wlan_hdd_state_ctrl_param_destroy(void)
11205{
11206 cdev_del(&wlan_hdd_state_cdev);
11207 device_destroy(class, device);
11208 class_destroy(class);
11209 unregister_chrdev_region(device, dev_num);
11210
11211 pr_info("Device node unregistered");
11212}
11213
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011214/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011215 * component_init - API to init cld component's
11216 *
11217 * Return: None
11218 */
11219static void component_init(void)
11220{
11221 pmo_init();
11222}
11223
11224/**
11225 * component_deinit - API to deinit cld component's
11226 *
11227 * Return: None
11228 */
11229static void component_deinit(void)
11230{
11231 pmo_deinit();
11232}
11233
11234/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011235 * __hdd_module_init - Module init helper
11236 *
11237 * Module init helper function used by both module and static driver.
11238 *
11239 * Return: 0 for success, errno on failure
11240 */
11241static int __hdd_module_init(void)
11242{
11243 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011244
Dustin Brownab482ac2017-06-09 17:00:44 -070011245 pr_err("%s: Loading driver v%s (%s)%s\n",
11246 WLAN_MODULE_NAME,
11247 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011248 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011249 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011250
Sachin Ahujadddd2632017-03-07 19:07:24 +053011251 ret = wlan_hdd_state_ctrl_param_create();
11252 if (ret) {
11253 pr_err("wlan_hdd_state_create:%x\n", ret);
11254 goto err_dev_state;
11255 }
11256
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011257 pld_init();
11258
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011259 ret = hdd_init();
11260 if (ret) {
11261 pr_err("hdd_init failed %x\n", ret);
11262 goto err_hdd_init;
11263 }
11264
Rajeev Kumar97767a02016-11-30 11:20:40 -080011265 dispatcher_init();
11266
Mukul Sharmad75a6672017-06-22 15:40:53 +053011267 /* Ensure to call post objmgr init */
11268 component_init();
11269
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011270 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011271
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011272 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011273
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011274 ret = wlan_hdd_register_driver();
11275 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011276 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11277 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011278 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011279 }
11280
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011281 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011282
11283 return 0;
11284out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011285 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011286 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011287 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011288
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011289err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011290 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011291 wlan_hdd_state_ctrl_param_destroy();
11292err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011293 return ret;
11294}
11295
11296/**
11297 * __hdd_module_exit - Module exit helper
11298 *
11299 * Module exit helper function used by both module and static driver.
11300 */
11301static void __hdd_module_exit(void)
11302{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011303
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011304 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11305 QWLAN_VERSIONSTR);
11306
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011307 hdd_wait_for_recovery_completion();
11308
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011309 wlan_hdd_unregister_driver();
11310
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011311 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011312
Mukul Sharmad75a6672017-06-22 15:40:53 +053011313 /* Ensure to call prior to objmgr deinit */
11314 component_deinit();
11315
Rajeev Kumar97767a02016-11-30 11:20:40 -080011316 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011317 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011318 pld_deinit();
11319
Sachin Ahujadddd2632017-03-07 19:07:24 +053011320 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011321}
11322
Arun Khandavallifae92942016-08-01 13:31:08 +053011323#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011324/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011325 * wlan_boot_cb() - Wlan boot callback
11326 * @kobj: object whose directory we're creating the link in.
11327 * @attr: attribute the user is interacting with
11328 * @buff: the buffer containing the user data
11329 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011330 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011331 * This callback is invoked when the fs is ready to start the
11332 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011333 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011334 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011335 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011336static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011337 struct kobj_attribute *attr,
11338 const char *buf,
11339 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011340{
Arun Khandavallifae92942016-08-01 13:31:08 +053011341
Arun Khandavallifae92942016-08-01 13:31:08 +053011342 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011343 pr_err("%s: wlan driver already initialized\n", __func__);
11344 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011345 }
11346
Arun Khandavallifae92942016-08-01 13:31:08 +053011347 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011348 pr_err("%s: wlan driver initialization failed\n", __func__);
11349 return -EIO;
11350 }
11351
11352 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011353
11354 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011355}
Arun Khandavallifae92942016-08-01 13:31:08 +053011356
11357/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011358 * hdd_sysfs_cleanup() - cleanup sysfs
11359 *
11360 * Return: None
11361 *
11362 */
11363static void hdd_sysfs_cleanup(void)
11364{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011365 /* remove from group */
11366 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11367 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11368 wlan_loader->attr_group);
11369
11370 /* unlink the object from parent */
11371 kobject_del(wlan_loader->boot_wlan_obj);
11372
11373 /* free the object */
11374 kobject_put(wlan_loader->boot_wlan_obj);
11375
11376 kfree(wlan_loader->attr_group);
11377 kfree(wlan_loader);
11378
11379 wlan_loader = NULL;
11380}
11381
11382/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011383 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11384 * ready
11385 *
11386 * This is creates the syfs entry boot_wlan. Which shall be invoked
11387 * when the filesystem is ready.
11388 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011389 * QDF API cannot be used here since this function is called even before
11390 * initializing WLAN driver.
11391 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011392 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011393 */
11394static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011395{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011396 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011397
11398 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011399 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011400 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011401
11402 wlan_loader->boot_wlan_obj = NULL;
11403 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11404 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011405 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011406 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011407
11408 wlan_loader->loaded_state = 0;
11409 wlan_loader->attr_group->attrs = attrs;
11410
11411 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11412 kernel_kobj);
11413 if (!wlan_loader->boot_wlan_obj) {
11414 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011415 goto error_return;
11416 }
11417
11418 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11419 wlan_loader->attr_group);
11420 if (ret) {
11421 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11422 goto error_return;
11423 }
11424
11425 return 0;
11426
11427error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011428 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011429
11430 return ret;
11431}
11432
11433/**
11434 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11435 *
11436 * Return: 0 on success or errno on failure
11437 */
11438static int wlan_deinit_sysfs(void)
11439{
Arun Khandavallifae92942016-08-01 13:31:08 +053011440 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011441 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011442 return -EINVAL;
11443 }
11444
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011445 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011446 return 0;
11447}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011448
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011449#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011450
11451#ifdef MODULE
11452/**
11453 * __hdd_module_init - Module init helper
11454 *
11455 * Module init helper function used by both module and static driver.
11456 *
11457 * Return: 0 for success, errno on failure
11458 */
11459static int hdd_module_init(void)
11460{
Arun Khandavallifae92942016-08-01 13:31:08 +053011461 if (__hdd_module_init()) {
11462 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011463 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011464 }
11465
Dustin Brownab482ac2017-06-09 17:00:44 -070011466 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011467}
11468#else
11469static int __init hdd_module_init(void)
11470{
11471 int ret = -EINVAL;
11472
11473 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011474 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011475 pr_err("Failed to create sysfs entry for loading wlan");
11476
11477 return ret;
11478}
11479#endif
11480
11481
11482#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011483/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011484 * hdd_module_exit() - Exit function
11485 *
11486 * This is the driver exit point (invoked when module is unloaded using rmmod)
11487 *
11488 * Return: None
11489 */
11490static void __exit hdd_module_exit(void)
11491{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011492 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011493}
Arun Khandavallifae92942016-08-01 13:31:08 +053011494#else
11495static void __exit hdd_module_exit(void)
11496{
11497 __hdd_module_exit();
11498 wlan_deinit_sysfs();
11499}
11500#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011501
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011502static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11503{
11504 return param_set_copystring(kmessage, kp);
11505}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011506
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011507/**
11508 * is_con_mode_valid() check con mode is valid or not
11509 * @mode: global con mode
11510 *
11511 * Return: TRUE on success FALSE on failure
11512 */
11513static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11514{
11515 switch (mode) {
11516 case QDF_GLOBAL_MONITOR_MODE:
11517 case QDF_GLOBAL_FTM_MODE:
11518 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011519 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011520 return true;
11521 default:
11522 return false;
11523 }
11524}
11525
11526/**
11527 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11528 * @mode: global con mode
11529 *
11530 * Return: adapter mode
11531 */
11532static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11533 enum tQDF_GLOBAL_CON_MODE mode)
11534{
11535
11536 switch (mode) {
11537 case QDF_GLOBAL_MISSION_MODE:
11538 return QDF_STA_MODE;
11539 case QDF_GLOBAL_MONITOR_MODE:
11540 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011541 case QDF_GLOBAL_EPPING_MODE:
11542 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011543 case QDF_GLOBAL_FTM_MODE:
11544 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011545 case QDF_GLOBAL_QVIT_MODE:
11546 return QDF_QVIT_MODE;
11547 default:
11548 return QDF_MAX_NO_OF_MODE;
11549 }
11550}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011551
Dustin Brown27cd9942017-09-27 16:11:44 -070011552static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11553 enum tQDF_GLOBAL_CON_MODE curr_mode)
11554{
11555 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11556 return;
11557
11558 switch (curr_mode) {
11559 case QDF_GLOBAL_MISSION_MODE:
11560 case QDF_GLOBAL_MONITOR_MODE:
11561 case QDF_GLOBAL_FTM_MODE:
11562 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11563 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11564
11565 /* re-use the existing session */
11566 hdd_stop_all_adapters(hdd_ctx, false);
11567 break;
11568 default:
11569 break;
11570 }
11571}
11572
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011573static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011574 enum tQDF_GLOBAL_CON_MODE curr_mode)
11575{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011576 int driver_status;
11577
11578 driver_status = hdd_ctx->driver_status;
11579
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011580 switch (curr_mode) {
11581 case QDF_GLOBAL_MISSION_MODE:
11582 case QDF_GLOBAL_MONITOR_MODE:
11583 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011584 hdd_deinit_all_adapters(hdd_ctx, false);
11585 hdd_close_all_adapters(hdd_ctx, false);
11586 break;
11587 case QDF_GLOBAL_EPPING_MODE:
11588 epping_disable();
11589 epping_close();
11590 break;
11591 default:
11592 return;
11593 }
11594}
11595
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011596static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011597 enum tQDF_GLOBAL_CON_MODE mode)
11598{
Jeff Johnson9d295242017-08-29 14:39:48 -070011599 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011600 int ret = 0;
11601 bool rtnl_held;
11602 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11603 QDF_STATUS status;
11604
11605 if (!qdf_dev) {
11606 hdd_err("qdf device context is Null return!");
11607 return -EINVAL;
11608 }
11609
11610 rtnl_held = hdd_hold_rtnl_lock();
11611 switch (mode) {
11612 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011613 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11614 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011615 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011616 break;
11617 case QDF_GLOBAL_FTM_MODE:
11618 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11619 wlan_hdd_get_intf_addr(hdd_ctx),
11620 NET_NAME_UNKNOWN, rtnl_held);
11621 if (adapter == NULL)
11622 ret = -EINVAL;
11623 break;
11624 case QDF_GLOBAL_MONITOR_MODE:
11625 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11626 wlan_hdd_get_intf_addr(hdd_ctx),
11627 NET_NAME_UNKNOWN, rtnl_held);
11628 if (adapter == NULL)
11629 ret = -EINVAL;
11630 break;
11631 case QDF_GLOBAL_EPPING_MODE:
11632 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011633 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011634 hdd_err("Failed to open in eeping mode: %d", status);
11635 ret = -EINVAL;
11636 break;
11637 }
11638 ret = epping_enable(qdf_dev->dev);
11639 if (ret) {
11640 hdd_err("Failed to enable in epping mode : %d", ret);
11641 epping_close();
11642 }
11643 break;
11644 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011645 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011646 ret = -ENOTSUPP;
11647 break;
11648 }
11649 hdd_release_rtnl_lock();
11650 rtnl_held = false;
11651 return ret;
11652}
11653
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011654/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011655 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011656 * @kmessage: con mode name on which driver to be bring up
11657 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011658 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011659 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011660 * This function is invoked when user updates con mode using sys entry,
11661 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011662 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011663 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011664 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011665static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011666 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011667{
11668 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011669 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011670 enum tQDF_GLOBAL_CON_MODE curr_mode;
11671 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011672
Dustin Brownab6029b2017-05-24 13:04:19 -070011673 hdd_info("con_mode handler: %s", kmessage);
11674
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011675 ret = wlan_hdd_validate_context(hdd_ctx);
11676 if (ret)
11677 return ret;
11678
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011679 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011680
11681 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011682
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011683 if (!(is_con_mode_valid(con_mode))) {
11684 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011685 ret = -EINVAL;
11686 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011687 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011688
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011689 curr_mode = hdd_get_conparam();
11690 if (curr_mode == con_mode) {
11691 hdd_err("curr mode: %d is same as user triggered mode %d",
11692 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011693 ret = 0;
11694 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011695 }
11696
Dustin Brown27cd9942017-09-27 16:11:44 -070011697 /* ensure adapters are stopped */
11698 hdd_stop_present_mode(hdd_ctx, curr_mode);
11699
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011700 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011701 if (ret) {
11702 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011703 goto reset_flags;
11704 }
11705
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011706 /* Cleanup present mode before switching to new mode */
11707 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11708
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011709 hdd_set_conparam(con_mode);
11710
11711 /* Register for new con_mode & then kick_start modules again */
11712 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11713 if (ret) {
11714 hdd_err("Failed to register for new mode");
11715 goto reset_flags;
11716 }
11717
11718 adapter_mode = hdd_get_adpter_mode(con_mode);
11719 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11720 hdd_err("invalid adapter");
11721 ret = -EINVAL;
11722 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011723 }
11724
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011725 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011726 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011727 hdd_err("Failed to get adapter:%d", adapter_mode);
11728 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011729 }
11730
11731 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11732 if (ret) {
11733 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011734 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011735 }
11736
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011737 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011738 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011739 if (hdd_start_adapter(adapter)) {
11740 hdd_err("Failed to start %s adapter", kmessage);
11741 ret = -EINVAL;
11742 goto reset_flags;
11743 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011744 }
11745
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011746 hdd_info("Mode successfully changed to %s", kmessage);
11747 ret = 0;
11748
11749reset_flags:
11750 cds_set_load_in_progress(false);
11751 return ret;
11752}
11753
11754
11755static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11756{
11757 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011758 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011759
11760 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11761 ret = wlan_hdd_validate_context(hdd_ctx);
11762 if (ret)
11763 return ret;
11764
11765 cds_ssr_protect(__func__);
11766 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11767 cds_ssr_unprotect(__func__);
11768
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011769 return ret;
11770}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011771
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011772static int con_mode_handler_ftm(const char *kmessage,
11773 struct kernel_param *kp)
11774{
11775 int ret;
11776
11777 ret = param_set_int(kmessage, kp);
11778
11779 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11780 pr_err("Only FTM mode supported!");
11781 return -ENOTSUPP;
11782 }
11783
11784 hdd_set_conparam(con_mode_ftm);
11785 con_mode = con_mode_ftm;
11786
11787 return ret;
11788}
11789
Ravi Joshia307f632017-07-17 23:41:41 -070011790static int con_mode_handler_monitor(const char *kmessage,
11791 struct kernel_param *kp)
11792{
11793 int ret;
11794
11795 ret = param_set_int(kmessage, kp);
11796
11797 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11798 pr_err("Only Monitor mode supported!");
11799 return -ENOTSUPP;
11800 }
11801
11802 hdd_set_conparam(con_mode_monitor);
11803 con_mode = con_mode_monitor;
11804
11805 return ret;
11806}
11807
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011808/**
11809 * hdd_get_conparam() - driver exit point
11810 *
11811 * This is the driver exit point (invoked when module is unloaded using rmmod)
11812 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011813 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011814 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011815enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011816{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011817 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011818}
11819
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011820void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011821{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011822 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011823}
11824
Komal Seelamc11bb222016-01-27 18:57:10 +053011825/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011826 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11827 * @hdd_ctx: HDD context
11828 *
11829 * Cleans up the pre cac interface, if it exists
11830 *
11831 * Return: None
11832 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011833void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011834{
11835 uint8_t session_id;
11836 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011837 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011838
11839 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11840 if (QDF_IS_STATUS_ERROR(status)) {
11841 hdd_err("failed to get pre cac vdev id");
11842 return;
11843 }
11844
11845 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11846 if (!precac_adapter) {
11847 hdd_err("invalid pre cac adapater");
11848 return;
11849 }
11850
11851 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11852 wlan_hdd_sap_pre_cac_failure,
11853 (void *)precac_adapter);
11854 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11855
11856}
11857
11858/**
Komal Seelamec702b02016-02-24 18:42:16 +053011859 * hdd_update_ol_config - API to update ol configuration parameters
11860 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011861 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011862 * Return: void
11863 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011864static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011865{
Komal Seelamec702b02016-02-24 18:42:16 +053011866 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011867 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011868
Komal Seelamec702b02016-02-24 18:42:16 +053011869 if (!ol_ctx)
11870 return;
11871
11872 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11873 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11874 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11875 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011876 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011877
11878 ol_init_ini_config(ol_ctx, &cfg);
11879}
11880
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011881#ifdef FEATURE_RUNTIME_PM
11882/**
11883 * hdd_populate_runtime_cfg() - populate runtime configuration
11884 * @hdd_ctx: hdd context
11885 * @cfg: pointer to the configuration memory being populated
11886 *
11887 * Return: void
11888 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011889static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011890 struct hif_config_info *cfg)
11891{
11892 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11893 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11894}
11895#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011896static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011897 struct hif_config_info *cfg)
11898{
11899}
11900#endif
11901
Komal Seelamec702b02016-02-24 18:42:16 +053011902/**
11903 * hdd_update_hif_config - API to update HIF configuration parameters
11904 * @hdd_ctx: HDD Context
11905 *
11906 * Return: void
11907 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011908static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011909{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011910 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011911 struct hif_config_info cfg;
11912
11913 if (!scn)
11914 return;
11915
11916 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011917 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011918 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011919
11920 if (hdd_ctx->config->prevent_link_down)
11921 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011922}
11923
11924/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011925 * hdd_update_dp_config() - Propagate config parameters to Lithium
11926 * datapath
11927 * @hdd_ctx: HDD Context
11928 *
11929 * Return: 0 for success/errno for failure
11930 */
11931static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
11932{
11933 struct cdp_config_params params;
11934 QDF_STATUS status;
11935
11936 params.tso_enable = hdd_ctx->config->tso_enable;
11937 params.lro_enable = hdd_ctx->config->lro_enable;
11938#ifdef QCA_LL_TX_FLOW_CONTROL_V2
11939 params.tx_flow_stop_queue_threshold =
11940 hdd_ctx->config->TxFlowStopQueueThreshold;
11941 params.tx_flow_start_queue_offset =
11942 hdd_ctx->config->TxFlowStartQueueOffset;
11943#endif
11944 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
11945 params.napi_enable = hdd_ctx->napi_enable;
11946 params.tcp_udp_checksumoffload =
11947 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
11948
11949 status = cdp_update_config_parameters(
11950 cds_get_context(QDF_MODULE_ID_SOC),
11951 &params);
11952 if (status) {
11953 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
11954 "%s: Failed to attach config parameters", __func__);
11955 return status;
11956 }
11957
11958 return 0;
11959}
11960
11961/**
Komal Seelamec702b02016-02-24 18:42:16 +053011962 * hdd_update_config() - Initialize driver per module ini parameters
11963 * @hdd_ctx: HDD Context
11964 *
11965 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011966 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011967 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011968int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011969{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011970 int ret;
11971
Komal Seelamec702b02016-02-24 18:42:16 +053011972 hdd_update_ol_config(hdd_ctx);
11973 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011974 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11975 ret = hdd_update_cds_config_ftm(hdd_ctx);
11976 else
11977 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011978 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011979
11980 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011981}
11982
Mukul Sharma9d797a02017-01-05 20:26:03 +053011983#ifdef FEATURE_WLAN_RA_FILTERING
11984/**
11985 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11986 * @psoc_cfg: pmo psoc Configuration
11987 * @hdd_ctx: Pointer to hdd context
11988 *
11989 * Return: none
11990 */
11991static inline void hdd_ra_populate_pmo_config(
11992 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011993 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011994{
11995 psoc_cfg->ra_ratelimit_interval =
11996 hdd_ctx->config->RArateLimitInterval;
11997 psoc_cfg->ra_ratelimit_enable =
11998 hdd_ctx->config->IsRArateLimitEnabled;
11999}
12000#else
12001static inline void hdd_ra_populate_pmo_config(
12002 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012003 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012004{
12005}
12006#endif
12007/**
12008 * hdd_update_pmo_config - API to update pmo configuration parameters
12009 * @hdd_ctx: HDD context
12010 *
12011 * Return: void
12012 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012013static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012014{
12015 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12016 struct pmo_psoc_cfg psoc_cfg;
12017 QDF_STATUS status;
12018
12019 /*
12020 * Value of hdd_ctx->wowEnable can be,
12021 * 0 - Disable both magic pattern match and pattern byte match.
12022 * 1 - Enable magic pattern match on all interfaces.
12023 * 2 - Enable pattern byte match on all interfaces.
12024 * 3 - Enable both magic patter and pattern byte match on
12025 * all interfaces.
12026 */
12027 psoc_cfg.magic_ptrn_enable =
12028 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12029 psoc_cfg.ptrn_match_enable_all_vdev =
12030 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012031 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12032 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012033 psoc_cfg.bpf_enable =
12034 hdd_ctx->config->bpf_packet_filter_enable;
12035 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012036 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012037 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12038 if (hdd_ctx->config->fhostNSOffload)
12039 psoc_cfg.ns_offload_enable_dynamic = true;
12040 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12041 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12042 psoc_cfg.active_mode_offload =
12043 hdd_ctx->config->active_mode_offload;
12044 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
12045 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012046 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12047 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12048 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12049 psoc_cfg.power_save_mode =
12050 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012051 psoc_cfg.auto_power_save_fail_mode =
12052 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012053
12054 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012055 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12056 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012057 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
12058 if (status != QDF_STATUS_SUCCESS) {
12059 hdd_err("failed pmo psoc configuration");
12060 return -EINVAL;
12061 }
12062
12063 return 0;
12064}
12065
Abhishek Singhb20db962017-03-03 21:28:46 +053012066#ifdef FEATURE_WLAN_SCAN_PNO
12067static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12068 struct hdd_config *cfg)
12069{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012070 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12071
Abhishek Singhb20db962017-03-03 21:28:46 +053012072 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12073 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12074 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12075 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12076 pno_cfg->channel_prediction_full_scan =
12077 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012078 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12079 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12080 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12081 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012082}
12083#else
12084static inline void
12085hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012086 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012087{
Abhishek Singhb20db962017-03-03 21:28:46 +053012088}
12089#endif
12090
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012091void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12092 struct hdd_config *cfg)
12093{
12094 uint8_t i = 0;
12095
12096 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12097 if (!ie_whitelist->white_list)
12098 return;
12099
12100 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12101 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12102 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12103 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12104 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12105 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12106 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12107 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12108
12109 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12110 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12111 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12112}
12113
Abhishek Singh257a9482017-03-06 16:52:39 +053012114/**
12115 * hdd_update_scan_config - API to update scan configuration parameters
12116 * @hdd_ctx: HDD context
12117 *
12118 * Return: 0 if success else err
12119 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012120static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012121{
12122 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12123 struct scan_user_cfg scan_cfg;
12124 struct hdd_config *cfg = hdd_ctx->config;
12125 QDF_STATUS status;
12126
12127 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12128 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12129 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12130 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12131 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12132 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12133 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012134 /* convert to ms */
12135 scan_cfg.scan_cache_aging_time =
12136 cfg->scanAgingTimeout * 1000;
12137 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12138 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12139 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12140 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012141 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012142 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Kiran Kumar Lokerea2dfefe2017-06-29 19:01:24 -070012143 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time ;
12144 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes ;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012145 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Abhishek Singh257a9482017-03-06 16:52:39 +053012146
Abhishek Singhb20db962017-03-03 21:28:46 +053012147 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012148 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012149
Abhishek Singh257a9482017-03-06 16:52:39 +053012150 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12151 if (status != QDF_STATUS_SUCCESS) {
12152 hdd_err("failed pmo psoc configuration");
12153 return -EINVAL;
12154 }
12155
12156 return 0;
12157}
Abhishek Singh257a9482017-03-06 16:52:39 +053012158
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012159static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012160{
12161 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12162 struct tdls_start_params tdls_cfg;
12163 struct tdls_user_config *config = &tdls_cfg.config;
12164 struct hdd_config *cfg = hdd_ctx->config;
12165 QDF_STATUS status;
12166
12167 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12168 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12169 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12170 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12171 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12172 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12173 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12174 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12175 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12176 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12177 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12178 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12179 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12180 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12181 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12182 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12183 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12184 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12185 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12186 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12187 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12188 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12189 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12190 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12191 (cfg->fEnableTDLSImplicitTrigger ?
12192 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12193 (cfg->fTDLSExternalControl ?
12194 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12195
12196 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12197 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12198 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12199 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012200 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012201 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012202 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12203 tdls_cfg.tdls_evt_cb_data = psoc;
12204 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12205 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12206 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012207 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12208 tdls_cfg.tdls_wmm_cb_data = psoc;
12209 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12210 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012211 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012212
12213 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12214 if (status != QDF_STATUS_SUCCESS) {
12215 hdd_err("failed pmo psoc configuration");
12216 return -EINVAL;
12217 }
12218
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012219 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012220 /* enable napier specific tdls data path */
12221 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012222
Frank Liud4b2fa02017-03-29 11:46:48 +080012223 return 0;
12224}
Frank Liud4b2fa02017-03-29 11:46:48 +080012225
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012226int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012227{
12228 int ret;
12229
12230 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012231 if (ret)
12232 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012233
Abhishek Singh257a9482017-03-06 16:52:39 +053012234 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012235 if (ret)
12236 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012237
Frank Liud4b2fa02017-03-29 11:46:48 +080012238 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012239 if (ret)
12240 return ret;
12241
12242 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012243
12244 return ret;
12245}
12246
Agrawal Ashish65634612016-08-18 13:24:32 +053012247/**
12248 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12249 * @mode : cfg80211 DFS mode
12250 *
12251 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12252 */
12253enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12254{
12255 switch (mode) {
12256 case DFS_MODE_ENABLE:
12257 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012258 case DFS_MODE_DISABLE:
12259 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012260 case DFS_MODE_DEPRIORITIZE:
12261 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012262 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012263 hdd_debug("ACS dfs mode is NONE");
12264 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012265 }
12266}
12267
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012268/**
12269 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12270 * @hddctx: pointer to hdd context
12271 * @set_value: enable/disable
12272 *
12273 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12274 * Host(even though it is duplicate). When Host send vendor command
12275 * disable,FW doesn't perform any action. Whenever any change in
12276 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12277 *
12278 * return - 0 on success, appropriate error values on failure.
12279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012280int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012281{
12282 QDF_STATUS status;
12283
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012284 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012285 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012286
12287 if (!hddctx->config->goptimize_chan_avoid_event) {
12288 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12289 return -EINVAL;
12290 }
12291
12292 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12293 if (!QDF_IS_STATUS_SUCCESS(status)) {
12294 hdd_err("Failed to send chan avoid command to SME");
12295 return -EINVAL;
12296 }
12297 return 0;
12298}
Agrawal Ashish65634612016-08-18 13:24:32 +053012299
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012300/**
12301 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12302 * @value: value to set
12303 *
12304 * This function will set the passed value to roaming in progress flag.
12305 *
12306 * Return: None
12307 */
12308void hdd_set_roaming_in_progress(bool value)
12309{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012310 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012311
12312 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12313 if (!hdd_ctx) {
12314 hdd_err("HDD context is NULL");
12315 return;
12316 }
12317
12318 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012319 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012320}
12321
12322/**
12323 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012324 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012325 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012326 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012327 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012328bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012329{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012330 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012331 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012332
12333 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12334 if (!hdd_ctx) {
12335 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012336 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012337 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012338 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12339 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012340 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12341 hdd_ctx->roaming_in_progress);
12342
12343 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012344}
12345
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012346/**
12347 * hdd_is_connection_in_progress() - check if connection is in
12348 * progress
12349 * @session_id: session id
12350 * @reason: scan reject reason
12351 *
12352 * Go through each adapter and check if Connection is in progress
12353 *
12354 * Return: true if connection is in progress else false
12355 */
12356bool hdd_is_connection_in_progress(uint8_t *session_id,
12357 enum scan_reject_states *reason)
12358{
12359 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012360 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012361 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012362 QDF_STATUS status = 0;
12363 uint8_t sta_id = 0;
12364 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012365 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012366
12367 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12368 if (!hdd_ctx) {
12369 hdd_err("HDD context is NULL");
12370 return false;
12371 }
12372
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012373 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12374 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012375 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012376 if (!adapter)
12377 goto end;
12378
12379 hdd_info("Adapter with device mode %s(%d) exists",
12380 hdd_device_mode_to_string(adapter->device_mode),
12381 adapter->device_mode);
12382 if (((QDF_STA_MODE == adapter->device_mode)
12383 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12384 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12385 && (eConnectionState_Connecting ==
12386 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12387 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012388 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012389 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12390 adapter->sessionId);
12391 if (session_id && reason) {
12392 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012393 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012394 }
12395 return true;
12396 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012397 /*
12398 * sme_neighbor_middle_of_roaming is for LFR2
12399 * hdd_is_roaming_in_progress is for LFR3
12400 */
12401 if (((QDF_STA_MODE == adapter->device_mode) &&
12402 sme_neighbor_middle_of_roaming(
12403 WLAN_HDD_GET_HAL_CTX(adapter),
12404 adapter->sessionId)) ||
12405 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012406 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012407 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12408 adapter->sessionId);
12409 if (session_id && reason) {
12410 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012411 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012412 }
12413 return true;
12414 }
12415 if ((QDF_STA_MODE == adapter->device_mode) ||
12416 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12417 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12418 hdd_sta_ctx =
12419 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12420 if ((eConnectionState_Associated ==
12421 hdd_sta_ctx->conn_info.connState)
12422 && (false ==
12423 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12424 sta_mac = (uint8_t *)
12425 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012426 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012427 " is in middle of WPS/EAPOL exchange.",
12428 MAC_ADDR_ARRAY(sta_mac));
12429 if (session_id && reason) {
12430 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012431 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012432 }
12433 return true;
12434 }
12435 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12436 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12437 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12438 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012439 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012440 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012441 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012442 continue;
12443
12444 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012445 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070012446 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012447 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012448 " of SAP/GO is in middle of WPS/EAPOL exchange",
12449 MAC_ADDR_ARRAY(sta_mac));
12450 if (session_id && reason) {
12451 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012452 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012453 }
12454 return true;
12455 }
12456 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012457 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012458 return true;
12459 }
12460 }
12461end:
12462 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12463 adapter_node = next;
12464 }
12465 return false;
12466}
12467
12468/**
12469 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012470 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012471 *
12472 * Return: None
12473 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012474void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012475{
Jeff Johnson87251032017-08-29 13:31:11 -070012476 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012477 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012478 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012479 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012480 tsap_Config_t *sap_config;
12481 void *sap_ctx;
12482
12483 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12484 sap_config = &hdd_ap_ctx->sapConfig;
12485 sap_ctx = hdd_ap_ctx->sapContext;
12486
12487 mutex_lock(&hdd_ctx->sap_lock);
12488 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12489 wlan_hdd_del_station(ap_adapter);
12490 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12491 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12492 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12493 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12494 qdf_status =
12495 qdf_wait_single_event(&hostapd_state->
12496 qdf_stop_bss_event,
12497 SME_CMD_TIMEOUT_VALUE);
12498
12499 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012500 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012501 goto end;
12502 }
12503 }
12504 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012505 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012506 ap_adapter->device_mode, ap_adapter->sessionId);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012507 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012508
12509 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012510 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012511 wlansap_reset_sap_config_add_ie(sap_config,
12512 eUPDATE_IE_ALL);
12513 goto end;
12514 }
12515
12516 qdf_event_reset(&hostapd_state->qdf_event);
12517 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12518 sap_config,
12519 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012520 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012521 wlansap_reset_sap_config_add_ie(sap_config,
12522 eUPDATE_IE_ALL);
12523 goto end;
12524 }
12525
Jeff Johnson6867ec32017-09-29 20:30:20 -070012526 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012527 qdf_status =
12528 qdf_wait_single_event(&hostapd_state->qdf_event,
12529 SME_CMD_TIMEOUT_VALUE);
12530 wlansap_reset_sap_config_add_ie(sap_config,
12531 eUPDATE_IE_ALL);
12532 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012533 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012534 goto end;
12535 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012536 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012537 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12538 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012539 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12540 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012541 ap_adapter->sessionId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012542 }
12543end:
12544 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012545}
12546
12547/**
12548 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12549 * with non dfs acs
12550 *
12551 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12552 *
12553 * Return: None
12554 */
12555void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12556{
Jeff Johnson9d295242017-08-29 14:39:48 -070012557 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012558 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012559 cds_context_type *cds_ctx;
12560
12561 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12562 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012563 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012564 return;
12565 }
12566
12567 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12568 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012569 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012570 return;
12571 }
12572
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012573 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12574 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012575 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012576 return;
12577 }
12578
12579 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012580 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12581 &ap_adapter->event_flags) &&
12582 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12583 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012584
Jeff Johnson6867ec32017-09-29 20:30:20 -070012585 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012586 ap_adapter->sessionCtx.ap.sapConfig.channel =
12587 AUTO_CHANNEL_SELECT;
12588 ap_adapter->sessionCtx.ap.sapConfig.
12589 acs_cfg.acs_mode = true;
12590
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012591 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012592 }
12593}
12594
12595/**
12596 * hdd_set_connection_in_progress() - to set the connection in
12597 * progress flag
12598 * @value: value to set
12599 *
12600 * This function will set the passed value to connection in progress flag.
12601 * If value is previously being set to true then no need to set it again.
12602 *
12603 * Return: true if value is being set correctly and false otherwise.
12604 */
12605bool hdd_set_connection_in_progress(bool value)
12606{
12607 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012608 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012609
12610 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12611 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012612 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012613 return false;
12614 }
12615
12616 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12617 /*
12618 * if the value is set to true previously and if someone is
12619 * trying to make it true again then it could be some race
12620 * condition being triggered. Avoid this situation by returning
12621 * false
12622 */
12623 if (hdd_ctx->connection_in_progress && value)
12624 status = false;
12625 else
12626 hdd_ctx->connection_in_progress = value;
12627 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12628 return status;
12629}
12630
Jeff Johnson9d295242017-08-29 14:39:48 -070012631int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012632{
12633 if (!adapter) {
12634 hdd_err("Invalid adapter");
12635 return -EINVAL;
12636 }
12637 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012638 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012639 WMA_VDEV_MCC_SET_TIME_QUOTA,
12640 set_value, VDEV_CMD);
12641 return 0;
12642
12643}
12644
Jeff Johnson9d295242017-08-29 14:39:48 -070012645int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012646{
12647 if (!adapter) {
12648 hdd_err("Invalid adapter");
12649 return -EINVAL;
12650 }
12651
12652 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012653 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012654 WMA_VDEV_MCC_SET_TIME_LATENCY,
12655 set_value, VDEV_CMD);
12656 return 0;
12657}
12658
Jeff Johnson9d295242017-08-29 14:39:48 -070012659struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012660 *psoc, uint8_t vdev_id)
12661{
Jeff Johnson9d295242017-08-29 14:39:48 -070012662 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012663 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012664
12665 /*
12666 * Currently PSOC is not being used. But this logic will
12667 * change once we have the converged implementation of
12668 * HDD context per PSOC in place. This would break if
12669 * multiple vdev objects reuse the vdev id.
12670 */
12671 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12672 if (!adapter)
12673 hdd_err("Get adapter by vdev id failed");
12674
12675 return adapter;
12676}
12677
Jeff Johnson9d295242017-08-29 14:39:48 -070012678int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012679 int8_t *rssi, int8_t *snr)
12680{
12681 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012682 struct hdd_wext_state *wext_state =
12683 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012684 tCsrRoamProfile *profile = &wext_state->roamProfile;
12685
12686 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12687 profile, bssid, rssi, snr);
12688 if (QDF_STATUS_SUCCESS != status) {
12689 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12690 return -EINVAL;
12691 }
12692
12693 return 0;
12694}
12695
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012696/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012697 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12698 * @adapter - HDD adapter
12699 * @tos - type of service
12700 * @status - status of the traffic
12701 *
12702 * Return: 0 on success and non zero value on failure
12703 */
12704
12705int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12706 bool is_tos_active)
12707{
12708 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012709 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012710 uint32_t max_off_chan_time = 0;
12711 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012712 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012713 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012714
12715 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12716 ret = wlan_hdd_validate_context(hdd_ctx);
12717
12718 if (ret < 0) {
12719 hdd_err("failed to set limit off chan params");
12720 return ret;
12721 }
12722
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012723 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12724
12725 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012726 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012727 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012728 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012729
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012730 if (adapter->active_ac) {
12731 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012732 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012733 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12734 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12735 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012736 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012737 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012738 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12739 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12740 PM_LATENCY);
12741 } else {
12742 /*ignore this command if only BE/BK is active */
12743 is_tos_active = false;
12744 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12745 hdd_ctx->config->conc_system_pref);
12746 }
12747 } else {
12748 /* No active tos */
12749 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12750 hdd_ctx->config->conc_system_pref);
12751 }
12752
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012753 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12754 is_tos_active, max_off_chan_time,
12755 hdd_ctx->config->nRestTimeConc, true);
12756 if (!QDF_IS_STATUS_SUCCESS(status)) {
12757 hdd_err("failed to set limit off chan params");
12758 ret = -EINVAL;
12759 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012760
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012761 return ret;
12762}
12763
12764/**
12765 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
12766 * @adapter - HDD adapter
12767 *
12768 * Return: 0 on success and non zero value on failure
12769 */
12770int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
12771{
12772 struct hdd_context *hdd_ctx;
12773 int ret;
12774 QDF_STATUS status;
12775 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
12776
12777 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12778 ret = wlan_hdd_validate_context(hdd_ctx);
12779 if (ret < 0)
12780 return ret;
12781
12782 /* set the system preferece to default */
12783 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12784 hdd_ctx->config->conc_system_pref);
12785
12786 /* clear the bitmap */
12787 adapter->active_ac = 0;
12788
12789 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
12790 adapter->sessionId, adapter->active_ac);
12791
12792 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12793 false, 0, 0, false);
12794 if (!QDF_IS_STATUS_SUCCESS(status)) {
12795 hdd_err("failed to reset limit off chan params");
12796 ret = -EINVAL;
12797 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012798
12799 return ret;
12800}
12801
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012802/**
12803 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12804 * @drv_op: Enum indicating driver op
12805 *
12806 * Return: none
12807 */
12808void hdd_start_driver_ops_timer(int drv_op)
12809{
12810 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12811 switch (drv_op) {
12812 case eHDD_DRV_OP_PROBE:
12813 memcpy(drv_ops_string, "probe", sizeof("probe"));
12814 break;
12815 case eHDD_DRV_OP_REMOVE:
12816 memcpy(drv_ops_string, "remove", sizeof("remove"));
12817 break;
12818 case eHDD_DRV_OP_SHUTDOWN:
12819 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12820 break;
12821 case eHDD_DRV_OP_REINIT:
12822 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12823 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053012824 case eHDD_DRV_OP_IFF_UP:
12825 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
12826 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012827 }
12828
12829 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12830 HDD_OPS_INACTIVITY_TIMEOUT);
12831}
12832
12833/**
12834 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12835 *
12836 * Return: none
12837 */
12838void hdd_stop_driver_ops_timer(void)
12839{
12840 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12841}
12842
12843/**
12844 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12845 * inactivity timer
12846 *
12847 * Return: None
12848 */
12849void hdd_drv_ops_inactivity_handler(void)
12850{
12851 hdd_err("%s: %d Sec timer expired while in .%s",
12852 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12853
12854 /* Driver shutdown is stuck, no recovery possible at this point */
12855 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12856 sizeof("shutdown")))
12857 QDF_BUG(0);
12858
12859 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012860 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012861 else
12862 QDF_BUG(0);
12863}
12864
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012865void hdd_pld_ipa_uc_shutdown_pipes(void)
12866{
12867 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12868
12869 if (!hdd_ctx)
12870 return;
12871
12872 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12873}
12874
Yun Parkff6a16a2017-09-26 16:38:18 -070012875/**
12876 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
12877 * @struct hdd_context *hdd_ctx
12878 * @struct hdd_adapter *padapter
12879 * @bool enble
12880 *
12881 * Return: none
12882 */
12883void hdd_set_rx_mode_rps(bool enable)
12884{
12885 struct cds_config_info *cds_cfg = cds_get_ini_config();
12886 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12887 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
12888
12889 if (adapter && hdd_ctx &&
12890 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
12891 if (enable && !cds_cfg->rps_enabled)
12892 hdd_send_rps_ind(adapter);
12893 else if (!enable && cds_cfg->rps_enabled)
12894 hdd_send_rps_disable_ind(adapter);
12895 }
12896}
12897
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012898/* Register the module init/exit functions */
12899module_init(hdd_module_init);
12900module_exit(hdd_module_exit);
12901
12902MODULE_LICENSE("Dual BSD/GPL");
12903MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12904MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12905
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012906module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12907 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012908
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012909module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12910 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12911
Ravi Joshia307f632017-07-17 23:41:41 -070012912module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12913 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12914
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012915module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12916 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12917
12918module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12919
12920module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12921
12922module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);