blob: 509dfe54e7db45a0a82c2f0409e614352f86fa19 [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;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001078 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079
1080}
1081
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001082/**
1083 * hdd_update_vdev_nss() - sets the vdev nss
1084 * @hdd_ctx: HDD context
1085 *
1086 * Sets the Nss per vdev type based on INI
1087 *
1088 * Return: None
1089 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001090static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001091{
1092 struct hdd_config *cfg_ini = hdd_ctx->config;
1093 uint8_t max_supp_nss = 1;
1094
Naveen Rawat10b1c152017-01-18 11:16:06 -08001095 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001096 max_supp_nss = 2;
1097
1098 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1099 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1100
1101 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1102 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1103}
1104
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301105/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301106 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1107 * @hdd_ctx: HDD context
1108 *
1109 * Updates wiphy vhtcap fields
1110 *
1111 * Return: None
1112 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001113static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301114{
1115 struct ieee80211_supported_band *band_5g =
1116 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1117 uint32_t val;
1118
1119 if (!band_5g) {
1120 hdd_debug("5GHz band disabled, skipping capability population");
1121 return;
1122 }
1123
1124 val = hdd_ctx->config->txBFCsnValue;
1125 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1126
1127 val = NUM_OF_SOUNDING_DIMENSIONS;
1128 band_5g->vht_cap.cap |=
1129 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1130
1131 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1132 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1133}
1134
1135/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301136 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1137 * @hdd_ctx: HDD context
1138 *
1139 * Sets the DBS capability as per INI and firmware capability
1140 *
1141 * Return: None
1142 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001143static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301144{
1145 struct hdd_config *cfg_ini = hdd_ctx->config;
1146 uint8_t hw_dbs_capable = 0;
1147
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001148 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1149 ((cfg_ini->dual_mac_feature_disable ==
1150 ENABLE_DBS_CXN_AND_SCAN) ||
1151 (cfg_ini->dual_mac_feature_disable ==
1152 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301153 hw_dbs_capable = 1;
1154
1155 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1156}
1157
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001158static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001159 struct wma_tgt_ht_cap *cfg)
1160{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301161 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001162 uint32_t value, val32;
1163 uint16_t val16;
1164 struct hdd_config *pconfig = hdd_ctx->config;
1165 tSirMacHTCapabilityInfo *phtCapInfo;
1166 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1167 uint8_t enable_tx_stbc;
1168
1169 /* check and update RX STBC */
1170 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1171 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1172
1173 /* get the MPDU density */
1174 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1175
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301176 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001177 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178 value = 0;
1179 }
1180
1181 /*
1182 * MPDU density:
1183 * override user's setting if value is larger
1184 * than the one supported by target
1185 */
1186 if (value > cfg->mpdu_density) {
1187 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1188 cfg->mpdu_density);
1189
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301190 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001191 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192 }
1193
1194 /* get the HT capability info */
1195 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301196 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001197 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001198 return;
1199 }
1200 val16 = (uint16_t) val32;
1201 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1202
1203 /* Set the LDPC capability */
1204 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1205
1206 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1207 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1208
1209 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1210 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1211
1212 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1213 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1214
1215 enable_tx_stbc = pconfig->enableTxSTBC;
1216
1217 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1218 pconfig->enable2x2 = 1;
1219 } else {
1220 pconfig->enable2x2 = 0;
1221 enable_tx_stbc = 0;
1222
1223 /* 1x1 */
1224 /* Update Rx Highest Long GI data Rate */
1225 if (sme_cfg_set_int(hdd_ctx->hHal,
1226 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001227 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301228 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001229 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001230 }
1231
1232 /* Update Tx Highest Long GI data Rate */
1233 if (sme_cfg_set_int
1234 (hdd_ctx->hHal,
1235 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001236 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301237 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001238 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001239 }
1240 }
1241 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1242 enable_tx_stbc = 0;
1243 phtCapInfo->txSTBC = enable_tx_stbc;
1244
1245 val32 = val16;
1246 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301247 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001248 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1250 value = SIZE_OF_SUPPORTED_MCS_SET;
1251 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301252 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001253 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001254
1255 if (pconfig->enable2x2) {
1256 for (value = 0; value < cfg->num_rf_chains; value++)
1257 mcs_set[value] =
1258 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1259
1260 status =
1261 sme_cfg_set_str(hdd_ctx->hHal,
1262 WNI_CFG_SUPPORTED_MCS_SET,
1263 mcs_set,
1264 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301265 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001266 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001267 }
1268 }
1269#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1270}
1271
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001272static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001273 struct wma_tgt_vht_cap *cfg)
1274{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301275 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001276 uint32_t value = 0;
1277 struct hdd_config *pconfig = hdd_ctx->config;
1278 struct wiphy *wiphy = hdd_ctx->wiphy;
1279 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001280 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001281 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001282 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001283 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001284
Dustin Brown5e06bd32016-10-04 12:49:10 -07001285 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001286 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001287 return;
1288 }
1289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001290 /* Get the current MPDU length */
1291 status =
1292 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1293 &value);
1294
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301295 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001296 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001297 value = 0;
1298 }
1299
1300 /*
1301 * VHT max MPDU length:
1302 * override if user configured value is too high
1303 * that the target cannot support
1304 */
1305 if (value > cfg->vht_max_mpdu) {
1306 status = sme_cfg_set_int(hdd_ctx->hHal,
1307 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1308 cfg->vht_max_mpdu);
1309
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001310 if (status == QDF_STATUS_E_FAILURE)
1311 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001312 }
1313
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001314 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1315 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1316
1317 if (pconfig->enable2x2)
1318 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1319
1320 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1321 QDF_STATUS_E_FAILURE) {
1322 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1323 }
1324
1325 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1326 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1327 if (pconfig->enable2x2)
1328 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1329
1330 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1331 QDF_STATUS_E_FAILURE) {
1332 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1333 }
1334
1335 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1336 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1337 if (pconfig->enable2x2)
1338 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1339
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001340 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001341 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1342
1343 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1344 QDF_STATUS_E_FAILURE) {
1345 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1346 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001348 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001349 &value);
1350
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301351 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001352 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001353 value = 0;
1354 }
1355
jiad4a7a33c2017-08-08 15:32:24 +08001356 /* Set HW RX LDPC capability */
1357 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1358 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001359 status = sme_cfg_set_int(hdd_ctx->hHal,
1360 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001361 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001362
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001363 if (status == QDF_STATUS_E_FAILURE)
1364 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 }
1366
1367 /* Get current GI 80 value */
1368 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1369 &value);
1370
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301371 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001372 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 value = 0;
1374 }
1375
1376 /* set the Guard interval 80MHz */
1377 if (value && !cfg->vht_short_gi_80) {
1378 status = sme_cfg_set_int(hdd_ctx->hHal,
1379 WNI_CFG_VHT_SHORT_GI_80MHZ,
1380 cfg->vht_short_gi_80);
1381
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001382 if (status == QDF_STATUS_E_FAILURE)
1383 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384 }
1385
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386 /* Get VHT TX STBC cap */
1387 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1388
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301389 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001390 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001391 value = 0;
1392 }
1393
1394 /* VHT TX STBC cap */
1395 if (value && !cfg->vht_tx_stbc) {
1396 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1397 cfg->vht_tx_stbc);
1398
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001399 if (status == QDF_STATUS_E_FAILURE)
1400 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 }
1402
1403 /* Get VHT RX STBC cap */
1404 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1405
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301406 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001407 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001408 value = 0;
1409 }
1410
1411 /* VHT RX STBC cap */
1412 if (value && !cfg->vht_rx_stbc) {
1413 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1414 cfg->vht_rx_stbc);
1415
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001416 if (status == QDF_STATUS_E_FAILURE)
1417 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001418 }
1419
1420 /* Get VHT SU Beamformer cap */
1421 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1422 &value);
1423
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301424 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001425 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001426 value = 0;
1427 }
1428
1429 /* set VHT SU Beamformer cap */
1430 if (value && !cfg->vht_su_bformer) {
1431 status = sme_cfg_set_int(hdd_ctx->hHal,
1432 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1433 cfg->vht_su_bformer);
1434
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001435 if (status == QDF_STATUS_E_FAILURE)
1436 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001437 }
1438
1439 /* check and update SU BEAMFORMEE capabality */
1440 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1441 pconfig->enableTxBF = cfg->vht_su_bformee;
1442
1443 status = sme_cfg_set_int(hdd_ctx->hHal,
1444 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1445 pconfig->enableTxBF);
1446
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001447 if (status == QDF_STATUS_E_FAILURE)
1448 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001449
1450 /* Get VHT MU Beamformer cap */
1451 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1452 &value);
1453
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301454 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001455 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001456 value = 0;
1457 }
1458
1459 /* set VHT MU Beamformer cap */
1460 if (value && !cfg->vht_mu_bformer) {
1461 status = sme_cfg_set_int(hdd_ctx->hHal,
1462 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1463 cfg->vht_mu_bformer);
1464
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001465 if (status == QDF_STATUS_E_FAILURE)
1466 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001467 }
1468
1469 /* Get VHT MU Beamformee cap */
1470 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1471 &value);
1472
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301473 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001474 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001475 value = 0;
1476 }
1477
1478 /* set VHT MU Beamformee cap */
1479 if (value && !cfg->vht_mu_bformee) {
1480 status = sme_cfg_set_int(hdd_ctx->hHal,
1481 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1482 cfg->vht_mu_bformee);
1483
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001484 if (status == QDF_STATUS_E_FAILURE)
1485 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001486 }
1487
1488 /* Get VHT MAX AMPDU Len exp */
1489 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1490 &value);
1491
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301492 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001493 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001494 value = 0;
1495 }
1496
1497 /*
1498 * VHT max AMPDU len exp:
1499 * override if user configured value is too high
1500 * that the target cannot support.
1501 * Even though Rome publish ampdu_len=7, it can
1502 * only support 4 because of some h/w bug.
1503 */
1504
1505 if (value > cfg->vht_max_ampdu_len_exp) {
1506 status = sme_cfg_set_int(hdd_ctx->hHal,
1507 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1508 cfg->vht_max_ampdu_len_exp);
1509
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001510 if (status == QDF_STATUS_E_FAILURE)
1511 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001512 }
1513
1514 /* Get VHT TXOP PS CAP */
1515 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1516
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301517 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001518 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001519 value = 0;
1520 }
1521
1522 /* set VHT TXOP PS cap */
1523 if (value && !cfg->vht_txop_ps) {
1524 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1525 cfg->vht_txop_ps);
1526
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001527 if (status == QDF_STATUS_E_FAILURE)
1528 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529 }
1530
1531 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1532 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1533 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1534 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1535 else
1536 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1537
1538
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001539 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1540 status = sme_cfg_set_int(hdd_ctx->hHal,
1541 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1542 VHT_CAP_160_AND_80P80_SUPP);
1543 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001544 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001545 band_5g->vht_cap.cap |=
1546 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001547 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1548 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1549 status = sme_cfg_set_int(hdd_ctx->hHal,
1550 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1551 VHT_CAP_160_SUPP);
1552 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001553 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001554 band_5g->vht_cap.cap |=
1555 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001556 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1557 }
1558 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1559 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301560 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001561 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301562 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001563 &value);
1564 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301565 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001566 value = 0;
1567 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301568 /* set the Guard interval 160MHz */
1569 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001570 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301571 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1572 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001573
1574 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301575 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001576 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577
1578 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1579 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1580
1581 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1582 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1583 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1584 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1585
1586 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1587 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1588
1589 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1590 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1591 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1592 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1593 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1594 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1595
1596 band_5g->vht_cap.cap |=
1597 (cfg->vht_max_ampdu_len_exp <<
1598 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1599
1600 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1601 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1602 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1603 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1604 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1605 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1606 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1607 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1608
1609 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1610 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1611
1612}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001613
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001614/**
1615 * hdd_generate_macaddr_auto() - Auto-generate mac address
1616 * @hdd_ctx: Pointer to the HDD context
1617 *
1618 * Auto-generate mac address using device serial number.
1619 * Keep the first 3 bytes of OUI as before and replace
1620 * the last 3 bytes with the lower 3 bytes of serial number.
1621 *
1622 * Return: 0 for success
1623 * Non zero failure code for errors
1624 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001625static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001626{
1627 unsigned int serialno = 0;
1628 struct qdf_mac_addr mac_addr = {
1629 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1630 };
1631
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001632 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001633 if (serialno == 0)
1634 return -EINVAL;
1635
1636 serialno &= 0x00ffffff;
1637
1638 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1639 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1640 mac_addr.bytes[5] = serialno & 0xff;
1641
1642 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1643 return 0;
1644}
1645
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301646/**
1647 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1648 * configuration to cfg_ini in HDD
1649 * @hdd_ctx: Pointer to hdd_ctx
1650 * @cfg: target configuration
1651 *
1652 * Return: None
1653 */
1654#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001655static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301656 struct wma_tgt_cfg *cfg)
1657{
1658 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1659}
1660#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001661static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301662 struct wma_tgt_cfg *cfg)
1663{
1664}
1665#endif
1666
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001667void hdd_update_tgt_cfg(void *context, void *param)
1668{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001669 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001670 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001671 struct wma_tgt_cfg *cfg = param;
1672 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001673 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301674 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301675
Yue Mae3e86ab2017-05-08 10:48:24 -07001676 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301677 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1678 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1679 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1680 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1681 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001682 /* Restore pdev to MAC/WMA contexts */
1683 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001684 } else {
1685 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1686 if (ret) {
1687 hdd_err("pdev creation fails!");
1688 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301689 } else
1690 hdd_debug("New pdev has been created with pdev_id = %u",
1691 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301692 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001693
Naveen Rawat64e477e2016-05-20 10:34:56 -07001694 if (cds_cfg) {
1695 if (hdd_ctx->config->enable_sub_20_channel_width !=
1696 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1697 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1698 cds_cfg->sub_20_channel_width =
1699 WLAN_SUB_20_CH_WIDTH_NONE;
1700 } else {
1701 cds_cfg->sub_20_channel_width =
1702 hdd_ctx->config->enable_sub_20_channel_width;
1703 }
1704 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001705
1706 /* first store the INI band capability */
1707 temp_band_cap = hdd_ctx->config->nBandCapability;
1708
1709 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301710 hdd_ctx->is_fils_roaming_supported =
1711 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001712
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001713 /*
1714 * now overwrite the target band capability with INI
1715 * setting if INI setting is a subset
1716 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001717
1718 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1719 (temp_band_cap != eCSR_BAND_ALL))
1720 hdd_ctx->config->nBandCapability = temp_band_cap;
1721 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1722 (temp_band_cap != eCSR_BAND_ALL) &&
1723 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001724 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001725 }
1726
Amar Singhal58b45ef2017-08-01 13:43:54 -07001727 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1728
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301729 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001730 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1731 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1732 }
1733
1734 /* This can be extended to other configurations like ht, vht cap... */
1735
Anurag Chouhanc5548422016-02-24 18:33:27 +05301736 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001737 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001738 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001739 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001740 static struct qdf_mac_addr default_mac_addr = {
1741 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1742 };
1743 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1744 &default_mac_addr)) {
1745 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1746 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1747 MAC_ADDRESS_STR,
1748 MAC_ADDR_ARRAY(hdd_ctx->config->
1749 intfMacAddr[0].bytes));
1750 } else {
1751 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1752 MAC_ADDRESS_STR,
1753 MAC_ADDR_ARRAY(hdd_ctx->config->
1754 intfMacAddr[0].bytes));
1755 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001756 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757 }
1758
1759 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001760 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001761
1762 hdd_ctx->max_intf_count = cfg->max_intf_count;
1763
Jeff Johnsonc875e242016-09-23 18:12:34 -07001764 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001765 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001767 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1768 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1769
1770 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1771
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001772 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001773 if (cfg->services.en_11ax) {
1774 hdd_info("11AX: 11ax is enabled - update HDD config");
1775 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1776 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001777
1778 hdd_update_vdev_nss(hdd_ctx);
1779
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301780 hdd_update_hw_dbs_capable(hdd_ctx);
1781
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001782 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001783 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001784 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001785 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001786
Nitesh Shahe50711f2017-04-26 16:30:45 +05301787 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1788 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1789 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001790 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001791 hdd_ctx->current_antenna_mode);
1792
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001793 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1794 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301795 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301796
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301797 if ((hdd_ctx->config->txBFCsnValue >
1798 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1799 !cfg->tx_bfee_8ss_enabled)
1800 hdd_ctx->config->txBFCsnValue =
1801 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1802
1803 if (sme_cfg_set_int(hdd_ctx->hHal,
1804 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1805 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1806 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1807
1808
1809 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1810 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1811 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301812
1813 /*
1814 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1815 */
1816 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301817
1818 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1819
Arun Khandavallid454d422016-08-17 12:47:05 +05301820 /*
1821 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1822 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1823 * configure the STA mode wow pattern.
1824 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301825 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301826 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301827
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301828 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1829
Yue Macd359b72017-10-03 15:21:00 -07001830 /*
1831 * This needs to be done after HDD pdev is created and stored since
1832 * it will access the HDD pdev object lock.
1833 */
1834 hdd_runtime_suspend_context_init(hdd_ctx);
1835
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001836 /* Configure NAN datapath features */
1837 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001838 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001839}
1840
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001841bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001842{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001843 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001844 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301845 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001846 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001847
Arif Hussaincd151632017-02-11 16:57:19 -08001848 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001849 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001850 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301851 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001852 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001853
Arif Hussaincd151632017-02-11 16:57:19 -08001854 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1855 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001856 adapter = adapterNode->adapter;
Arif Hussaincd151632017-02-11 16:57:19 -08001857 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1858
1859 if ((QDF_SAP_MODE == adapter->device_mode ||
1860 QDF_P2P_GO_MODE == adapter->device_mode) &&
1861 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1862 ap_ctx->operatingChannel))) {
1863 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1864 true;
1865 hdd_info("tx blocked for session: %d",
1866 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301867 }
Arif Hussaincd151632017-02-11 16:57:19 -08001868 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1869 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001870 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301871
1872 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001873}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001874
1875/**
1876 * hdd_is_valid_mac_address() - validate MAC address
1877 * @pMacAddr: Pointer to the input MAC address
1878 *
1879 * This function validates whether the given MAC address is valid or not
1880 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1881 * where X is the hexa decimal digit character and separated by ':'
1882 * This algorithm works even if MAC address is not separated by ':'
1883 *
1884 * This code checks given input string mac contains exactly 12 hexadecimal
1885 * digits and a separator colon : appears in the input string only after
1886 * an even number of hex digits.
1887 *
1888 * Return: 1 for valid and 0 for invalid
1889 */
1890bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1891{
1892 int xdigit = 0;
1893 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001894
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001895 while (*pMacAddr) {
1896 if (isxdigit(*pMacAddr)) {
1897 xdigit++;
1898 } else if (':' == *pMacAddr) {
1899 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1900 break;
1901
1902 ++separator;
1903 } else {
1904 /* Invalid MAC found */
1905 return 0;
1906 }
1907 ++pMacAddr;
1908 }
1909 return xdigit == 12 && (separator == 5 || separator == 0);
1910}
1911
1912/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301913 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1914 * @dev: Handle to struct net_device to be updated.
1915 *
1916 * Return: None
1917 */
1918static void hdd_mon_mode_ether_setup(struct net_device *dev)
1919{
1920 dev->header_ops = NULL;
1921 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1922 dev->hard_header_len = ETH_HLEN;
1923 dev->mtu = ETH_DATA_LEN;
1924 dev->addr_len = ETH_ALEN;
1925 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1926 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1927 dev->priv_flags |= IFF_TX_SKB_SHARING;
1928
1929 memset(dev->broadcast, 0xFF, ETH_ALEN);
1930}
1931
1932/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001933 * __hdd__mon_open() - HDD Open function
1934 * @dev: Pointer to net_device structure
1935 *
1936 * This is called in response to ifconfig up
1937 *
1938 * Return: 0 for success; non-zero for failure
1939 */
1940static int __hdd_mon_open(struct net_device *dev)
1941{
1942 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001943 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1944 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001945
1946 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001947
1948 ret = wlan_hdd_validate_context(hdd_ctx);
1949 if (ret)
1950 return ret;
1951
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301952 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001953
1954 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1955 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1956 if (ret) {
1957 hdd_err("Failed to start WLAN modules return");
1958 return ret;
1959 }
1960 hdd_err("hdd_wlan_start_modules() successful !");
1961
1962 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1963 ret = hdd_start_adapter(adapter);
1964 if (ret) {
1965 hdd_err("Failed to start adapter :%d",
1966 adapter->device_mode);
1967 return ret;
1968 }
1969 hdd_err("hdd_start_adapters() successful !");
1970 }
1971 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1972 }
1973
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001974 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001975
1976 if (!ret)
1977 ret = hdd_enable_monitor_mode(dev);
1978
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001979 return ret;
1980}
1981
1982/**
1983 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1984 * @dev: Pointer to net_device structure
1985 *
1986 * This is called in response to ifconfig up
1987 *
1988 * Return: 0 for success; non-zero for failure
1989 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001990static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001991{
1992 int ret;
1993
1994 cds_ssr_protect(__func__);
1995 ret = __hdd_mon_open(dev);
1996 cds_ssr_unprotect(__func__);
1997
1998 return ret;
1999}
2000
2001/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302002 * hdd_start_adapter() - Wrapper function for device specific adapter
2003 * @adapter: pointer to HDD adapter
2004 *
2005 * This function is called to start the device specific adapter for
2006 * the mode passed in the adapter's device_mode.
2007 *
2008 * Return: 0 for success; non-zero for failure
2009 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002010int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302011{
2012
2013 int ret;
2014 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
2015
2016 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002017 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302018
2019 switch (device_mode) {
2020 case QDF_P2P_CLIENT_MODE:
2021 case QDF_P2P_DEVICE_MODE:
2022 case QDF_OCB_MODE:
2023 case QDF_STA_MODE:
2024 case QDF_MONITOR_MODE:
2025 ret = hdd_start_station_adapter(adapter);
2026 if (ret)
2027 goto err_start_adapter;
2028 break;
2029 case QDF_P2P_GO_MODE:
2030 case QDF_SAP_MODE:
2031 ret = hdd_start_ap_adapter(adapter);
2032 if (ret)
2033 goto err_start_adapter;
2034 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302035 case QDF_IBSS_MODE:
2036 /*
2037 * For IBSS interface is initialized as part of
2038 * hdd_init_station_mode()
2039 */
2040 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302041 case QDF_FTM_MODE:
2042 ret = hdd_start_ftm_adapter(adapter);
2043 if (ret)
2044 goto err_start_adapter;
2045 break;
2046 default:
2047 hdd_err("Invalid session type %d", device_mode);
2048 QDF_ASSERT(0);
2049 goto err_start_adapter;
2050 }
2051 if (hdd_set_fw_params(adapter))
2052 hdd_err("Failed to set the FW params for the adapter!");
2053
2054 /*
2055 * Action frame registered in one adapter which will
2056 * applicable to all interfaces
2057 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302058 ret = wlan_hdd_cfg80211_register_frames(adapter);
2059 if (ret < 0) {
2060 hdd_err("Failed to register frames - ret %d", ret);
2061 goto err_start_adapter;
2062 }
2063
Arun Khandavallifae92942016-08-01 13:31:08 +05302064 EXIT();
2065 return 0;
2066err_start_adapter:
2067 return -EINVAL;
2068}
2069
2070/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302071 * hdd_enable_power_management() - API to Enable Power Management
2072 *
2073 * API invokes Bus Interface Layer power management functionality
2074 *
2075 * Return: None
2076 */
2077static void hdd_enable_power_management(void)
2078{
2079 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2080
2081 if (!hif_ctx) {
2082 hdd_err("Bus Interface Context is Invalid");
2083 return;
2084 }
2085
2086 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2087}
2088
2089/**
2090 * hdd_disable_power_management() - API to disable Power Management
2091 *
2092 * API disable Bus Interface Layer Power management functionality
2093 *
2094 * Return: None
2095 */
2096static void hdd_disable_power_management(void)
2097{
2098 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2099
2100 if (!hif_ctx) {
2101 hdd_err("Bus Interface Context is Invalid");
2102 return;
2103 }
2104
2105 hif_disable_power_management(hif_ctx);
2106}
2107
2108/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302109 * hdd_update_hw_sw_info() - API to update the HW/SW information
2110 *
2111 * API to update the HW and SW information in the driver
2112 *
2113 * Return: None
2114 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002115static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302116{
2117 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002118 size_t target_hw_name_len;
2119 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302120
2121 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2122 if (!hif_sc) {
2123 hdd_err("HIF context is NULL");
2124 return;
2125 }
2126
2127 /*
2128 * target hw version/revision would only be retrieved after firmware
2129 * download
2130 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002131 hif_get_hw_info(hif_sc,
2132 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302133 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002134 &target_hw_name);
2135
2136 if (hdd_ctx->target_hw_name)
2137 qdf_mem_free(hdd_ctx->target_hw_name);
2138
2139 target_hw_name_len = strlen(target_hw_name) + 1;
2140 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2141 if (hdd_ctx->target_hw_name)
2142 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2143 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302144
2145 /* Get the wlan hw/fw version */
2146 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302147}
2148
2149/**
gbian62edd7e2017-03-07 13:12:13 +08002150 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2151 * @hdd_ctx: Pointer to hdd context
2152 *
2153 * Return: none
2154 */
2155static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002156hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002157{
2158 uint8_t num_entries = 0;
2159 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2160 uint8_t *tx_sched_wrr_ac;
2161 int i;
2162 cds_context_type *cds_ctx;
2163
2164 if (NULL == hdd_ctx)
2165 return;
2166
2167 if (NULL == hdd_ctx->config) {
2168 /* Do nothing if hdd_ctx is invalid */
2169 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2170 return;
2171 }
2172
2173 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2174
2175 if (!cds_ctx) {
2176 hdd_err("Invalid CDS Context");
2177 return;
2178 }
2179
2180 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2181 switch (i) {
2182 case OL_TX_WMM_AC_BE:
2183 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2184 break;
2185 case OL_TX_WMM_AC_BK:
2186 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2187 break;
2188 case OL_TX_WMM_AC_VI:
2189 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2190 break;
2191 case OL_TX_WMM_AC_VO:
2192 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2193 break;
2194 default:
2195 tx_sched_wrr_ac = NULL;
2196 break;
2197 }
2198
2199 hdd_string_to_u8_array(tx_sched_wrr_ac,
2200 tx_sched_wrr_param,
2201 &num_entries,
2202 sizeof(tx_sched_wrr_param));
2203
2204 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2205 cds_ctx->ac_specs[i].wrr_skip_weight =
2206 tx_sched_wrr_param[0];
2207 cds_ctx->ac_specs[i].credit_threshold =
2208 tx_sched_wrr_param[1];
2209 cds_ctx->ac_specs[i].send_limit =
2210 tx_sched_wrr_param[2];
2211 cds_ctx->ac_specs[i].credit_reserve =
2212 tx_sched_wrr_param[3];
2213 cds_ctx->ac_specs[i].discard_weight =
2214 tx_sched_wrr_param[4];
2215 }
2216
2217 num_entries = 0;
2218 }
2219}
2220
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002221#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002222static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2223 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2224{
Jeff Johnson9d295242017-08-29 14:39:48 -07002225 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002226 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002227
2228 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2229 if (!adapter) {
2230 hdd_err("Adapter is NULL");
2231 return PM_MAX_NUM_OF_MODE;
2232 }
2233
2234 return policy_mgr_convert_device_mode_to_qdf_type(
2235 adapter->device_mode);
2236}
2237
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002238static void hdd_register_policy_manager_callback(
2239 struct wlan_objmgr_psoc *psoc)
2240{
2241 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002242
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002243 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002244 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002245 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2246 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002247 hdd_cbacks.get_mode_for_non_connected_vdev =
2248 wlan_hdd_get_mode_for_non_connected_vdev;
2249
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002250 if (QDF_STATUS_SUCCESS !=
2251 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2252 hdd_err("HDD callback registration with policy manager failed");
2253 }
2254}
2255#else
2256static void hdd_register_policy_manager_callback(
2257 struct wlan_objmgr_psoc *psoc)
2258{
2259}
2260#endif
2261
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002262#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002263static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002264{
2265 struct nan_callbacks cb_obj = {0};
2266
2267 cb_obj.ndi_open = hdd_ndi_open;
2268 cb_obj.ndi_close = hdd_ndi_close;
2269 cb_obj.ndi_start = hdd_ndi_start;
2270 cb_obj.ndi_delete = hdd_ndi_delete;
2271 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2272 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2273
Naveen Rawat37f62c82017-03-26 22:24:43 -07002274 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2275 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002276 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002277
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002278 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2279}
2280#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002281static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002282{
2283}
2284#endif
2285
gbian62edd7e2017-03-07 13:12:13 +08002286/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302287 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2288 * @hdd_ctx: HDD context
2289 * @adapter: HDD adapter
2290 * @reinit: flag to indicate from SSR or normal path
2291 *
2292 * This function maintains the driver state machine it will be invoked from
2293 * startup, reinit and change interface. Depending on the driver state shall
2294 * perform the opening of the modules.
2295 *
2296 * Return: 0 for success; non-zero for failure
2297 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002298int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2299 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302300 bool reinit)
2301{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002302 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302303 qdf_device_t qdf_dev;
2304 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302305 bool unint = false;
2306 void *hif_ctx;
2307
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002308 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302309
2310 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2311 if (!qdf_dev) {
2312 hdd_err("QDF Device Context is Invalid return");
2313 return -EINVAL;
2314 }
2315
2316 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302317 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302318
2319 if (QDF_TIMER_STATE_RUNNING ==
2320 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2321
2322 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002323 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302324 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2325 }
2326
2327 switch (hdd_ctx->driver_status) {
2328 case DRIVER_MODULES_UNINITIALIZED:
2329 unint = true;
2330 /* Fall through dont add break here */
2331 case DRIVER_MODULES_CLOSED:
2332 if (!reinit && !unint) {
2333 ret = pld_power_on(qdf_dev->dev);
2334 if (ret) {
2335 hdd_err("Failed to Powerup the device: %d", ret);
2336 goto release_lock;
2337 }
2338 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002339
2340 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2341 hdd_ctx->config->enable_fw_log);
2342
Arun Khandavallifae92942016-08-01 13:31:08 +05302343 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2344 qdf_dev->bus_type,
2345 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2346 HIF_ENABLE_TYPE_PROBE);
2347 if (ret) {
2348 hdd_err("Failed to open hif: %d", ret);
2349 goto power_down;
2350 }
2351
2352 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302353 if (!hif_ctx) {
2354 hdd_err("hif context is null!!");
2355 goto power_down;
2356 }
2357
Arun Khandavallifae92942016-08-01 13:31:08 +05302358 status = ol_cds_init(qdf_dev, hif_ctx);
2359 if (status != QDF_STATUS_SUCCESS) {
2360 hdd_err("No Memory to Create BMI Context :%d", status);
2361 goto hif_close;
2362 }
2363
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002364 ret = hdd_update_config(hdd_ctx);
2365 if (ret) {
2366 hdd_err("Failed to update configuration :%d", ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002367 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002368 }
2369
gbian62edd7e2017-03-07 13:12:13 +08002370 hdd_update_cds_ac_specs_params(hdd_ctx);
2371
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302372 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302373 if (!QDF_IS_STATUS_SUCCESS(status)) {
2374 hdd_err("Failed to Open CDS: %d", status);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002375 ret = (status == QDF_STATUS_E_NOMEM) ? -ENOMEM : -EINVAL;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002376 goto cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302377 }
2378
Mukul Sharma9d797a02017-01-05 20:26:03 +05302379 /* initalize components configurations after psoc open */
2380 ret = hdd_update_components_config(hdd_ctx);
2381 if (ret) {
2382 hdd_err("Failed to update components configs :%d",
2383 ret);
2384 goto close;
2385 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002386 status = cds_dp_open(hdd_ctx->hdd_psoc);
2387 if (!QDF_IS_STATUS_SUCCESS(status)) {
2388 hdd_err("Failed to Open cds post open: %d", status);
2389 goto close;
2390 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302391
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002392 /*
2393 * NAN compoenet requires certian operations like, open adapter,
2394 * close adapter, etc. to be initiated by HDD, for those
2395 * register HDD callbacks with UMAC's NAN componenet.
2396 */
2397 hdd_nan_register_callbacks(hdd_ctx);
2398
Arun Khandavallifae92942016-08-01 13:31:08 +05302399 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2400
Jeff Johnson3a280122017-09-13 07:42:00 -07002401 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302402 if (!QDF_IS_STATUS_SUCCESS(status)) {
2403 hdd_err("Failed to pre-enable CDS: %d", status);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002404 ret = (status == QDF_STATUS_E_NOMEM) ? -ENOMEM : -EINVAL;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002405 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302406 }
2407
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002408 hdd_register_policy_manager_callback(
2409 hdd_ctx->hdd_psoc);
2410
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302411 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302412 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302413
Arun Khandavallifae92942016-08-01 13:31:08 +05302414 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2415 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2416 hdd_ftm_mc_process_msg);
2417 break;
2418 }
2419 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002420 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302421 break;
2422 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302423
2424 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002425 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2426 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002427 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002428 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302429 }
2430
Arun Khandavallifae92942016-08-01 13:31:08 +05302431 /* Fall through dont add break here */
2432 case DRIVER_MODULES_OPENED:
2433 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002434 hdd_alert("adapter is Null");
2435 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302436 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302437 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2438 hdd_err("in ftm mode, no need to configure cds modules");
2439 break;
2440 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302441 if (hdd_configure_cds(hdd_ctx, adapter)) {
2442 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002443 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302444 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302445 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302446 hdd_info("Driver Modules Successfully Enabled");
2447 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2448 break;
2449 case DRIVER_MODULES_ENABLED:
2450 hdd_info("Driver modules already Enabled");
2451 break;
2452 default:
2453 hdd_err("WLAN start invoked in wrong state! :%d\n",
2454 hdd_ctx->driver_status);
2455 goto release_lock;
2456 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302457 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302458 mutex_unlock(&hdd_ctx->iface_change_lock);
2459 EXIT();
2460 return 0;
2461
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002462post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002463 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002464
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002465cds_txrx_free:
2466 cds_dp_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302467close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002468 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002469 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302470
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002471cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302472 ol_cds_free();
2473
2474hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002475 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2476 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302477power_down:
2478 if (!reinit && !unint)
2479 pld_power_off(qdf_dev->dev);
2480release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302481 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302482 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302483 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002484
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002485 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302486}
2487
Naveen Rawat910726a2017-03-06 11:42:51 -08002488#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002489static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002490{
2491 int ret = os_if_wifi_pos_register_nl();
2492
2493 if (ret)
2494 hdd_err("os_if_wifi_pos_register_nl failed");
2495
2496 return ret;
2497}
2498
2499static int hdd_deactivate_wifi_pos(void)
2500{
2501 int ret = os_if_wifi_pos_deregister_nl();
2502
2503 if (ret)
2504 hdd_err("os_if_wifi_pos_deregister_nl failed");
2505
2506 return ret;
2507}
2508
2509/**
2510 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2511 * @hdd_ctx: hdd context
2512 *
2513 * Return: status of operation
2514 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002515static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002516{
2517 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2518 struct hdd_config *cfg = hdd_ctx->config;
2519
2520 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2521 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2522 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2523 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2524 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2525 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2526 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2527 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2528}
2529#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002530static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002531{
2532 return oem_activate_service(hdd_ctx);
2533}
2534
2535static int hdd_deactivate_wifi_pos(void)
2536{
2537 return 0;
2538}
2539
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002540static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002541{
2542}
2543#endif
2544
Arun Khandavallifae92942016-08-01 13:31:08 +05302545/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002546 * __hdd_open() - HDD Open function
2547 * @dev: Pointer to net_device structure
2548 *
2549 * This is called in response to ifconfig up
2550 *
2551 * Return: 0 for success; non-zero for failure
2552 */
2553static int __hdd_open(struct net_device *dev)
2554{
Jeff Johnson9d295242017-08-29 14:39:48 -07002555 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002556 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002557 int ret;
2558
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002559 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302560 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302561 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002562
Arunk Khandavallie1b3a382017-09-26 12:01:26 +05302563 if (!hdd_wait_for_recovery_completion()) {
2564 hdd_err("Recovery failed");
2565 return -EIO;
2566 }
2567
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302568 /* Nothing to be done if device is unloading */
2569 if (cds_is_driver_unloading()) {
2570 hdd_err("Driver is unloading can not open the hdd");
2571 return -EBUSY;
2572 }
2573
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302574 mutex_lock(&hdd_init_deinit_lock);
2575
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302576 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2577
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302578 /*
2579 * This scenario can be hit in cases where in the wlan driver after
2580 * registering the netdevices and there is a failure in driver
2581 * initialization. So return error gracefully because the netdevices
2582 * will be de-registered as part of the load failure.
2583 */
2584
2585 if (!cds_is_driver_loaded()) {
2586 hdd_err("Failed to start the wlan driver!!");
2587 ret = -EIO;
2588 goto err_hdd_hdd_init_deinit_lock;
2589 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302590
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002591
Arun Khandavallifae92942016-08-01 13:31:08 +05302592 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2593 if (ret) {
2594 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302595 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302596 }
2597
2598
2599 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2600 ret = hdd_start_adapter(adapter);
2601 if (ret) {
2602 hdd_err("Failed to start adapter :%d",
2603 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302604 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302605 }
2606 }
2607
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002608 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2609 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002610 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002611 /* Enable TX queues only when we are connected */
2612 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302613 WLAN_START_ALL_NETIF_QUEUE,
2614 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002615 }
2616
Naveen Rawat286def52016-09-23 15:38:02 -07002617 /* Enable carrier and transmit queues for NDI */
2618 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002619 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002620 wlan_hdd_netif_queue_control(adapter,
2621 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2622 WLAN_CONTROL_PATH);
2623 }
2624
Naveen Rawat910726a2017-03-06 11:42:51 -08002625 hdd_populate_wifi_pos_cfg(hdd_ctx);
2626
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302627err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302628 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302629 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002630 return ret;
2631}
2632
Arun Khandavallifae92942016-08-01 13:31:08 +05302633
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002634/**
2635 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2636 * @dev: Pointer to net_device structure
2637 *
2638 * This is called in response to ifconfig up
2639 *
2640 * Return: 0 for success; non-zero for failure
2641 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002642static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002643{
2644 int ret;
2645
2646 cds_ssr_protect(__func__);
2647 ret = __hdd_open(dev);
2648 cds_ssr_unprotect(__func__);
2649
2650 return ret;
2651}
2652
2653/**
2654 * __hdd_stop() - HDD stop function
2655 * @dev: Pointer to net_device structure
2656 *
2657 * This is called in response to ifconfig down
2658 *
2659 * Return: 0 for success; non-zero for failure
2660 */
2661static int __hdd_stop(struct net_device *dev)
2662{
Jeff Johnson9d295242017-08-29 14:39:48 -07002663 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002664 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002665 int ret;
2666
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002667 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002668
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302669 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002670 adapter->sessionId, adapter->device_mode));
2671
2672 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302673 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002674 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002675
2676 /* Nothing to be done if the interface is not opened */
2677 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002678 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002679 return -ENODEV;
2680 }
2681
2682 /* Make sure the interface is marked as closed */
2683 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302684
2685 hdd_debug("Disabling Auto Power save timer");
2686 sme_ps_disable_auto_ps_timer(
2687 WLAN_HDD_GET_HAL_CTX(adapter),
2688 adapter->sessionId);
2689
2690 /*
2691 * Disable TX on the interface, after this hard_start_xmit() will not
2692 * be called on that interface
2693 */
2694 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302695 wlan_hdd_netif_queue_control(adapter,
2696 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2697 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002698
2699 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002700 * NAN data interface is different in some sense. The traffic on NDI is
2701 * bursty in nature and depends on the need to transfer. The service
2702 * layer may down the interface after the usage and up again when
2703 * required. In some sense, the NDI is expected to be available
2704 * (like SAP) iface until NDI delete request is issued by the service
2705 * layer. Skip BSS termination and adapter deletion for NAN Data
2706 * interface (NDI).
2707 */
2708 if (WLAN_HDD_IS_NDI(adapter))
2709 return 0;
2710
2711 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002712 * The interface is marked as down for outside world (aka kernel)
2713 * But the driver is pretty much alive inside. The driver needs to
2714 * tear down the existing connection on the netdev (session)
2715 * cleanup the data pipes and wait until the control plane is stabilized
2716 * for this interface. The call also needs to wait until the above
2717 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002718 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002719 * That is intentional to be able to scan if it is a STA/P2P interface
2720 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302721 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002722
2723 /* DeInit the adapter. This ensures datapath cleanup as well */
2724 hdd_deinit_adapter(hdd_ctx, adapter, true);
2725
Arun Khandavallifae92942016-08-01 13:31:08 +05302726
2727 /*
2728 * Find if any iface is up. If any iface is up then can't put device to
2729 * sleep/power save mode
2730 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302731 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002732 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302733 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302734 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302735 hdd_prevent_suspend_timeout(
2736 hdd_ctx->config->iface_change_wait_time,
2737 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302738 }
2739
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740 EXIT();
2741 return 0;
2742}
2743
2744/**
2745 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2746 * @dev: pointer to net_device structure
2747 *
2748 * This is called in response to ifconfig down
2749 *
2750 * Return: 0 for success and error number for failure
2751 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002752static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002753{
2754 int ret;
2755
2756 cds_ssr_protect(__func__);
2757 ret = __hdd_stop(dev);
2758 cds_ssr_unprotect(__func__);
2759
2760 return ret;
2761}
2762
2763/**
2764 * __hdd_uninit() - HDD uninit function
2765 * @dev: Pointer to net_device structure
2766 *
2767 * This is called during the netdev unregister to uninitialize all data
2768 * associated with the device
2769 *
2770 * Return: None
2771 */
2772static void __hdd_uninit(struct net_device *dev)
2773{
Jeff Johnson9d295242017-08-29 14:39:48 -07002774 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002775 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002776
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002777 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002778
2779 do {
2780 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002781 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002782 break;
2783 }
2784
Jeff Johnson399c6272017-08-30 10:51:00 -07002785 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2786 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002787 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002788 break;
2789 }
2790
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002791 if (dev != adapter->dev)
2792 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002793
Jeff Johnson399c6272017-08-30 10:51:00 -07002794 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002795
2796 /* after uninit our adapter structure will no longer be valid */
2797 adapter->dev = NULL;
2798 adapter->magic = 0;
2799 } while (0);
2800
2801 EXIT();
2802}
2803
2804/**
2805 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2806 * @dev: pointer to net_device structure
2807 *
2808 * This is called during the netdev unregister to uninitialize all data
2809 * associated with the device
2810 *
2811 * Return: none
2812 */
2813static void hdd_uninit(struct net_device *dev)
2814{
2815 cds_ssr_protect(__func__);
2816 __hdd_uninit(dev);
2817 cds_ssr_unprotect(__func__);
2818}
2819
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002820static int hdd_open_cesium_nl_sock(void)
2821{
2822#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2823 struct netlink_kernel_cfg cfg = {
2824 .groups = WLAN_NLINK_MCAST_GRP_ID,
2825 .input = NULL
2826 };
2827#endif
2828 int ret = 0;
2829
2830#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2831 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2832#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2833 THIS_MODULE,
2834#endif
2835 &cfg);
2836#else
2837 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2838 WLAN_NLINK_MCAST_GRP_ID,
2839 NULL, NULL, THIS_MODULE);
2840#endif
2841
2842 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002843 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002844 ret = -ECONNREFUSED;
2845 }
2846
2847 return ret;
2848}
2849
2850static void hdd_close_cesium_nl_sock(void)
2851{
2852 if (NULL != cesium_nl_srv_sock) {
2853 netlink_kernel_release(cesium_nl_srv_sock);
2854 cesium_nl_srv_sock = NULL;
2855 }
2856}
2857
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002858/**
2859 * __hdd_set_mac_address() - set the user specified mac address
2860 * @dev: Pointer to the net device.
2861 * @addr: Pointer to the sockaddr.
2862 *
2863 * This function sets the user specified mac address using
2864 * the command ifconfig wlanX hw ether <mac adress>.
2865 *
2866 * Return: 0 for success, non zero for failure
2867 */
2868static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2869{
Jeff Johnson9d295242017-08-29 14:39:48 -07002870 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002871 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002872 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302873 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002874 int ret;
2875
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002876 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002877
2878 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2879 ret = wlan_hdd_validate_context(hdd_ctx);
2880 if (0 != ret)
2881 return ret;
2882
2883 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2884 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2885
2886 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302887 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002888}
2889
2890/**
2891 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2892 * function from SSR
2893 * @dev: pointer to net_device structure
2894 * @addr: Pointer to the sockaddr
2895 *
2896 * This function sets the user specified mac address using
2897 * the command ifconfig wlanX hw ether <mac adress>.
2898 *
2899 * Return: 0 for success.
2900 */
2901static int hdd_set_mac_address(struct net_device *dev, void *addr)
2902{
2903 int ret;
2904
2905 cds_ssr_protect(__func__);
2906 ret = __hdd_set_mac_address(dev, addr);
2907 cds_ssr_unprotect(__func__);
2908
2909 return ret;
2910}
2911
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002912uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002913{
2914 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002915
Anurag Chouhan6d760662016-02-20 16:05:43 +05302916 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002917 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2918 break;
2919 }
2920
Anurag Chouhan6d760662016-02-20 16:05:43 +05302921 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002922 return NULL;
2923
2924 hdd_ctx->config->intfAddrMask |= (1 << i);
2925 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2926}
2927
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07002928void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
2929 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002930{
2931 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002932
Anurag Chouhan6d760662016-02-20 16:05:43 +05302933 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002934 if (!memcmp(releaseAddr,
2935 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2936 6)) {
2937 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2938 break;
2939 }
2940 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002941}
2942
2943#ifdef WLAN_FEATURE_PACKET_FILTERING
2944/**
2945 * __hdd_set_multicast_list() - set the multicast address list
2946 * @dev: Pointer to the WLAN device.
2947 * @skb: Pointer to OS packet (sk_buff).
2948 *
2949 * This funciton sets the multicast address list.
2950 *
2951 * Return: None
2952 */
2953static void __hdd_set_multicast_list(struct net_device *dev)
2954{
Jeff Johnson9d295242017-08-29 14:39:48 -07002955 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002956 int i = 0, status;
2957 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002958 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302959 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2960 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2961 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002962
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002963 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302964 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302965 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302966
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002967 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302968 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302969 goto out;
2970
Dustin Brownc788acb2017-08-01 17:43:51 -07002971 status = hdd_validate_adapter(adapter);
2972 if (status)
2973 goto out;
2974
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302975 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2976 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002977 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302978 goto out;
2979 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002980
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302981 /* Delete already configured multicast address list */
2982 if (adapter->mc_addr_list.mc_cnt > 0) {
2983 hdd_info("clear previously configured MC address list");
2984 hdd_disable_and_flush_mc_addr_list(adapter,
2985 pmo_mc_list_change_notify);
2986 }
2987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002988 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002989 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302990 hdd_disable_and_flush_mc_addr_list(adapter,
2991 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 } else {
2993 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302994 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002995 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302996 pmo_ucfg_max_mc_addr_supported(psoc));
2997 hdd_disable_and_flush_mc_addr_list(adapter,
2998 pmo_mc_list_change_notify);
2999 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003000 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003001 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003002 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303003 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003004 if (i == mc_count)
3005 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303006 memset(&(mc_list_request->mc_addr[i].bytes),
3007 0, ETH_ALEN);
3008 memcpy(&(mc_list_request->mc_addr[i].bytes),
3009 ha->addr, ETH_ALEN);
3010 hdd_info("mlist[%d] = %pM", i,
3011 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003012 i++;
3013 }
3014 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303015
3016 mc_list_request->psoc = psoc;
3017 mc_list_request->vdev_id = adapter->sessionId;
3018 mc_list_request->count = mc_count;
3019 status = hdd_cache_mc_addr_list(mc_list_request);
3020 if (status == 0) {
3021 hdd_enable_mc_addr_filtering(adapter,
3022 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003023 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303024 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003025 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303026out:
3027 if (mc_list_request)
3028 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303029 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003030}
3031
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303032
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003033/**
3034 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3035 * @dev: pointer to net_device
3036 *
3037 * Return: none
3038 */
3039static void hdd_set_multicast_list(struct net_device *dev)
3040{
3041 cds_ssr_protect(__func__);
3042 __hdd_set_multicast_list(dev);
3043 cds_ssr_unprotect(__func__);
3044}
3045#endif
3046
3047/**
3048 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3049 * @dev: Pointer to the WLAN device.
3050 * @skb: Pointer to OS packet (sk_buff).
3051 *
3052 * This function is registered with the Linux OS for network
3053 * core to decide which queue to use first.
3054 *
3055 * Return: ac, Queue Index/access category corresponding to UP in IP header
3056 */
3057static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3058#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3059 , void *accel_priv
3060#endif
3061#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3062 , select_queue_fallback_t fallback
3063#endif
3064)
3065{
3066 return hdd_wmm_select_queue(dev, skb);
3067}
3068
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003069static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003070 .ndo_open = hdd_open,
3071 .ndo_stop = hdd_stop,
3072 .ndo_uninit = hdd_uninit,
3073 .ndo_start_xmit = hdd_hard_start_xmit,
3074 .ndo_tx_timeout = hdd_tx_timeout,
3075 .ndo_get_stats = hdd_get_stats,
3076 .ndo_do_ioctl = hdd_ioctl,
3077 .ndo_set_mac_address = hdd_set_mac_address,
3078 .ndo_select_queue = hdd_select_queue,
3079#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003080 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003081#endif
3082};
3083
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003084/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003085static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003086 .ndo_open = hdd_mon_open,
3087 .ndo_stop = hdd_stop,
3088 .ndo_get_stats = hdd_get_stats,
3089};
3090
3091/**
3092 * hdd_set_station_ops() - update net_device ops for monitor mode
3093 * @pWlanDev: Handle to struct net_device to be updated.
3094 * Return: None
3095 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003096void hdd_set_station_ops(struct net_device *pWlanDev)
3097{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003098 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
3099 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
3100 else
3101 pWlanDev->netdev_ops = &wlan_drv_ops;
3102}
3103
3104/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003105 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3106 * @hdd_ctx: global hdd context
3107 * @macAddr: mac address to assign to the interface
3108 * @name: User-visible name of the interface
3109 *
3110 * hdd adapter pointer would point to the netdev->priv space, this function
3111 * would retrive the pointer, and setup the hdd adapter configuration.
3112 *
3113 * Return: the pointer to hdd adapter, otherwise NULL
3114 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003115static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003116 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003117 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003118 const char *name)
3119{
3120 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003121 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003122 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003123 /*
3124 * cfg80211 initialization and registration....
3125 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003126 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003127#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3128 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003129#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003130 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3131 hdd_mon_mode_ether_setup : ether_setup),
3132 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133
3134 if (pWlanDev != NULL) {
3135
3136 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003137 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138
Jeff Johnson9d295242017-08-29 14:39:48 -07003139 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303140 sta_ctx = &adapter->sessionCtx.station;
3141 qdf_mem_set(sta_ctx->conn_info.staId,
3142 sizeof(sta_ctx->conn_info.staId),
3143 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003144 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003145 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003146 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303147 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148
3149 init_completion(&adapter->session_open_comp_var);
3150 init_completion(&adapter->session_close_comp_var);
3151 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303152 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153 init_completion(&adapter->linkup_event_var);
3154 init_completion(&adapter->cancel_rem_on_chan_var);
3155 init_completion(&adapter->rem_on_chan_ready_event);
3156 init_completion(&adapter->sta_authorized_event);
3157 init_completion(&adapter->offchannel_tx_event);
3158 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003159 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003160 init_completion(&adapter->change_country_code);
3161
3162
3163 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303164 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003165
3166 adapter->offloads_configured = false;
3167 adapter->isLinkUpSvcNeeded = false;
3168 adapter->higherDtimTransition = true;
3169 /* Init the net_device structure */
3170 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3171
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303172 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303174 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003175 sizeof(tSirMacAddr));
3176 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177
3178 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3179 pWlanDev->features |=
3180 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3181 pWlanDev->features |= NETIF_F_RXCSUM;
3182
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003183 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003185 hdd_set_station_ops(adapter->dev);
3186
Dustin Brownc81dd412017-08-15 16:26:28 -07003187 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003189 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190 adapter->wdev.wiphy = hdd_ctx->wiphy;
3191 adapter->wdev.netdev = pWlanDev;
3192 /* set pWlanDev's parent to underlying device */
3193 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3194 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303195 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003196 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303197 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198 }
3199
3200 return adapter;
3201}
3202
Jeff Johnson9d295242017-08-29 14:39:48 -07003203static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003205 struct net_device *dev = adapter->dev;
3206 int ret;
3207
3208 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003209
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003210 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003211 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3212
3213 ret = dev_alloc_name(dev, dev->name);
3214 if (ret < 0) {
3215 hdd_err(
3216 "unable to get dev name: %s, err = 0x%x",
3217 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303218 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003219 }
3220 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003221
3222 ret = register_netdevice(dev);
3223 if (ret) {
3224 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3225 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303226 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003227 }
3228 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003229 ret = register_netdev(dev);
3230 if (ret) {
3231 hdd_err("register_netdev(%s) failed, err = 0x%x",
3232 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303233 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003234 }
3235 }
3236 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3237
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003238 EXIT();
3239
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303240 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241}
3242
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003243QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244{
Jeff Johnson9d295242017-08-29 14:39:48 -07003245 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003246
3247 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003248 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303249 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250 }
3251
3252 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003253 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303254 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003255 }
3256
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003257 /*
3258 * For NAN Data interface, the close session results in the final
3259 * indication to the userspace
3260 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003261 if (adapter->device_mode == QDF_NDI_MODE)
3262 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003263
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3265
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003266 /*
3267 * We can be blocked while waiting for scheduled work to be
3268 * flushed, and the adapter structure can potentially be freed, in
3269 * which case the magic will have been reset. So make sure the
3270 * magic is still good, and hence the adapter structure is still
3271 * valid, before signaling completion
3272 */
3273 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3274 complete(&adapter->session_close_comp_var);
3275
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303276 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003277}
3278
Jeff Johnson9d295242017-08-29 14:39:48 -07003279int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003280{
Dustin Brownd28772b2017-03-17 14:16:07 -07003281 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003282
Dustin Brownd28772b2017-03-17 14:16:07 -07003283 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003284 if (QDF_IS_STATUS_ERROR(status))
3285 return qdf_status_to_os_return(status);
3286
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003287 status = ucfg_reg_11d_vdev_created_update(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
3291 if (wma_capability_enhanced_mcast_filter())
3292 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3293 else
3294 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003295
3296 return qdf_status_to_os_return(status);
3297}
3298
Jeff Johnson9d295242017-08-29 14:39:48 -07003299int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003300{
3301 QDF_STATUS status;
3302 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003303 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003304 unsigned long rc;
3305
3306 hdd_info("destroying vdev %d", adapter->sessionId);
3307
3308 /* vdev created sanity check */
3309 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3310 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3311 return -EINVAL;
3312 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003313 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003314 /*
3315 * In SSR case, there is no need to destroy vdev in firmware since
3316 * it has already asserted. vdev can be released directly.
3317 */
3318 if (cds_is_driver_recovering())
3319 goto release_vdev;
3320
Dustin Brownd28772b2017-03-17 14:16:07 -07003321 /* close sme session (destroy vdev in firmware via legacy API) */
3322 INIT_COMPLETION(adapter->session_close_comp_var);
3323 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3324 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3325 hdd_sme_close_session_callback, adapter);
3326 if (QDF_IS_STATUS_ERROR(status)) {
3327 hdd_err("failed to close sme session: %d", status);
3328 return qdf_status_to_os_return(status);
3329 }
3330
3331 /* block on a completion variable until sme session is closed */
3332 rc = wait_for_completion_timeout(
3333 &adapter->session_close_comp_var,
3334 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3335 if (!rc) {
3336 hdd_err("timed out waiting for close sme session: %ld", rc);
3337 if (adapter->device_mode == QDF_NDI_MODE)
3338 hdd_ndp_session_end_handler(adapter);
3339 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3340 return -ETIMEDOUT;
3341 }
Yue Maf9782842017-05-08 12:49:49 -07003342release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003343 /* do vdev logical destroy via objmgr */
3344 errno = hdd_objmgr_destroy_vdev(adapter);
3345 if (errno) {
3346 hdd_err("failed to destroy objmgr vdev: %d", errno);
3347 return errno;
3348 }
3349
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003350 /* now that sme session is closed, allow physical vdev destroy */
3351 errno = hdd_objmgr_release_vdev(adapter);
3352 if (errno) {
3353 hdd_err("failed to release objmgr vdev: %d", errno);
3354 return errno;
3355 }
3356
Dustin Brownd28772b2017-03-17 14:16:07 -07003357 hdd_info("vdev destroyed successfully");
3358
3359 return 0;
3360}
3361
Jeff Johnson9d295242017-08-29 14:39:48 -07003362int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003363{
3364 QDF_STATUS status;
3365 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003366 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003367 uint32_t type;
3368 uint32_t sub_type;
3369 unsigned long rc;
3370
3371 hdd_info("creating new vdev");
3372
3373 /* determine vdev (sub)type */
3374 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303375 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003376 hdd_err("failed to get vdev type: %d", status);
3377 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003378 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003379
3380 /* do vdev create via objmgr */
3381 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003382 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003383 if (errno) {
3384 hdd_err("failed to create objmgr vdev: %d", errno);
3385 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003386 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003387
3388 /* Open a SME session (prepare vdev in firmware via legacy API) */
3389 INIT_COMPLETION(adapter->session_open_comp_var);
3390 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3391 (uint8_t *)&adapter->macAddressCurrent,
3392 adapter->sessionId, type, sub_type);
3393 if (QDF_IS_STATUS_ERROR(status)) {
3394 hdd_err("failed to open sme session: %d", status);
3395 errno = qdf_status_to_os_return(status);
3396 goto objmgr_vdev_destroy;
3397 }
3398
3399 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003400 rc = wait_for_completion_timeout(
3401 &adapter->session_open_comp_var,
3402 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3403 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003404 hdd_err("timed out waiting for open sme session: %ld", rc);
3405 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303406 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3407 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003408 }
3409
3410 /* firmware ready for component communication, raise vdev_ready event */
3411 errno = hdd_vdev_ready(adapter);
3412 if (errno) {
3413 hdd_err("failed to dispatch vdev ready event: %d", errno);
3414 goto hdd_vdev_destroy;
3415 }
3416
3417 hdd_info("vdev %d created successfully", adapter->sessionId);
3418
3419 return 0;
3420
3421 /*
3422 * Due to legacy constraints, we need to destroy in the same order as
3423 * create. So, split error handling into 2 cases to accommodate.
3424 */
3425
3426objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003427 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003428
3429 return errno;
3430
3431hdd_vdev_destroy:
3432 QDF_BUG(!hdd_vdev_destroy(adapter));
3433
3434 return errno;
3435}
3436
Jeff Johnson9d295242017-08-29 14:39:48 -07003437QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003438{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003439 struct hdd_station_ctx *sta_ctx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003440 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003441 QDF_STATUS status;
3442 int ret_val;
3443
3444 ret_val = hdd_vdev_create(adapter);
3445 if (ret_val) {
3446 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303447 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003448 }
3449
Dustin Brownd28772b2017-03-17 14:16:07 -07003450 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3451 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3452 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003453 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003454
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003455 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003456 status = hdd_register_wext(adapter->dev);
3457 if (QDF_IS_STATUS_ERROR(status)) {
3458 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003459 goto error_register_wext;
3460 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003461 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462
Jeff Johnsond377dce2017-10-04 10:32:42 -07003463 qdf_mem_set(sta_ctx->conn_info.staId,
3464 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303465
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003466 /* set fast roaming capability in sme session */
3467 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3468 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003470 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471 hdd_ctx->config->OperatingChannel;
3472
3473 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003474 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475
3476 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303477 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003478 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 status, status);
3480 goto error_init_txrx;
3481 }
3482
3483 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3484
3485 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303486 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003487 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488 status, status);
3489 goto error_wmm_init;
3490 }
3491
3492 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3493
Naveen Rawat247a8682017-06-05 15:00:31 -07003494 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003495 WMI_PDEV_PARAM_BURST_ENABLE,
3496 hdd_ctx->config->enableSifsBurst,
3497 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003498 if (ret_val)
3499 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003501 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303502 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504error_wmm_init:
3505 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3506 hdd_deinit_tx_rx(adapter);
3507error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003508 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003509error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003510 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003511
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003512 return status;
3513}
3514
Jeff Johnson9d295242017-08-29 14:39:48 -07003515void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516{
Wu Gao02bd75b2017-10-13 18:34:02 +08003517 hdd_debug("Cleanup action frame");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518}
3519
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303520/**
3521 * hdd_station_adapter_deinit() - De-initialize the station adapter
3522 * @hdd_ctx: global hdd context
3523 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003524 * @rtnl_held: Used to indicate whether or not the caller is holding
3525 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303526 *
3527 * This function De-initializes the STA/P2P/OCB adapter.
3528 *
3529 * Return: None.
3530 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003531static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003532 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003533 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303534{
3535 ENTER_DEV(adapter->dev);
3536
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303537 if (adapter->dev) {
3538 if (rtnl_held)
3539 adapter->dev->wireless_handlers = NULL;
3540 else {
3541 rtnl_lock();
3542 adapter->dev->wireless_handlers = NULL;
3543 rtnl_unlock();
3544 }
3545 }
3546
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303547 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3548 hdd_deinit_tx_rx(adapter);
3549 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3550 }
3551
3552 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3553 hdd_wmm_adapter_close(adapter);
3554 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3555 }
3556
3557 hdd_cleanup_actionframe(hdd_ctx, adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303558
3559 EXIT();
3560}
3561
3562/**
3563 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3564 * @hdd_ctx: global hdd context
3565 * @adapter: HDD adapter
3566 * @rtnl_held: the rtnl lock hold flag
3567 * This function De-initializes the AP/P2PGo adapter.
3568 *
3569 * Return: None.
3570 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003571static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003572 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003573 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303574{
3575 ENTER_DEV(adapter->dev);
3576
3577 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3578 hdd_wmm_adapter_close(adapter);
3579 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3580 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003581 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303582
3583 hdd_cleanup_actionframe(hdd_ctx, adapter);
3584
3585 hdd_unregister_hostapd(adapter, rtnl_held);
3586
3587 EXIT();
3588}
3589
Jeff Johnson9d295242017-08-29 14:39:48 -07003590void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591 bool rtnl_held)
3592{
3593 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303594
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003595 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003596 case QDF_STA_MODE:
3597 case QDF_P2P_CLIENT_MODE:
3598 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303600 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003601 break;
3602 }
3603
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003604 case QDF_SAP_MODE:
3605 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003606 {
3607
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303608 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609 break;
3610 }
3611
3612 default:
3613 break;
3614 }
3615
3616 EXIT();
3617}
3618
Jeff Johnson9d295242017-08-29 14:39:48 -07003619static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003620 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003621{
3622 struct net_device *pWlanDev = NULL;
3623
3624 if (adapter)
3625 pWlanDev = adapter->dev;
3626 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003627 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628 return;
3629 }
3630
Rajeev Kumardca5f812016-02-04 17:28:06 -08003631 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303632
3633 if (adapter->scan_info.default_scan_ies) {
3634 qdf_mem_free(adapter->scan_info.default_scan_ies);
3635 adapter->scan_info.default_scan_ies = NULL;
3636 }
3637
Komal Seelama89be8d2016-09-29 11:09:26 +05303638 hdd_adapter_runtime_suspend_denit(adapter);
3639
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003640 /*
3641 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3642 * the driver is almost closed and cannot handle either control
3643 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003644 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3645 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003646 * is not right. Setting this flag helps hdd_stop() to recognize that
3647 * the interface is closed and restricts any operations on that
3648 */
3649 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3650
3651 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003652 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003654 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656 /*
3657 * Note that the adapter is no longer valid at this point
3658 * since the memory has been reclaimed
3659 */
3660 }
3661}
3662
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003663static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003664 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665{
3666 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003667 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303668 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003669
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003670 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303671 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003672 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003673 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303674 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003675 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303676 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677 }
3678 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3679 adapterNode = pNext;
3680 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303681 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003682}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003683
Arun Khandavalli2358d522016-05-16 18:05:37 +05303684#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3685/**
3686 * hdd_set_fw_log_params() - Set log parameters to FW
3687 * @hdd_ctx: HDD Context
3688 * @adapter: HDD Adapter
3689 *
3690 * This function set the FW Debug log level based on the INI.
3691 *
3692 * Return: None
3693 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003694static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003695 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303696{
3697 uint8_t count = 0, numentries = 0,
3698 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3699 uint32_t value = 0;
3700 int ret;
3701
Arun Khandavallifae92942016-08-01 13:31:08 +05303702 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3703 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003704 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303705 return;
3706 }
3707
Arun Khandavallifae92942016-08-01 13:31:08 +05303708 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303709 hdd_ctx->fw_log_settings.dl_type =
3710 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003711 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303712 WMI_DBGLOG_TYPE,
3713 hdd_ctx->config->enableFwLogType,
3714 DBG_CMD);
3715 if (ret != 0)
3716 hdd_err("Failed to enable FW log type ret %d",
3717 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303718
3719 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303720 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003721 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303722 WMI_DBGLOG_LOG_LEVEL,
3723 hdd_ctx->config->enableFwLogLevel,
3724 DBG_CMD);
3725 if (ret != 0)
3726 hdd_err("Failed to enable FW log level ret %d",
3727 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303728
3729 hdd_string_to_u8_array(
3730 hdd_ctx->config->enableFwModuleLogLevel,
3731 moduleloglevel,
3732 &numentries,
3733 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3734
3735 while (count < numentries) {
3736 /*
3737 * FW module log level input string looks like
3738 * below:
3739 * gFwDebugModuleLoglevel=<FW Module ID>,
3740 * <Log Level>,...
3741 * For example:
3742 * gFwDebugModuleLoglevel=
3743 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3744 * Above input string means :
3745 * For FW module ID 1 enable log level 0
3746 * For FW module ID 2 enable log level 1
3747 * For FW module ID 3 enable log level 2
3748 * For FW module ID 4 enable log level 3
3749 * For FW module ID 5 enable log level 4
3750 * For FW module ID 6 enable log level 5
3751 * For FW module ID 7 enable log level 6
3752 */
3753
Nishank Aggarwale239d962017-03-03 12:26:02 +05303754 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3755 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3756 hdd_err("Module id %d and dbglog level %d input length is more than max",
3757 moduleloglevel[count],
3758 moduleloglevel[count + 1]);
3759 return;
3760 }
3761
3762 value = moduleloglevel[count] << 16;
3763 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003764 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303765 WMI_DBGLOG_MOD_LOG_LEVEL,
3766 value, DBG_CMD);
3767 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303768 hdd_err("Failed to enable FW module log level %d ret %d",
3769 value, ret);
3770
3771 count += 2;
3772 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303773
Arun Khandavalli2358d522016-05-16 18:05:37 +05303774}
3775#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003776static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003777 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303778{
3779}
3780
3781#endif
3782
3783/**
3784 * hdd_set_fw_params() - Set parameters to firmware
3785 * @adapter: HDD adapter
3786 *
3787 * This function Sets various parameters to fw once the
3788 * adapter is started.
3789 *
3790 * Return: 0 on success or errno on failure
3791 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003792int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303793{
3794 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003795 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303796
3797 ENTER_DEV(adapter->dev);
3798
3799 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3800 if (!hdd_ctx)
3801 return -EINVAL;
3802
Dustin Brown732ab9c2017-06-15 13:24:09 -07003803 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3804 hdd_debug("FTM Mode is active; nothing to do");
3805 return 0;
3806 }
3807
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303808 ret = sme_cli_set_command(adapter->sessionId,
3809 WMI_PDEV_PARAM_DTIM_SYNTH,
3810 hdd_ctx->config->enable_lprx, PDEV_CMD);
3811 if (ret) {
3812 hdd_err("Failed to set LPRx");
3813 goto error;
3814 }
3815
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303816 if (adapter->device_mode == QDF_STA_MODE) {
3817 sme_set_smps_cfg(adapter->sessionId,
3818 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3819 hdd_ctx->config->upper_brssi_thresh);
3820
3821 sme_set_smps_cfg(adapter->sessionId,
3822 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3823 hdd_ctx->config->lower_brssi_thresh);
3824
3825 sme_set_smps_cfg(adapter->sessionId,
3826 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3827 hdd_ctx->config->enable_dtim_1chrx);
3828 }
3829
Dustin Brown732ab9c2017-06-15 13:24:09 -07003830 if (hdd_ctx->config->enable2x2) {
3831 hdd_debug("configuring 2x2 mode fw params");
3832
Naveen Rawat247a8682017-06-05 15:00:31 -07003833 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003834 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3835 hdd_ctx->config->enable_cck_tx_fir_override,
3836 PDEV_CMD);
3837 if (ret) {
3838 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3839 ret);
3840 goto error;
3841 }
3842 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303843#define HDD_DTIM_1CHAIN_RX_ID 0x5
3844#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003845 hdd_debug("configuring 1x1 mode fw params");
3846
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003847 /*
3848 * Disable DTIM 1 chain Rx when in 1x1,
3849 * we are passing two value
3850 * as param_id << 29 | param_value.
3851 * Below param_value = 0(disable)
3852 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003853 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003854 WMI_STA_SMPS_PARAM_CMDID,
3855 HDD_DTIM_1CHAIN_RX_ID <<
3856 HDD_SMPS_PARAM_VALUE_S,
3857 VDEV_CMD);
3858 if (ret) {
3859 hdd_err("DTIM 1 chain set failed %d", ret);
3860 goto error;
3861 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303862
Naveen Rawat247a8682017-06-05 15:00:31 -07003863 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003864 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3865 hdd_ctx->config->txchainmask1x1,
3866 PDEV_CMD);
3867 if (ret) {
3868 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3869 ret);
3870 goto error;
3871 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303872
Naveen Rawat247a8682017-06-05 15:00:31 -07003873 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003874 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3875 hdd_ctx->config->rxchainmask1x1,
3876 PDEV_CMD);
3877 if (ret) {
3878 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3879 ret);
3880 goto error;
3881 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303882#undef HDD_DTIM_1CHAIN_RX_ID
3883#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003884 }
3885
Naveen Rawat247a8682017-06-05 15:00:31 -07003886 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003887 WMI_PDEV_PARAM_HYST_EN,
3888 hdd_ctx->config->enableMemDeepSleep,
3889 PDEV_CMD);
3890 if (ret) {
3891 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3892 goto error;
3893 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303894
Naveen Rawat247a8682017-06-05 15:00:31 -07003895 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003896 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3897 hdd_ctx->config->rts_profile,
3898 VDEV_CMD);
3899 if (ret) {
3900 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3901 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303902 }
3903
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003904 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3905
3906 ret = wma_cli_set_command(adapter->sessionId,
3907 GEN_VDEV_PARAM_AMSDU,
3908 hdd_ctx->config->max_amsdu_num,
3909 GEN_CMD);
3910 if (ret != 0) {
3911 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3912 goto error;
3913 }
3914
Arun Khandavalli2358d522016-05-16 18:05:37 +05303915 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303916 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003917
Arun Khandavalli2358d522016-05-16 18:05:37 +05303918 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303919
Arun Khandavalli2358d522016-05-16 18:05:37 +05303920error:
3921 return -EINVAL;
3922}
3923
Ryan Hsu07495ea2016-01-21 15:25:39 -08003924/**
3925 * hdd_open_adapter() - open and setup the hdd adatper
3926 * @hdd_ctx: global hdd context
3927 * @session_type: type of the interface to be created
3928 * @iface_name: User-visible name of the interface
3929 * @macAddr: MAC address to assign to the interface
3930 * @name_assign_type: the name of assign type of the netdev
3931 * @rtnl_held: the rtnl lock hold flag
3932 *
3933 * This function open and setup the hdd adpater according to the device
3934 * type request, assign the name, the mac address assigned, and then prepared
3935 * the hdd related parameters, queue, lock and ready to start.
3936 *
3937 * Return: the pointer of hdd adapter, otherwise NULL.
3938 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003939struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003940 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003941 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003942 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943{
Jeff Johnson9d295242017-08-29 14:39:48 -07003944 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303946 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Jeff Johnson5e4b93c2017-09-30 18:09:16 -07003947 struct hdd_cfg80211_state *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949
3950 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3951 /*
3952 * Max limit reached on the number of vdevs configured by the
3953 * host. Return error
3954 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303955 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3956 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957 return NULL;
3958 }
3959
3960 if (macAddr == NULL) {
3961 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303962 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003963 return NULL;
3964 }
3965 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303966 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303967 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3968 " already exists",
3969 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970 return NULL;
3971 }
3972
3973 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003974 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003975 /* Reset locally administered bit if the device mode is STA */
3976 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303977 hdd_info("locally administered bit reset in sta mode: "
3978 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003980 case QDF_P2P_CLIENT_MODE:
3981 case QDF_P2P_DEVICE_MODE:
3982 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003983 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303984 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003985 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3986 name_assign_type,
3987 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003988
3989 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303990 hdd_err("failed to allocate adapter for session %d",
3991 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992 return NULL;
3993 }
3994
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003995 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003997 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303999 else if (QDF_MONITOR_MODE == session_type)
4000 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 else
4002 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4003
4004 adapter->device_mode = session_type;
4005
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004007 /*
4008 * Workqueue which gets scheduled in IPv4 notification
4009 * callback
4010 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004011 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4012 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013
4014#ifdef WLAN_NS_OFFLOAD
4015 /*
4016 * Workqueue which gets scheduled in IPv6
4017 * notification callback.
4018 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4020 hdd_ipv6_notifier_work_queue);
4021#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004022 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304023 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304025 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004026 }
4027
4028 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004029 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304031 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4032 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304033
Ravi Joshi1a292562017-05-18 16:28:54 -07004034 /* Initialize NAN Data Interface */
4035 if (QDF_NDI_MODE == session_type) {
4036 status = hdd_init_nan_data_mode(adapter);
4037 if (QDF_STATUS_SUCCESS != status)
4038 goto err_free_netdev;
4039 }
4040
4041 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004042
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004043 case QDF_P2P_GO_MODE:
4044 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004045 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4046 name_assign_type,
4047 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004048 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004049 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304050 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004051 return NULL;
4052 }
4053
4054 adapter->wdev.iftype =
4055 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004056 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004057 NL80211_IFTYPE_P2P_GO;
4058 adapter->device_mode = session_type;
4059
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004060 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304061 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004062 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4063 goto err_free_netdev;
4064 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004065 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304067 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4068 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304069
4070 /*
4071 * Workqueue which gets scheduled in IPv4 notification
4072 * callback
4073 */
4074 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4075 hdd_ipv4_notifier_work_queue);
4076
4077#ifdef WLAN_NS_OFFLOAD
4078 /*
4079 * Workqueue which gets scheduled in IPv6
4080 * notification callback.
4081 */
4082 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4083 hdd_ipv6_notifier_work_queue);
4084#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004085 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304086 case QDF_FTM_MODE:
4087 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4088 name_assign_type,
4089 "wlan0");
4090 if (NULL == adapter) {
4091 hdd_err("Failed to allocate adapter for FTM mode");
4092 return NULL;
4093 }
4094 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4095 adapter->device_mode = session_type;
4096 status = hdd_register_interface(adapter, rtnl_held);
4097 if (QDF_STATUS_SUCCESS != status) {
4098 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4099 goto err_free_netdev;
4100 }
4101 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004102 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304103 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304104 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4105 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304106 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004107 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004108 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304109 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110 return NULL;
4111 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112
hqueaa33ee2017-05-04 17:56:35 +08004113 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4114
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116
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);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004414 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004415 if (QDF_SAP_MODE == adapter->device_mode) {
4416 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4417 cds_flush_delayed_work(
4418 &adapter->acs_pending_work);
4419 clear_bit(ACS_PENDING, &adapter->event_flags);
4420 }
4421 }
Krunal Soni22208392017-09-29 18:10:34 -07004422 cds_flush_work(&adapter->sap_stop_bss_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004423 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004424 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004425 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4426
4427 hdd_deregister_tx_flow_control(adapter);
4428
Kapil Guptac1224bf2017-06-22 21:22:40 +05304429 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004430 mutex_lock(&hdd_ctx->sap_lock);
4431 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304432 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304433 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434
4435 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436 status = wlansap_stop_bss(
4437 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304439 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004440 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304442 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304443 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304444 qdf_status =
4445 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004446 qdf_stop_bss_event,
4447 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448
Anurag Chouhance0dc992016-02-16 18:18:03 +05304449 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004450 hdd_err("failure waiting for wlansap_stop_bss %d",
4451 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004452 }
4453 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004454 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004455 }
4456 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004457 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4458 adapter->device_mode,
4459 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004460
Anurag Chouhanc5548422016-02-24 18:33:27 +05304461 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004462 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004463 updateIE.smeSessionId = adapter->sessionId;
4464 updateIE.ieBufferlength = 0;
4465 updateIE.pAdditionIEBuffer = NULL;
4466 updateIE.append = false;
4467 updateIE.notify = false;
4468 /* Probe bcn reset */
4469 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4470 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304471 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004472 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004473 }
4474 /* Assoc resp reset */
4475 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4476 &updateIE,
4477 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304478 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004479 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004480 }
4481 /* Reset WNI_CFG_PROBE_RSP Flags */
4482 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004483 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004484 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4485 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304486 /*
4487 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4488 */
4489 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4490 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4491
Peng Xu66162de2016-02-11 17:01:20 -08004492 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004493 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004494 mutex_unlock(&hdd_ctx->sap_lock);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304495
4496#ifdef WLAN_OPEN_SOURCE
4497 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4498#endif
4499
4500#ifdef WLAN_NS_OFFLOAD
4501#ifdef WLAN_OPEN_SOURCE
4502 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4503#endif
4504#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004505 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004506 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004507 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004508 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004509 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004510 break;
4511 default:
4512 break;
4513 }
4514
4515 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304516 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004517}
4518
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304519/**
4520 * hdd_deinit_all_adapters - deinit all adapters
4521 * @hdd_ctx: HDD context
4522 * @rtnl_held: True if RTNL lock held
4523 *
4524 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004525void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304526{
4527 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4528 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004529 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304530
4531 ENTER();
4532
4533 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4534
4535 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004536 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304537 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4538 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4539 adapter_node = next;
4540 }
4541
4542 EXIT();
4543}
4544
Dustin Brown27cd9942017-09-27 16:11:44 -07004545QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4546 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004547{
4548 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304549 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004550 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004551
4552 ENTER();
4553
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304554 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4555
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004556 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4557
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304558 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004559 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004560 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004561 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4562 adapterNode = pNext;
4563 }
4564
4565 EXIT();
4566
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304567 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568}
4569
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004570QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571{
4572 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304573 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004574 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004575 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004576 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004577
4578 ENTER();
4579
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304580 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4581
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004582 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4583
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304584 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004585 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004586 hdd_notice("Disabling queues for adapter type: %d",
4587 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304588
4589 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004590 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304591 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004592 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304593
Arun Khandavallicc544b32017-01-30 19:52:16 +05304594 if (hdd_ctx->config->sap_internal_restart &&
4595 adapter->device_mode == QDF_SAP_MODE) {
4596 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304597 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304598 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004599 if (test_bit(SOFTAP_BSS_STARTED,
4600 &adapter->event_flags)) {
4601 hdd_sap_indicate_disconnect_for_sta(adapter);
4602 hdd_cleanup_actionframe(hdd_ctx, adapter);
4603 hdd_sap_destroy_events(adapter);
4604 }
4605 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4606 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304607 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304608 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004609 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004610 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004611
4612 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4613
4614 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004615 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4616 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004617 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4618 hdd_wmm_adapter_close(adapter);
4619 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4620 }
4621
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304622 if (adapter->device_mode == QDF_STA_MODE)
4623 hdd_clear_fils_connection_info(adapter);
4624
Wu Gao3545e642017-07-14 19:24:41 +08004625 if (adapter->device_mode == QDF_SAP_MODE) {
4626 /*
4627 * If adapter is SAP, set session ID to invalid
4628 * since SAP session will be cleanup during SSR.
4629 */
Wu Gao36717432016-11-21 15:09:48 +08004630 wlansap_set_invalid_session(
4631 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4632
Wu Gao3545e642017-07-14 19:24:41 +08004633 wlansap_cleanup_cac_timer(
4634 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4635 }
4636
Yue Mad5b4b9f2017-05-26 16:23:40 -07004637 /* Delete peers if any for STA and P2P client modes */
4638 if (adapter->device_mode == QDF_STA_MODE ||
4639 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004640 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004641 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004642 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004643
4644 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4645 peerMacAddr.bytes);
4646 }
4647
Yue Maf9782842017-05-08 12:49:49 -07004648 /* Destroy vdev which will be recreated during reinit. */
4649 hdd_vdev_destroy(adapter);
4650
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004651 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4652 adapterNode = pNext;
4653 }
4654
4655 EXIT();
4656
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304657 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004658}
4659
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004660bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304661{
4662 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4663 QDF_STATUS status;
4664 bool close_modules = true;
4665
Arun Khandavalliba479c42017-07-26 21:29:40 +05304666 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4667 hdd_info("FTM mode, don't close the module");
4668 return false;
4669 }
4670
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304671 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4672 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4673 if (test_bit(DEVICE_IFACE_OPENED,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004674 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004675 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304676 close_modules = false;
4677 break;
4678 }
4679 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4680 adapter_node = next;
4681 }
4682
4683 return close_modules;
4684}
4685
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304686bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304687{
4688 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4689 return true;
4690 else
4691 return false;
4692}
4693
Anurag Chouhanc4092922016-09-08 15:56:11 +05304694#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004695 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304696struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4697 struct ieee80211_channel *channel,
4698 const u8 *bssid, const u8 *ssid,
4699 size_t ssid_len)
4700{
4701 return cfg80211_get_bss(wiphy, channel, bssid,
4702 ssid, ssid_len,
4703 WLAN_CAPABILITY_ESS,
4704 WLAN_CAPABILITY_ESS);
4705}
4706#else
4707struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4708 struct ieee80211_channel *channel,
4709 const u8 *bssid, const u8 *ssid,
4710 size_t ssid_len)
4711{
4712 return cfg80211_get_bss(wiphy, channel, bssid,
4713 ssid, ssid_len,
4714 IEEE80211_BSS_TYPE_ESS,
4715 IEEE80211_PRIVACY_ANY);
4716}
4717#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304718
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304719#if defined CFG80211_CONNECT_BSS || \
4720 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304721#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304722 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304723/**
4724 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4725 * @timeout_reason: reason for connect timeout
4726 *
4727 * This function is used to convert host timeout
4728 * reason enum to kernel specific enum.
4729 *
4730 * Return: nl timeout enum
4731 */
4732static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4733 tSirResultCodes timeout_reason)
4734{
4735 switch (timeout_reason) {
4736 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4737 return NL80211_TIMEOUT_SCAN;
4738 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4739 return NL80211_TIMEOUT_AUTH;
4740 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4741 return NL80211_TIMEOUT_ASSOC;
4742 default:
4743 return NL80211_TIMEOUT_UNSPECIFIED;
4744 }
4745}
4746
4747/**
4748 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4749 * @dev: network device
4750 * @bssid: bssid to which we want to associate
4751 * @timeout_reason: reason for connect timeout
4752 *
4753 * This API is used to send connection timeout reason to supplicant
4754 *
4755 * Return: void
4756 */
4757static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4758 const u8 *bssid,
4759 tSirResultCodes timeout_reason)
4760{
4761 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004762
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304763 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4764
4765 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4766 nl_timeout_reason);
4767}
4768
4769/**
4770 * __hdd_connect_bss() - API to send connection status to supplicant
4771 * @dev: network device
4772 * @bssid: bssid to which we want to associate
4773 * @req_ie: Request Information Element
4774 * @req_ie_len: len of the req IE
4775 * @resp_ie: Response IE
4776 * @resp_ie_len: len of ht response IE
4777 * @status: status
4778 * @gfp: Kernel Flag
4779 * @timeout_reason: reason for connect timeout
4780 *
4781 * Return: void
4782 */
4783static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4784 struct cfg80211_bss *bss, const u8 *req_ie,
4785 size_t req_ie_len, const u8 *resp_ie,
4786 size_t resp_ie_len, int status, gfp_t gfp,
4787 tSirResultCodes timeout_reason)
4788{
4789 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004790
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304791 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4792
4793 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4794 resp_ie, resp_ie_len, status, gfp,
4795 nl_timeout_reason);
4796}
4797#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304798#if defined CFG80211_CONNECT_TIMEOUT || \
4799 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304800static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4801 const u8 *bssid,
4802 tSirResultCodes timeout_reason)
4803{
4804 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4805}
4806#endif
4807
4808static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4809 struct cfg80211_bss *bss, const u8 *req_ie,
4810 size_t req_ie_len, const u8 *resp_ie,
4811 size_t resp_ie_len, int status, gfp_t gfp,
4812 tSirResultCodes timeout_reason)
4813{
4814 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4815 resp_ie, resp_ie_len, status, gfp);
4816}
4817#endif
4818
Abhishek Singha84d3952016-09-13 13:45:05 +05304819/**
4820 * hdd_connect_bss() - API to send connection status to supplicant
4821 * @dev: network device
4822 * @bssid: bssid to which we want to associate
4823 * @req_ie: Request Information Element
4824 * @req_ie_len: len of the req IE
4825 * @resp_ie: Response IE
4826 * @resp_ie_len: len of ht response IE
4827 * @status: status
4828 * @gfp: Kernel Flag
4829 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304830 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304831 *
4832 * The API is a wrapper to send connection status to supplicant
4833 *
4834 * Return: Void
4835 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304836#if defined CFG80211_CONNECT_TIMEOUT || \
4837 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05304838static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4839 struct cfg80211_bss *bss, const u8 *req_ie,
4840 size_t req_ie_len, const u8 *resp_ie,
4841 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304842 bool connect_timeout,
4843 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304844{
4845 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304846 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304847 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304848 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4849 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304850}
4851#else
4852static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4853 struct cfg80211_bss *bss, const u8 *req_ie,
4854 size_t req_ie_len, const u8 *resp_ie,
4855 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304856 bool connect_timeout,
4857 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304858{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304859 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4860 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304861}
4862#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304863
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304864#if defined(WLAN_FEATURE_FILS_SK)
4865#if defined(CFG80211_CONNECT_DONE) || \
4866 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
4867#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
4868 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304869/**
4870 * hdd_populate_fils_params() - Populate FILS keys to connect response
4871 * @fils_params: connect response to supplicant
4872 * @fils_kek: FILS kek
4873 * @fils_kek_len: FILS kek length
4874 * @pmk: FILS PMK
4875 * @pmk_len: FILS PMK length
4876 * @pmkid: PMKID
4877 * @fils_seq_num: FILS Seq number
4878 *
4879 * Return: None
4880 */
4881static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4882 *fils_params, const uint8_t *fils_kek,
4883 size_t fils_kek_len, const uint8_t *pmk,
4884 size_t pmk_len, const uint8_t *pmkid,
4885 uint16_t fils_seq_num)
4886{
4887 /* Increament seq number to be used for next FILS */
4888 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4889 fils_params->update_erp_next_seq_num = true;
4890 fils_params->fils_kek = fils_kek;
4891 fils_params->fils_kek_len = fils_kek_len;
4892 fils_params->pmk = pmk;
4893 fils_params->pmk_len = pmk_len;
4894 fils_params->pmkid = pmkid;
4895}
4896#else
4897static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4898 *fils_params, const uint8_t
4899 *fils_kek, size_t fils_kek_len,
4900 const uint8_t *pmk, size_t pmk_len,
4901 const uint8_t *pmkid,
4902 uint16_t fils_seq_num)
4903{ }
4904#endif
4905
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304906void hdd_update_hlp_info(struct net_device *dev, tCsrRoamInfo *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304907{
4908 struct sk_buff *skb;
4909 uint16_t skb_len;
4910 struct llc_snap_hdr_t *llc_hdr;
4911 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304912 uint8_t *hlp_data;
4913 uint16_t hlp_data_len;
4914 struct fils_join_rsp_params *roam_fils_params
4915 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304916 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
4917
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304918 if (!roam_fils_params) {
4919 hdd_err("FILS Roam Param NULL");
4920 return;
4921 }
4922
4923 if (!roam_fils_params->hlp_data_len || !roam_fils_params->hlp_data) {
4924 hdd_err("FILS HLP Data NULL, len %d",
4925 roam_fils_params->hlp_data_len);
4926 return;
4927 }
4928
4929 hlp_data = roam_fils_params->hlp_data;
4930 hlp_data_len = roam_fils_params->hlp_data_len;
4931
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304932 /* Calculate skb length */
4933 skb_len = (2 * ETH_ALEN) + hlp_data_len;
4934 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
4935 if (skb == NULL) {
4936 hdd_err("HLP packet nbuf alloc fails");
4937 return;
4938 }
4939
4940 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
4941 QDF_MAC_ADDR_SIZE);
4942 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
4943 QDF_MAC_ADDR_SIZE);
4944
4945 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
4946 if (IS_SNAP(llc_hdr)) {
4947 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4948 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4949 }
4950
4951 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
4952
4953 /*
4954 * This HLP packet is formed from HLP info encapsulated
4955 * in assoc response frame which is AEAD encrypted.
4956 * Hence, this checksum validation can be set unnecessary.
4957 * i.e. network layer need not worry about checksum.
4958 */
4959 skb->ip_summed = CHECKSUM_UNNECESSARY;
4960
4961 status = hdd_rx_packet_cbk(padapter, skb);
4962 if (QDF_IS_STATUS_ERROR(status)) {
4963 hdd_err("Sending HLP packet fails");
4964 return;
4965 }
4966 hdd_debug("send HLP packet to netif successfully");
4967}
4968
4969/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304970 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4971 * @dev: network device
4972 * @bssid: bssid to which we want to associate
4973 * @bss: cfg80211 bss info
4974 * @roam_info: information about connected bss
4975 * @req_ie: Request Information Element
4976 * @req_ie_len: len of the req IE
4977 * @resp_ie: Response IE
4978 * @resp_ie_len: len of ht response IE
4979 * @status: status
4980 * @gfp: allocation flags
4981 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4982 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304983 *
4984 * This API is used as wrapper to send FILS key/sequence number
4985 * params etc. to supplicant in case of FILS connection
4986 *
4987 * Return: None
4988 */
4989static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4990 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4991 const u8 *req_ie, size_t req_ie_len,
4992 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004993 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304994 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304995{
4996 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304997 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
4998 struct fils_join_rsp_params *roam_fils_params =
4999 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005000
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305001 qdf_mem_zero(&fils_params, sizeof(fils_params));
5002
5003 if (!roam_fils_params) {
5004 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5005 } else {
5006 fils_params.status = status;
5007 fils_params.bssid = bssid;
5008 fils_params.timeout_reason = timeout_reason;
5009 fils_params.req_ie = req_ie;
5010 fils_params.req_ie_len = req_ie_len;
5011 fils_params.resp_ie = resp_ie;
5012 fils_params.resp_ie_len = resp_ie_len;
5013 fils_params.bss = bss;
5014 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5015 roam_fils_params->kek_len,
5016 roam_fils_params->fils_pmk,
5017 roam_fils_params->fils_pmk_len,
5018 roam_fils_params->fils_pmkid,
5019 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305020 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305021 }
5022 hdd_debug("FILS indicate connect status %d seq no %d",
5023 fils_params.status,
5024 fils_params.fils_erp_next_seq_num);
5025
5026 cfg80211_connect_done(dev, &fils_params, gfp);
5027
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305028 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305029 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305030
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305031 /* Clear all the FILS key info */
5032 if (roam_fils_params && roam_fils_params->fils_pmk)
5033 qdf_mem_free(roam_fils_params->fils_pmk);
5034 if (roam_fils_params)
5035 qdf_mem_free(roam_fils_params);
5036 roam_info->fils_join_rsp = NULL;
5037}
5038#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005039static inline void
5040hdd_connect_done(struct net_device *dev, const u8 *bssid,
5041 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
5042 const u8 *req_ie, size_t req_ie_len,
5043 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5044 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305045 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305046{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305047#endif
5048#endif
5049
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305050#if defined(WLAN_FEATURE_FILS_SK) && \
5051 (defined(CFG80211_CONNECT_DONE) || \
5052 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305053/**
5054 * hdd_fils_update_connect_results() - API to send fils connection status to
5055 * supplicant.
5056 * @dev: network device
5057 * @bssid: bssid to which we want to associate
5058 * @bss: cfg80211 bss info
5059 * @roam_info: information about connected bss
5060 * @req_ie: Request Information Element
5061 * @req_ie_len: len of the req IE
5062 * @resp_ie: Response IE
5063 * @resp_ie_len: len of ht response IE
5064 * @status: status
5065 * @gfp: allocation flags
5066 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5067 * @timeout_reason: reason for connect timeout
5068 *
5069 * The API is a wrapper to send connection status to supplicant
5070 *
5071 * Return: 0 if success else failure
5072 */
5073static int hdd_fils_update_connect_results(struct net_device *dev,
5074 const u8 *bssid,
5075 struct cfg80211_bss *bss,
5076 tCsrRoamInfo *roam_info, const u8 *req_ie,
5077 size_t req_ie_len, const u8 *resp_ie,
5078 size_t resp_ie_len, u16 status, gfp_t gfp,
5079 bool connect_timeout,
5080 tSirResultCodes timeout_reason)
5081{
5082 ENTER();
5083 if (!roam_info || !roam_info->is_fils_connection)
5084 return -EINVAL;
5085
5086 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5087 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305088 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305089 return 0;
5090}
5091#else
5092static inline int hdd_fils_update_connect_results(struct net_device *dev,
5093 const u8 *bssid,
5094 struct cfg80211_bss *bss,
5095 tCsrRoamInfo *roam_info, const u8 *req_ie,
5096 size_t req_ie_len, const u8 *resp_ie,
5097 size_t resp_ie_len, u16 status, gfp_t gfp,
5098 bool connect_timeout,
5099 tSirResultCodes timeout_reason)
5100{
5101 return -EINVAL;
5102}
5103#endif
5104
Anurag Chouhanc4092922016-09-08 15:56:11 +05305105/**
5106 * hdd_connect_result() - API to send connection status to supplicant
5107 * @dev: network device
5108 * @bssid: bssid to which we want to associate
5109 * @roam_info: information about connected bss
5110 * @req_ie: Request Information Element
5111 * @req_ie_len: len of the req IE
5112 * @resp_ie: Response IE
5113 * @resp_ie_len: len of ht response IE
5114 * @status: status
5115 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305116 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305117 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305118 *
5119 * The API is a wrapper to send connection status to supplicant
5120 * and allow runtime suspend
5121 *
5122 * Return: Void
5123 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305124void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5125 tCsrRoamInfo *roam_info, const u8 *req_ie,
5126 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305127 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305128 bool connect_timeout,
5129 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305130{
Jeff Johnson9d295242017-08-29 14:39:48 -07005131 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305132 struct cfg80211_bss *bss = NULL;
5133
5134 if (WLAN_STATUS_SUCCESS == status) {
5135 struct ieee80211_channel *chan;
5136 int freq;
5137 int chan_no = roam_info->pBssDesc->channelId;
5138
5139 if (chan_no <= 14)
5140 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005141 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305142 else
5143 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005144 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305145
5146 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5147 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5148 roam_info->u.pConnectedProfile->SSID.ssId,
5149 roam_info->u.pConnectedProfile->SSID.length);
5150 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305151
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305152 if (hdd_fils_update_connect_results(dev, bssid, bss,
5153 roam_info, req_ie, req_ie_len, resp_ie,
5154 resp_ie_len, status, gfp, connect_timeout,
5155 timeout_reason) != 0) {
5156 hdd_connect_bss(dev, bssid, bss, req_ie,
5157 req_ie_len, resp_ie, resp_ie_len,
5158 status, gfp, connect_timeout, timeout_reason);
5159 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305160
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005161 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005162 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305163}
5164#else
5165void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5166 tCsrRoamInfo *roam_info, const u8 *req_ie,
5167 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305168 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305169 bool connect_timeout,
5170 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305171{
Jeff Johnson9d295242017-08-29 14:39:48 -07005172 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305173
Anurag Chouhanc4092922016-09-08 15:56:11 +05305174 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5175 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005176
5177 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005178 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305179}
5180#endif
5181
5182
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005183QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005184{
5185 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305186 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005187 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305189 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005190#endif
5191 eConnectionState connState;
5192
5193 ENTER();
5194
5195 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305196 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005197 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198
Arun Khandavallifae92942016-08-01 13:31:08 +05305199 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305200 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005202 hdd_wmm_init(adapter);
5203
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005204 adapter->scan_info.mScanPending = false;
5205
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005206 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005207 case QDF_STA_MODE:
5208 case QDF_P2P_CLIENT_MODE:
5209 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210
5211 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5212 ->conn_info.connState;
5213
5214 hdd_init_station_mode(adapter);
5215 /* Open the gates for HDD to receive Wext commands */
5216 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005218 /* Indicate disconnect event to supplicant
5219 * if associated previously
5220 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005221 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005222 eConnectionState_IbssConnected == connState ||
5223 eConnectionState_NotConnected == connState ||
5224 eConnectionState_IbssDisconnected == connState ||
5225 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005226 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005227
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005228 memset(&wrqu, '\0', sizeof(wrqu));
5229 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5230 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5231 wireless_send_event(adapter->dev, SIOCGIWAP,
5232 &wrqu, NULL);
5233 adapter->sessionCtx.station.
5234 hdd_ReassocScenario = false;
5235
5236 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305237 wlan_hdd_cfg80211_indicate_disconnect(
5238 adapter->dev, false,
5239 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240 } else if (eConnectionState_Connecting == connState) {
5241 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005242 * Indicate connect failure to supplicant if we
5243 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305245 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305246 NULL, 0, NULL, 0,
5247 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005248 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249 }
5250
5251 hdd_register_tx_flow_control(adapter,
5252 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005253 hdd_tx_resume_cb,
5254 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005255
5256 break;
5257
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005258 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005259 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305260 hdd_init_ap_mode(adapter, true);
5261
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262 break;
5263
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005264 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005265#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005266 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005267 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5268#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005269 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005270 /* event supplicant to restart */
5271 cfg80211_del_sta(adapter->dev,
5272 (const u8 *)&bcastMac.bytes[0],
5273 GFP_KERNEL);
5274#endif
5275 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305276 case QDF_MONITOR_MODE:
5277 hdd_init_station_mode(adapter);
5278 hdd_set_mon_rx_cb(adapter->dev);
5279 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5280 adapter->mon_bandwidth);
5281 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005282 default:
5283 break;
5284 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005285 /*
5286 * Action frame registered in one adapter which will
5287 * applicable to all interfaces
5288 */
5289 wlan_hdd_cfg80211_register_frames(adapter);
5290
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305291get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005292 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5293 adapterNode = pNext;
5294 }
5295
5296 EXIT();
5297
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305298 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005299}
5300
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005301QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005302 hdd_adapter_list_node_t **padapterNode)
5303{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305304 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005305
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005306 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305307 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5308 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005309 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005310 return status;
5311}
5312
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005313QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314 hdd_adapter_list_node_t *adapterNode,
5315 hdd_adapter_list_node_t **pNextAdapterNode)
5316{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305317 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005318
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005319 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305320 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5321 (qdf_list_node_t *) adapterNode,
5322 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005323
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005324 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005325 return status;
5326}
5327
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005328QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005329 hdd_adapter_list_node_t *adapterNode)
5330{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305331 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005332
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005333 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305334 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005335 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005336 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005337 return status;
5338}
5339
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005340QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005341 hdd_adapter_list_node_t **padapterNode)
5342{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305343 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005344
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005345 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305346 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5347 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005348 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005349 return status;
5350}
5351
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005352QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005353 hdd_adapter_list_node_t *adapterNode)
5354{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305355 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005356
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005357 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305358 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5359 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005360 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005361 return status;
5362}
5363
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005364QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005365 hdd_adapter_list_node_t *adapterNode)
5366{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305367 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005368
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005369 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305370 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5371 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005372 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005373 return status;
5374}
5375
Jeff Johnson9d295242017-08-29 14:39:48 -07005376struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005377 tSirMacAddr macAddr)
5378{
5379 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005380 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305381 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005382
5383 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5384
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305385 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005386 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005387
5388 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305389 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005390 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005391 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005392
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005393 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5394 adapterNode = pNext;
5395 }
5396
5397 return NULL;
5398
5399}
5400
Jeff Johnson9d295242017-08-29 14:39:48 -07005401struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005402 uint32_t vdev_id)
5403{
5404 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005405 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305406 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005407
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305408 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005409
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305410 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005411 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412
5413 if (adapter->sessionId == vdev_id)
5414 return adapter;
5415
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305416 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005417 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5418 adapterNode = pNext;
5419 }
5420
Jeff Johnson5880d792016-08-15 13:32:30 -07005421 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005422
5423 return NULL;
5424}
5425
Abhishek Singh7996eb72015-12-30 17:24:02 +05305426/**
5427 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5428 * the sessionid
5429 * @hdd_ctx: hdd context.
5430 * @sme_session_id: sme session is for the adapter to get.
5431 *
5432 * This function is used to get the adapter with provided session id
5433 *
5434 * Return: adapter pointer if found
5435 *
5436 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005437struct hdd_adapter *
5438hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5439 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305440{
5441 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005442 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305443 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305444
5445
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305446 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305447
5448 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305449 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005450 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305451
5452 if (adapter &&
5453 adapter->sessionId == sme_session_id)
5454 return adapter;
5455
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305456 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305457 hdd_get_next_adapter(hdd_ctx,
5458 adapter_node, &next);
5459 adapter_node = next;
5460 }
5461 return NULL;
5462}
5463
Jeff Johnson9d295242017-08-29 14:39:48 -07005464struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005465 const char *iface_name)
5466{
5467 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005468 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005469 QDF_STATUS qdf_status;
5470
5471 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5472
5473 while ((NULL != adapter_node) &&
5474 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005475 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005476
5477 if (adapter &&
5478 !qdf_str_cmp(adapter->dev->name, iface_name))
5479 return adapter;
5480
5481 qdf_status =
5482 hdd_get_next_adapter(hdd_ctx,
5483 adapter_node, &next);
5484 adapter_node = next;
5485 }
5486 return NULL;
5487}
5488
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005489/**
5490 * hdd_get_adapter() - to get adapter matching the mode
5491 * @hdd_ctx: hdd context
5492 * @mode: adapter mode
5493 *
5494 * This routine will return the pointer to adapter matching
5495 * with the passed mode.
5496 *
5497 * Return: pointer to adapter or null
5498 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005499struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005500 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005501{
5502 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005503 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305504 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005505
5506 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5507
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305508 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005509 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005510
5511 if (adapter && (mode == adapter->device_mode))
5512 return adapter;
5513
5514 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5515 adapterNode = pNext;
5516 }
5517
5518 return NULL;
5519
5520}
5521
5522/**
5523 * hdd_get_operating_channel() - return operating channel of the device mode
5524 * @hdd_ctx: Pointer to the HDD context.
5525 * @mode: Device mode for which operating channel is required.
5526 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005527 * QDF_STA_MODE,
5528 * QDF_P2P_CLIENT_MODE,
5529 * QDF_SAP_MODE,
5530 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005531 *
5532 * This API returns the operating channel of the requested device mode
5533 *
5534 * Return: channel number. "0" id the requested device is not found OR it is
5535 * not connected.
5536 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005537uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005538 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005539{
5540 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305541 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005542 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005543 uint8_t operatingChannel = 0;
5544
5545 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5546
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305547 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005548 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005549
5550 if (mode == adapter->device_mode) {
5551 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005552 case QDF_STA_MODE:
5553 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005554 if (hdd_conn_is_connected
5555 (WLAN_HDD_GET_STATION_CTX_PTR
5556 (adapter))) {
5557 operatingChannel =
5558 (WLAN_HDD_GET_STATION_CTX_PTR
5559 (adapter))->conn_info.
5560 operationChannel;
5561 }
5562 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005563 case QDF_SAP_MODE:
5564 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005565 /* softap connection info */
5566 if (test_bit
5567 (SOFTAP_BSS_STARTED,
5568 &adapter->event_flags))
5569 operatingChannel =
5570 (WLAN_HDD_GET_AP_CTX_PTR
5571 (adapter))->operatingChannel;
5572 break;
5573 default:
5574 break;
5575 }
5576
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005577 /* Found the device of interest. break the loop */
5578 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005579 }
5580
5581 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5582 adapterNode = pNext;
5583 }
5584 return operatingChannel;
5585}
5586
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005587static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005588 hdd_ctx)
5589{
5590 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305591 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005592 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005593
5594 ENTER();
5595
5596 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5597
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305598 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005599 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005600 if ((adapter->device_mode == QDF_STA_MODE) ||
5601 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5602 (adapter->device_mode == QDF_IBSS_MODE) ||
5603 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5604 (adapter->device_mode == QDF_SAP_MODE) ||
5605 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005606 wlan_hdd_cfg80211_deregister_frames(adapter);
5607 hdd_unregister_wext(adapter->dev);
5608 }
5609 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5610 adapterNode = pNext;
5611 }
5612
5613 EXIT();
5614
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305615 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005616}
5617
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005618QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005619{
5620 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305621 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005622 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005623
5624 ENTER();
5625
5626 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5627
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305628 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005629 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005630 if ((adapter->device_mode == QDF_STA_MODE) ||
5631 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5632 (adapter->device_mode == QDF_IBSS_MODE) ||
5633 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5634 (adapter->device_mode == QDF_SAP_MODE) ||
5635 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005636 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5637 adapter->sessionId, INVALID_SCAN_ID,
5638 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005639 }
5640 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5641 adapterNode = pNext;
5642 }
5643
5644 EXIT();
5645
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305646 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005647}
5648
Dustin Brownf27bce82016-11-03 12:52:27 -07005649/**
5650 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5651 * adapters
5652 * @hdd_ctx: The HDD context containing the adapters to operate on
5653 *
5654 * return: QDF_STATUS_SUCCESS
5655 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005656static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005657{
5658 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5659 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005660 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005661 int err;
5662
5663 ENTER();
5664
5665 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5666
5667 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005668 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005669 if ((adapter->device_mode == QDF_STA_MODE) ||
5670 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5671 (adapter->device_mode == QDF_IBSS_MODE) ||
5672 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5673 (adapter->device_mode == QDF_SAP_MODE) ||
5674 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5675 err = wlan_hdd_sched_scan_stop(adapter->dev);
5676 if (err)
5677 hdd_err("Unable to stop scheduled scan");
5678 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005679 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5680 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005681 adapter_node = next_node;
5682 }
5683
5684 EXIT();
5685
5686 return QDF_STATUS_SUCCESS;
5687}
5688
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689#ifdef WLAN_NS_OFFLOAD
5690/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005691 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005692 * @hdd_ctx: Pointer to hdd context
5693 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005694 * Unregister for IPv6 address change notifications.
5695 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005696 * Return: None
5697 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005698static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005699{
5700 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005701}
5702
5703/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005704 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005705 * @hdd_ctx: Pointer to hdd context
5706 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005707 * Register for IPv6 address change notifications.
5708 *
5709 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005710 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005711static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005712{
5713 int ret;
5714
5715 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5716 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005717 if (ret) {
5718 hdd_err("Failed to register IPv6 notifier: %d", ret);
5719 goto out;
5720 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005721
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005722 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005723out:
5724 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005725}
5726#else
5727/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005728 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005729 * @hdd_ctx: Pointer to hdd context
5730 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005731 * Unregister for IPv6 address change notifications.
5732 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005733 * Return: None
5734 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005735static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005736{
5737}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005738
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005739/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005740 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005741 * @hdd_ctx: Pointer to hdd context
5742 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005743 * Register for IPv6 address change notifications.
5744 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005745 * Return: None
5746 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005747static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005748{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005749 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005750}
5751#endif
5752
5753/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005754 * hdd_register_notifiers - Register netdev notifiers.
5755 * @hdd_ctx: HDD context
5756 *
5757 * Register netdev notifiers like IPv4 and IPv6.
5758 *
5759 * Return: 0 on success and errno on failure
5760 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005761static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005762{
5763 int ret;
5764
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005765 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5766 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305767 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005768
5769 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5770 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5771 if (ret) {
5772 hdd_err("Failed to register IPv4 notifier: %d", ret);
5773 goto unregister_ip6_notifier;
5774 }
5775
5776 return 0;
5777
5778unregister_ip6_notifier:
5779 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005780out:
5781 return ret;
5782
5783}
5784
5785/**
5786 * hdd_unregister_notifiers - Unregister netdev notifiers.
5787 * @hdd_ctx: HDD context
5788 *
5789 * Unregister netdev notifiers like IPv4 and IPv6.
5790 *
5791 * Return: None.
5792 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005793void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005794{
5795 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5796
5797 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005798}
5799
5800/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005801 * hdd_exit_netlink_services - Exit netlink services
5802 * @hdd_ctx: HDD context
5803 *
5804 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5805 * nl service.
5806 *
5807 * Return: None.
5808 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005809static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005810{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005811 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005812 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005813 ptt_sock_deactivate_svc();
5814
5815 nl_srv_exit();
5816}
5817
5818/**
5819 * hdd_init_netlink_services- Init netlink services
5820 * @hdd_ctx: HDD context
5821 *
5822 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5823 * nl service.
5824 *
5825 * Return: 0 on success and errno on failure.
5826 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005827static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005828{
5829 int ret;
5830
Ryan Hsuceddceb2016-04-28 10:20:14 -07005831 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005832 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005833 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005834 goto out;
5835 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005836 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005837
Naveen Rawat910726a2017-03-06 11:42:51 -08005838 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005839 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005840 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005841 goto err_nl_srv;
5842 }
5843
5844 ret = ptt_sock_activate_svc();
5845 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005846 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005847 goto err_nl_srv;
5848 }
5849
5850 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005851 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005852 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005853
5854 ret = cnss_diag_activate_service();
5855 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005856 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005857 goto err_close_cesium;
5858 }
5859
5860 return 0;
5861
5862err_close_cesium:
5863 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005864 ptt_sock_deactivate_svc();
5865err_nl_srv:
5866 nl_srv_exit();
5867out:
5868 return ret;
5869}
5870
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005871/**
5872 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5873 * @hdd_ctx: HDD context.
5874 *
5875 * Destroy RX wakelock.
5876 *
5877 * Return: None.
5878 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005879static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005880{
5881 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5882}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005883
5884/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005885 * hdd_rx_wake_lock_create() - Create RX wakelock
5886 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005887 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005888 * Create RX wakelock.
5889 *
5890 * Return: None.
5891 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005892static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005893{
5894 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5895}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005896
5897/**
Houston Hoffman160db392016-10-10 17:37:51 -07005898 * hdd_context_deinit() - Deinitialize HDD context
5899 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005900 *
Houston Hoffman160db392016-10-10 17:37:51 -07005901 * Deinitialize HDD context along with all the feature specific contexts but
5902 * do not free hdd context itself. Caller of this API is supposed to free
5903 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005904 *
Houston Hoffman160db392016-10-10 17:37:51 -07005905 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005906 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005907static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005908{
Houston Hoffman160db392016-10-10 17:37:51 -07005909 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005910
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005911 hdd_sap_context_destroy(hdd_ctx);
5912
5913 hdd_rx_wake_lock_destroy(hdd_ctx);
5914
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005915 hdd_scan_context_destroy(hdd_ctx);
5916
5917 qdf_list_destroy(&hdd_ctx->hddAdapters);
5918
Houston Hoffman160db392016-10-10 17:37:51 -07005919 return 0;
5920}
5921
5922/**
5923 * hdd_context_destroy() - Destroy HDD context
5924 * @hdd_ctx: HDD context to be destroyed.
5925 *
5926 * Free config and HDD context as well as destroy all the resources.
5927 *
5928 * Return: None
5929 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005930static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005931{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005932 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305933
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305934 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5935
Houston Hoffman160db392016-10-10 17:37:51 -07005936 hdd_context_deinit(hdd_ctx);
5937
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305938 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005939 hdd_ctx->config = NULL;
5940
5941 wiphy_free(hdd_ctx->wiphy);
5942}
5943
5944/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305945 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5946 *
5947 * This function is used to destroy bug report lock
5948 *
5949 * Return: None
5950 */
5951static void wlan_destroy_bug_report_lock(void)
5952{
5953 p_cds_contextType p_cds_context;
5954
5955 p_cds_context = cds_get_global_context();
5956 if (!p_cds_context) {
5957 hdd_err("cds context is NULL");
5958 return;
5959 }
5960
5961 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5962}
5963
5964/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005965 * hdd_wlan_exit() - HDD WLAN exit function
5966 * @hdd_ctx: Pointer to the HDD Context
5967 *
5968 * This is the driver exit point (invoked during rmmod)
5969 *
5970 * Return: None
5971 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005972static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005973{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305974 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005975 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305976 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005977
5978 ENTER();
5979
Arun Khandavallifae92942016-08-01 13:31:08 +05305980 if (QDF_TIMER_STATE_RUNNING ==
5981 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005982 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305983 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005984 }
5985
Arun Khandavallifae92942016-08-01 13:31:08 +05305986 if (!QDF_IS_STATUS_SUCCESS
5987 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5988 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005989
Arun Khandavallifae92942016-08-01 13:31:08 +05305990
5991 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005992
Prashanth Bhattaab004382016-10-11 16:08:11 -07005993 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005994
5995#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305996 if (QDF_TIMER_STATE_RUNNING ==
5997 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5998 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005999 }
6000
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306001 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306002 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006003 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006004 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006005 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6006 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6007 hdd_ctx->last_acs_channel_list = NULL;
6008 hdd_ctx->num_of_channels = 0;
6009 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006010#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006011
Arun Khandavallifae92942016-08-01 13:31:08 +05306012 mutex_lock(&hdd_ctx->iface_change_lock);
6013 driver_status = hdd_ctx->driver_status;
6014 mutex_unlock(&hdd_ctx->iface_change_lock);
6015
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006016 /*
6017 * Powersave Offload Case
6018 * Disable Idle Power Save Mode
6019 */
6020 hdd_set_idle_ps_config(hdd_ctx, false);
6021
Arun Khandavallifae92942016-08-01 13:31:08 +05306022 if (driver_status != DRIVER_MODULES_CLOSED) {
6023 hdd_unregister_wext_all_adapters(hdd_ctx);
6024 /*
6025 * Cancel any outstanding scan requests. We are about to close
6026 * all of our adapters, but an adapter structure is what SME
6027 * passes back to our callback function. Hence if there
6028 * are any outstanding scan requests then there is a
6029 * race condition between when the adapter is closed and
6030 * when the callback is invoked. We try to resolve that
6031 * race condition here by canceling any outstanding scans
6032 * before we close the adapters.
6033 * Note that the scans may be cancelled in an asynchronous
6034 * manner, so ideally there needs to be some kind of
6035 * synchronization. Rather than introduce a new
6036 * synchronization here, we will utilize the fact that we are
6037 * about to Request Full Power, and since that is synchronized,
6038 * the expectation is that by the time Request Full Power has
6039 * completed, all scans will be cancelled
6040 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07006041 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05306042 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006043 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006044 hdd_stop_all_adapters(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006045 }
6046
6047 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306048 * Close the scheduler before calling cds_close to make sure
6049 * no thread is scheduled after the each module close is
6050 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006051 */
Jeff Johnson7d562272017-09-13 15:12:54 -07006052 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306053 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05306054 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306055 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006056 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006057
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306058 unregister_netdevice_notifier(&hdd_netdev_notifier);
6059
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006060 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306061
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306062 qdf_nbuf_deinit_replenish_timer();
6063
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306064 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6065 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6066 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6067
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006068 /*
6069 * Close CDS
6070 * This frees pMac(HAL) context. There should not be any call
6071 * that requires pMac access after this.
6072 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006073
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006074 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006075 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006076
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006077 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006078
6079 hdd_ipa_cleanup(hdd_ctx);
6080
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306081 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306082 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306083 /*
6084 * If there is re_init failure wiphy would have already de-registered
6085 * check the wiphy status before un-registering again
6086 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306087 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306088 wiphy_unregister(wiphy);
6089 wlan_hdd_cfg80211_deinit(wiphy);
6090 hdd_lpass_notify_stop(hdd_ctx);
6091 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006092
Arun Khandavallifae92942016-08-01 13:31:08 +05306093 hdd_exit_netlink_services(hdd_ctx);
6094 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306095#ifdef FEATURE_WLAN_CH_AVOID
6096 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6097#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306098
6099 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6100 if (driver_status)
6101 hdd_err("Pdev delete failed");
6102
6103 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6104 if (driver_status)
6105 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006106
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006107 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006108}
6109
6110void __hdd_wlan_exit(void)
6111{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006112 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006113
6114 ENTER();
6115
Anurag Chouhan6d760662016-02-20 16:05:43 +05306116 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006117 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006118 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006119 EXIT();
6120 return;
6121 }
6122
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006123 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306124 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006125
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006126 /* Do all the cleanup before deregistering the driver */
6127 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006128
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006129 EXIT();
6130}
6131
6132#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006133/**
6134 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006135 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006136 *
6137 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6138 * Then new ACS request will do a fresh scan without reusing the cached
6139 * scan information.
6140 *
6141 * Return: void
6142 */
Tang Yingying523322d2017-01-17 23:28:43 +08006143static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006144{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006145 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006146
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006147 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006148 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006149 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6150 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6151 hdd_ctx->last_acs_channel_list = NULL;
6152 hdd_ctx->num_of_channels = 0;
6153 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006154
6155 if (!hdd_ctx->hHal)
6156 return;
6157 sme_scan_flush_result(hdd_ctx->hHal);
6158}
6159#endif
6160
6161#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006162int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6163 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006164{
6165 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306166 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006167 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006168
6169 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6170
6171 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306172 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306174
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006175 if (!hdd_ctx->hHal)
6176 return -EINVAL;
6177
Jeff Johnsone7672e72017-10-21 15:10:04 -07006178 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006179 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306180 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006181 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006182 return -EINVAL;
6183 }
6184
6185 return 0;
6186}
6187#endif
6188
6189/**
6190 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6191 * @state: state
6192 *
6193 * This function notifies FW with modem power status
6194 *
6195 * Return: 0 if successful, error number otherwise
6196 */
6197int hdd_wlan_notify_modem_power_state(int state)
6198{
6199 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306200 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006201 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202
Anurag Chouhan6d760662016-02-20 16:05:43 +05306203 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306205 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006206 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306207
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006208 if (!hdd_ctx->hHal)
6209 return -EINVAL;
6210
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306211 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6212 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006213 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006214 state);
6215 return -EINVAL;
6216 }
6217 return 0;
6218}
6219
6220/**
6221 *
6222 * hdd_post_cds_enable_config() - HDD post cds start config helper
6223 * @adapter - Pointer to the HDD
6224 *
6225 * Return: None
6226 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006227QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006228{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306229 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006230
6231 /*
6232 * Send ready indication to the HDD. This will kick off the MAC
6233 * into a 'running' state and should kick off an initial scan.
6234 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306235 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6236 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006237 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6238 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306239 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240 }
6241
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306242 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006243}
6244
6245/* wake lock APIs for HDD */
6246void hdd_prevent_suspend(uint32_t reason)
6247{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306248 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006249}
6250
6251void hdd_allow_suspend(uint32_t reason)
6252{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306253 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254}
6255
6256void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6257{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306258 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6259 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260}
6261
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006262/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006263QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006264{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006265
Amar Singhal6f8592b2017-04-26 14:31:58 -07006266 return sme_init_chan_list(hdd_ctx->hHal,
6267 hdd_ctx->reg.alpha2,
6268 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006269}
6270
6271/**
6272 * hdd_is_5g_supported() - check if hardware supports 5GHz
6273 * @hdd_ctx: Pointer to the hdd context
6274 *
6275 * HDD function to know if hardware supports 5GHz
6276 *
6277 * Return: true if hardware supports 5GHz
6278 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006279bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006280{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006281 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006282 return true;
6283
Amar Singhal58b45ef2017-08-01 13:43:54 -07006284 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006285 return true;
6286 else
6287 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006288}
6289
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006290static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006291{
6292 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006293 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006294
6295 wiphy = hdd_ctx->wiphy;
6296
6297 /*
6298 * The channel information in
6299 * wiphy needs to be initialized before wiphy registration
6300 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006301 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6302 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006303 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006304 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006305 }
6306
6307#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6308 wiphy->wowlan = &wowlan_support_reg_init;
6309#else
6310 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6311 WIPHY_WOWLAN_MAGIC_PKT |
6312 WIPHY_WOWLAN_DISCONNECT |
6313 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6314 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6315 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6316 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6317 WIPHY_WOWLAN_RFKILL_RELEASE;
6318
6319 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6320 WOW_MAX_FILTERS_PER_LIST);
6321 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6322 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6323#endif
6324
6325 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006326 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306327 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006328 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306329 return ret_val;
6330 }
6331
Amar Singhal5cccafe2017-02-15 12:42:58 -08006332 if (!hdd_ctx->reg_offload)
6333 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006334
Amar Singhale4f28ee2015-10-21 14:36:56 -07006335 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006336}
6337
Ravi Joshie2331e82015-07-01 18:18:54 -07006338/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006339 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006340 * @hdd_ctx - handle to hdd context
6341 * @tx_packets - transmit packet count
6342 * @rx_packets - receive packet count
6343 *
6344 * The function controls the bus bandwidth and dynamic control of
6345 * tcp delayed ack configuration
6346 *
6347 * Returns: None
6348 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006349#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006350static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006351 const uint64_t tx_packets,
6352 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006353{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006354 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006355 uint64_t temp_rx = 0;
6356 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006357 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006358 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006359 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006360 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006361 uint16_t index = 0;
6362 bool vote_level_change = false;
6363 bool rx_level_change = false;
6364 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006365
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006367 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006368 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006369 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006370 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006371 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006372 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006373 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006374
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006375 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006376 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6377 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006379 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006380 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306381 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306382 if (hdd_ctx->hbw_requested) {
6383 pld_remove_pm_qos(hdd_ctx->parent_dev);
6384 hdd_ctx->hbw_requested = false;
6385 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306386 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006387 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006388 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306389 if (!hdd_ctx->hbw_requested) {
6390 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6391 hdd_ctx->hbw_requested = true;
6392 }
6393
Nirav Shah3bbfa512016-05-12 16:43:49 +05306394 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006395 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006396 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006397 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006398 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006399
Mohit Khannaf8f96822017-05-17 17:11:59 -07006400 qdf_dp_trace_throttle_live_mode(
6401 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6402
Mohit Khannae71e2262015-11-10 09:37:24 -08006403 /* fine-tuning parameters for RX Flows */
6404 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6405
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006406 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006407
Ravi Joshifed83572016-10-07 16:20:37 -07006408 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6409 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6410 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6411 next_rx_level = WLAN_SVC_TP_HIGH;
6412 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006413 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006414 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006415 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006416 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006417
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006418 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006419 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006420 next_rx_level, temp_rx);
6421 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006422 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006423 /* Send throughput indication only if it is enabled.
6424 * Disabling tcp_del_ack will revert the tcp stack behavior
6425 * to default delayed ack. Note that this will disable the
6426 * dynamic delayed ack mechanism across the system
6427 */
6428 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306429 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6430 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006431 &next_rx_level,
6432 sizeof(next_rx_level));
6433 }
6434
Mohit Khannae71e2262015-11-10 09:37:24 -08006435 /* fine-tuning parameters for TX Flows */
6436 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6437 hdd_ctx->prev_tx = tx_packets;
6438 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6439 next_tx_level = WLAN_SVC_TP_HIGH;
6440 else
6441 next_tx_level = WLAN_SVC_TP_LOW;
6442
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006443 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006444 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6445 next_tx_level, temp_tx);
6446 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006447 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306448 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6449 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006450 &next_tx_level,
6451 sizeof(next_tx_level));
6452 }
6453
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006454 index = hdd_ctx->hdd_txrx_hist_idx;
6455
6456 if (vote_level_change || tx_level_change || rx_level_change) {
6457 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6458 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6459 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6460 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6461 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6462 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6463 hdd_ctx->hdd_txrx_hist_idx++;
6464 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6465 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006466}
6467
6468#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306469static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006470{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006471 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306472 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006473 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306474 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306475 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6476 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006477 uint64_t total_tx = 0, total_rx = 0;
6478 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306479 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306480 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006481 bool connected = false;
6482 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6483
Prashanth Bhattaab004382016-10-11 16:08:11 -07006484 if (wlan_hdd_validate_context(hdd_ctx))
6485 return;
6486
Jingxiang Gec64e1932017-08-22 14:38:59 +08006487 if (hdd_ctx->isWiphySuspended)
6488 goto restart_timer;
6489
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006490 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306491 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006492 status =
6493 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6494
Jeff Johnson57eb2732017-10-02 11:40:20 -07006495 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006496 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006497 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306498 /*
6499 * Validate magic so we don't end up accessing
6500 * an invalid adapter.
6501 */
6502 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6503 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006504
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006505 if ((adapter->device_mode == QDF_STA_MODE ||
6506 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006507 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6508 != eConnectionState_Associated) {
6509
6510 continue;
6511 }
6512
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006513 if ((adapter->device_mode == QDF_SAP_MODE ||
6514 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006515 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6516
6517 continue;
6518 }
6519
6520 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6521 adapter->prev_tx_packets);
6522 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6523 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306524
6525 if (adapter->device_mode == QDF_SAP_MODE ||
6526 adapter->device_mode == QDF_P2P_GO_MODE ||
6527 adapter->device_mode == QDF_IBSS_MODE) {
6528
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006529 ret = cdp_get_intra_bss_fwd_pkts_count(
6530 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306531 adapter->sessionId,
6532 &fwd_tx_packets, &fwd_rx_packets);
6533 if (ret == A_OK) {
6534 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6535 fwd_tx_packets,
6536 adapter->prev_fwd_tx_packets);
6537 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6538 fwd_tx_packets,
6539 adapter->prev_fwd_rx_packets);
6540 }
6541 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006542
6543 total_rx += adapter->stats.rx_packets;
6544 total_tx += adapter->stats.tx_packets;
6545
6546 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6547 adapter->prev_tx_packets = adapter->stats.tx_packets;
6548 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306549 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6550 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006551 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6552 connected = true;
6553 }
6554
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306555 /* add intra bss forwarded tx and rx packets */
6556 tx_packets += fwd_tx_packets_diff;
6557 rx_packets += fwd_rx_packets_diff;
6558
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006559 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6560 tx_packets += (uint64_t)ipa_tx_packets;
6561 rx_packets += (uint64_t)ipa_rx_packets;
6562
Yun Park2aa880c2017-08-22 10:58:10 -07006563 if (adapter) {
6564 adapter->stats.tx_packets += ipa_tx_packets;
6565 adapter->stats.rx_packets += ipa_rx_packets;
6566 }
6567
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006568 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006569 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006570 return;
6571 }
6572
Yuanyuan Liu13738502016-04-06 17:41:37 -07006573 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006574
6575 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6576 hdd_ipa_uc_stat_request(adapter, 2);
6577
Jingxiang Gec64e1932017-08-22 14:38:59 +08006578restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006579 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006580 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006581 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306582 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006583 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006584 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006585}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006586
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306587/**
6588 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6589 * @arg: Argument of timer function
6590 *
6591 * Schedule a workqueue in this function where all the processing is done.
6592 *
6593 * Return: None.
6594 */
6595static void __hdd_bus_bw_cbk(void *arg)
6596{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006597 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306598
6599 if (wlan_hdd_validate_context(hdd_ctx))
6600 return;
6601
6602 schedule_work(&hdd_ctx->bus_bw_work);
6603}
6604
6605/**
6606 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6607 * @arg: Argument of timer function
6608 *
6609 * Return: None.
6610 */
6611static void hdd_bus_bw_cbk(void *arg)
6612{
6613 cds_ssr_protect(__func__);
6614 __hdd_bus_bw_cbk(arg);
6615 cds_ssr_unprotect(__func__);
6616}
6617
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006618int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006619{
6620 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306621 INIT_WORK(&hdd_ctx->bus_bw_work,
6622 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006623 hdd_ctx->bus_bw_timer_running = false;
6624 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306625 qdf_timer_init(NULL,
6626 &hdd_ctx->bus_bw_timer,
6627 hdd_bus_bw_cbk, (void *)hdd_ctx,
6628 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006629
6630 return 0;
6631}
6632
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006633void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006634{
Dustin Brownfce08d12017-01-17 16:29:38 -08006635 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006636 hdd_reset_tcp_delack(hdd_ctx);
6637
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006638 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306639 cancel_work_sync(&hdd_ctx->bus_bw_work);
6640 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006641 hdd_ctx->bus_bw_timer_running = false;
6642 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006643}
Lin Baic5c06882017-09-21 13:58:43 +08006644
6645void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6646{
6647 if (hdd_ctx)
6648 cancel_work_sync(&hdd_ctx->bus_bw_work);
6649}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006650#endif
6651
6652/**
Nirav Shahed34b212016-04-25 10:59:16 +05306653 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6654 * @hdd_ctx: hdd context
6655 *
6656 * Return: 0 for success or error code
6657 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006658static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306659{
6660 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6661 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6662 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006663 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306664 return -ENOMEM;
6665 }
6666 return 0;
6667}
6668
6669/**
6670 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6671 * @hdd_ctx: hdd context
6672 *
6673 * Return: none
6674 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006675void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306676{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306677 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6678 return;
6679
6680 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6681 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306682}
6683
Nirav Shahda008342016-05-17 18:50:40 +05306684static uint8_t *convert_level_to_string(uint32_t level)
6685{
6686 switch (level) {
6687 /* initialize the wlan sub system */
6688 case WLAN_SVC_TP_NONE:
6689 return "NONE";
6690 case WLAN_SVC_TP_LOW:
6691 return "LOW";
6692 case WLAN_SVC_TP_MEDIUM:
6693 return "MED";
6694 case WLAN_SVC_TP_HIGH:
6695 return "HIGH";
6696 default:
6697 return "INVAL";
6698 }
6699}
6700
Nirav Shahed34b212016-04-25 10:59:16 +05306701
6702/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006703 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6704 * @hdd_ctx: hdd context
6705 *
6706 * Return: none
6707 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006708void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006709{
6710 int i;
6711
6712#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006713 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306714 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006715 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006716 hdd_ctx->config->busBandwidthHighThreshold,
6717 hdd_ctx->config->busBandwidthMediumThreshold,
6718 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006719 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306720 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006721 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006722 hdd_ctx->config->tcpDelackThresholdHigh,
6723 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006724 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306725 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006726#endif
6727
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006728 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306729 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6730
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006731 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006732
6733 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006734 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006735 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006736 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006737 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6738 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006739 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006740 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6741 convert_level_to_string(
6742 hdd_ctx->hdd_txrx_hist[i].
6743 next_vote_level),
6744 convert_level_to_string(
6745 hdd_ctx->hdd_txrx_hist[i].
6746 next_rx_level),
6747 convert_level_to_string(
6748 hdd_ctx->hdd_txrx_hist[i].
6749 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006750 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006751}
6752
6753/**
6754 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6755 * @hdd_ctx: hdd context
6756 *
6757 * Return: none
6758 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006759void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006760{
6761 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306762 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6763 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006764}
6765
6766/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006767 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006768 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006769 *
6770 * Return: none
6771 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006772void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006773{
6774
Jeff Johnson9d295242017-08-29 14:39:48 -07006775 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006776 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306777 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306779 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006780
6781 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306782 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006783 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006784
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006785 hdd_debug("Netif queue operation statistics:");
6786 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306787 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006788 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306789 curr_time = qdf_system_ticks();
6790 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306791 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306792 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306793 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306794 unpause = adapter->total_unpause_time;
6795 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306796 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306797 pause = adapter->total_pause_time;
6798 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006799 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306800 qdf_system_ticks_to_msecs(total),
6801 qdf_system_ticks_to_msecs(pause),
6802 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006803 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006804
Nirav Shahda008342016-05-17 18:50:40 +05306805 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6806 qdf_time_t pause_delta = 0;
6807
6808 if (adapter->pause_map & (1 << i))
6809 pause_delta = delta;
6810
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006811 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006812 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006813 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006814 hdd_reason_type_to_string(i),
6815 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306816 adapter->queue_oper_stats[i].unpause_count,
6817 qdf_system_ticks_to_msecs(
6818 adapter->queue_oper_stats[i].total_pause_time +
6819 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006820 }
6821
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006822 hdd_debug("Netif queue operation history:");
6823 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306824 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6825
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006826 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006827
6828 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006829 /* using hdd_log to avoid printing function name */
6830 if (adapter->queue_oper_history[i].time == 0)
6831 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006832 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006833 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306834 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006835 adapter->queue_oper_history[i].time),
6836 hdd_action_type_to_string(
6837 adapter->queue_oper_history[i].netif_action),
6838 hdd_reason_type_to_string(
6839 adapter->queue_oper_history[i].netif_reason),
6840 adapter->queue_oper_history[i].pause_map);
6841 }
6842
6843 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6844 adapter_node = next;
6845 }
6846
6847
6848}
6849
6850/**
6851 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6852 * @hdd_ctx: hdd context
6853 *
6854 * Return: none
6855 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006856void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006857{
Jeff Johnson9d295242017-08-29 14:39:48 -07006858 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006859 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306860 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006861
6862 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306863 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006864 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006865
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306866 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006867 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306868 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006869 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306870 adapter->history_index = 0;
6871 adapter->start_time = adapter->last_time = qdf_system_ticks();
6872 adapter->total_pause_time = 0;
6873 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006874 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6875 adapter_node = next;
6876 }
6877}
6878
6879/**
6880 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6881 * @halHandle: Hal handle
6882 * @pContext: Pointer to the context
6883 * @sessionId: Session ID
6884 * @scanId: Scan ID
6885 * @status: Status
6886 *
6887 * This is the callback to be executed when 11d scan is completed to flush out
6888 * the scan results
6889 *
6890 * 11d scan is done during driver load and is a passive scan on all
6891 * channels supported by the device, 11d scans may find some APs on
6892 * frequencies which are forbidden to be used in the regulatory domain
6893 * the device is operating in. If these APs are notified to the supplicant
6894 * it may try to connect to these APs, thus flush out all the scan results
6895 * which are present in SME after 11d scan is done.
6896 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306897 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006898 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306899static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006900 uint8_t sessionId, uint32_t scanId,
6901 eCsrScanStatus status)
6902{
6903 ENTER();
6904
6905 sme_scan_flush_result(halHandle);
6906
6907 EXIT();
6908
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306909 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006910}
6911
6912#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6913/**
6914 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6915 * @hdd_ctx: hdd global context
6916 *
6917 * Return: none
6918 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006919static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006920{
6921 uint8_t i;
6922
6923 mutex_init(&hdd_ctx->op_ctx.op_lock);
6924 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6925 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6926 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6927 }
6928}
6929#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006930static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006931{
6932}
6933#endif
6934
Yingying Tang95409972016-10-20 15:16:15 +08006935#ifdef WLAN_FEATURE_WOW_PULSE
6936/**
6937 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006938 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006939 * @enable: enable or disable this behaviour
6940 *
6941 * Return: int
6942 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006943static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006944{
6945 struct hdd_config *pcfg_ini = phddctx->config;
6946 struct wow_pulse_mode wow_pulse_set_info;
6947 QDF_STATUS status;
6948
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006949 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006950
6951 if (false == phddctx->config->wow_pulse_support)
6952 return 0;
6953
6954 /* prepare the request to send to SME */
6955 if (enable == true) {
6956 wow_pulse_set_info.wow_pulse_enable = true;
6957 wow_pulse_set_info.wow_pulse_pin =
6958 pcfg_ini->wow_pulse_pin;
6959 wow_pulse_set_info.wow_pulse_interval_low =
6960 pcfg_ini->wow_pulse_interval_low;
6961 wow_pulse_set_info.wow_pulse_interval_high =
6962 pcfg_ini->wow_pulse_interval_high;
6963 } else {
6964 wow_pulse_set_info.wow_pulse_enable = false;
6965 wow_pulse_set_info.wow_pulse_pin = 0;
6966 wow_pulse_set_info.wow_pulse_interval_low = 0;
6967 wow_pulse_set_info.wow_pulse_interval_high = 0;
6968 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006969 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006970 wow_pulse_set_info.wow_pulse_enable,
6971 wow_pulse_set_info.wow_pulse_pin,
6972 wow_pulse_set_info.wow_pulse_interval_low,
6973 wow_pulse_set_info.wow_pulse_interval_high);
6974
6975 status = sme_set_wow_pulse(&wow_pulse_set_info);
6976 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006977 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006978 return -EIO;
6979 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006980 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006981 return 0;
6982}
6983#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006984static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006985{
6986 return 0;
6987}
6988#endif
6989
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006990#ifdef WLAN_FEATURE_FASTPATH
6991/**
6992 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6993 * @hdd_cfg: hdd config
6994 * @context: lower layer context
6995 *
6996 * Return: none
6997 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306998void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006999 void *context)
7000{
7001 if (hdd_cfg->fastpath_enable)
7002 hif_enable_fastpath(context);
7003}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007004#endif
7005
Yuanyuan Liu13738502016-04-06 17:41:37 -07007006#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007007/**
7008 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007009 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007010 * @level: thermal level
7011 *
7012 * Change IPA data path to SW path when the thermal throttle level greater
7013 * than 0, and restore the original data path when throttle level is 0
7014 *
7015 * Return: none
7016 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007017static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007018{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007019 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007020
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007021 /* Change IPA to SW path when throttle level greater than 0 */
7022 if (level > THROTTLE_LEVEL_0)
7023 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7024 else
7025 /* restore original concurrency mode */
7026 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7027}
7028
7029/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307030 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7031 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307032 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007033 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307034 * Get a safe channel to restart SAP. PCL already takes into account the
7035 * unsafe channels. So, the PCL is validated with the ACS range to provide
7036 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007037 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307038 * Return: Channel number to restart SAP in case of success. In case of any
7039 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007040 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307041static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007042 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007043{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307044 struct sir_pcl_list pcl;
7045 QDF_STATUS status;
7046 uint32_t i, j;
7047 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007048 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307049 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007050
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307051 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7052 if (!hdd_ctx) {
7053 hdd_err("invalid HDD context");
7054 return INVALID_CHANNEL_ID;
7055 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007056
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307057 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7058 if (!hal_handle) {
7059 hdd_err("invalid HAL handle");
7060 return INVALID_CHANNEL_ID;
7061 }
7062
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007063 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7064 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007065 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7066 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307067 if (QDF_IS_STATUS_ERROR(status)) {
7068 hdd_err("Get PCL failed");
7069 return INVALID_CHANNEL_ID;
7070 }
7071
Frank Liudc2cefb2017-06-21 15:38:18 +08007072 /*
7073 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7074 * channel is unsafe channel, the pcl may be empty, instead of return,
7075 * try to choose a safe channel from acs range.
7076 */
7077 if (!pcl.pcl_len)
7078 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307079
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007080 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307081 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7082 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7083
7084 /* PCL already takes unsafe channel into account */
7085 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007086 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307087 if ((pcl.pcl_list[i] >=
7088 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7089 (pcl.pcl_list[i] <=
7090 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007091 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307092 return pcl.pcl_list[i];
7093 }
7094 }
7095
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007096 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307097
7098 /* Try for safe channel from all valid channel */
7099 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007100 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307101 &pcl.pcl_len);
7102 if (QDF_IS_STATUS_ERROR(status)) {
7103 hdd_err("error in getting valid channel list");
7104 return INVALID_CHANNEL_ID;
7105 }
7106
7107 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007108 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307109 found = false;
7110 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007111 if (pcl.pcl_list[i] ==
7112 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007113 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307114 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007115 break;
7116 }
7117 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307118
7119 if (found)
7120 continue;
7121
7122 if ((pcl.pcl_list[i] >=
7123 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7124 (pcl.pcl_list[i] <=
7125 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007126 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307127 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007128 }
7129 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307130
7131 return INVALID_CHANNEL_ID;
7132}
7133
7134/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007135 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307136 * @adapter: AP adapter
7137 * @channel: Channel
7138 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007139 * Moves the SAP interface by invoking the function which
7140 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307141 *
7142 * Return: None
7143 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007144void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307145{
Jeff Johnson87251032017-08-29 13:31:11 -07007146 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307147 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007148 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307149
7150 if (!adapter) {
7151 hdd_err("invalid adapter");
7152 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007153 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307154
7155 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7156
7157 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7158 if (!hal_handle) {
7159 hdd_err("invalid HAL handle");
7160 return;
7161 }
7162
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007163 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7164
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307165 hdd_ap_ctx->sapConfig.channel = channel;
7166 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7167 hdd_ap_ctx->sapConfig.ch_width_orig;
7168
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007169 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307170 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7171
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007172 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7173 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307174 hdd_ap_ctx->sapConfig.sec_ch,
7175 &hdd_ap_ctx->sapConfig.ch_params);
7176
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007177 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7178 adapter->sessionId, channel,
7179 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007180}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307181
Jeff Johnson9d295242017-08-29 14:39:48 -07007182int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307183{
7184 struct hdd_external_acs_timer_context *timer_context;
7185
7186 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7187
7188 if (QDF_TIMER_STATE_RUNNING ==
7189 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7190 ap.vendor_acs_timer)) {
7191 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7192 }
7193 timer_context = (struct hdd_external_acs_timer_context *)
7194 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7195 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307196 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307197 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307198 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7199 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307200 hdd_notice("Updated ACS config to nl with reason %d", reason);
7201
7202 return 0;
7203}
7204
Agrawal Ashish467dde42016-09-08 18:44:22 +05307205/**
7206 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7207 * @hdd_ctx: hdd context pointer
7208 *
7209 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7210 * and if ACS is enabled, driver will ask userspace to restart the
7211 * sap. User space on LTE coex indication restart driver.
7212 *
7213 * Return - none
7214 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007215void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307216{
7217 QDF_STATUS status;
7218 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007219 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307220 uint32_t i;
7221 bool found = false;
7222 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007223
Agrawal Ashish467dde42016-09-08 18:44:22 +05307224 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7225 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007226 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307227
7228 if (!adapter_temp) {
7229 hdd_err("adapter is NULL, moving to next one");
7230 goto next_adapater;
7231 }
7232
7233 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7234 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007235 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307236 adapter_temp->device_mode,
7237 adapter_temp->sessionCtx.ap.sapConfig.
7238 acs_cfg.acs_mode);
7239 goto next_adapater;
7240 }
7241
7242 found = false;
7243 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007244 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307245 hdd_ctxt->unsafe_channel_list[i]) {
7246 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007247 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307248 adapter_temp->sessionCtx.ap.operatingChannel);
7249 break;
7250 }
7251 }
7252
7253 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007254 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307255 adapter_temp->sessionCtx.ap.operatingChannel);
7256 goto next_adapater;
7257 }
7258
Kapil Gupta8878ad92017-02-13 11:56:04 +05307259 if (hdd_ctxt->config->vendor_acs_support &&
7260 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7261 hdd_update_acs_timer_reason(adapter_temp,
7262 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7263 goto next_adapater;
7264 } else
7265 restart_chan =
7266 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307267 adapter_temp);
7268 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007269 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307270 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007271 /*
7272 * SAP restart due to unsafe channel. While
7273 * restarting the SAP, make sure to clear
7274 * acs_channel, channel to reset to
7275 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307276 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007277 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307278 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7279 adapter_temp->sessionCtx.ap.sapConfig.channel =
7280 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007281 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307282 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7283 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007284 hdd_debug("driver to start sap: %d",
7285 hdd_ctxt->config->sap_internal_restart);
7286 if (hdd_ctxt->config->sap_internal_restart)
7287 hdd_switch_sap_channel(adapter_temp, restart_chan);
7288 else
7289 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307290 }
7291
7292next_adapater:
7293 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7294 adapter_node = next;
7295 }
7296}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307297
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007298/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007299 * hdd_init_channel_avoidance() - Initialize channel avoidance
7300 * @hdd_ctx: HDD global context
7301 *
7302 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007303 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007304 * down to the lower layers. Then subscribe to subsequent channel
7305 * avoidance events.
7306 *
7307 * Return: None
7308 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007309static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007310{
7311 uint16_t unsafe_channel_count;
7312 int index;
7313
Yuanyuan Liu13738502016-04-06 17:41:37 -07007314 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7315 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007316 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007317 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007318
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007319 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007320 hdd_ctx->unsafe_channel_count);
7321
Anurag Chouhan6d760662016-02-20 16:05:43 +05307322 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007323 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007324
7325 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007326 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007327 hdd_ctx->unsafe_channel_list[index]);
7328
7329 }
7330
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007331}
Dustin Brown676a2322017-08-15 13:16:13 -07007332
Jeff Johnson9d295242017-08-29 14:39:48 -07007333static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007334 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007335{
7336 uint8_t restart_chan;
7337
7338 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7339 if (!restart_chan) {
7340 hdd_alert("fail to restart SAP");
7341 return;
7342 }
7343
7344 /* SAP restart due to unsafe channel. While restarting
7345 * the SAP, make sure to clear acs_channel, channel to
7346 * reset to 0. Otherwise these settings will override
7347 * the ACS while restart.
7348 */
7349 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7350 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7351
7352 hdd_debug("sending coex indication");
7353
7354 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7355 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7356 hdd_switch_sap_channel(adapter, restart_chan);
7357}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007358
7359int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7360 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7361{
7362 uint32_t size;
7363 uint16_t *unsafe_list;
7364 uint16_t chan_count;
7365
7366 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7367 return -EINVAL;
7368
7369 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7370 NUM_CHANNELS);
7371 if (chan_count) {
7372 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7373 unsafe_list = qdf_mem_malloc(size);
7374 if (!unsafe_list) {
7375 hdd_err("No memory for unsafe chan list size%d",
7376 size);
7377 return -ENOMEM;
7378 }
7379 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7380 } else {
7381 unsafe_list = NULL;
7382 }
7383
7384 *local_unsafe_list = unsafe_list;
7385 *local_unsafe_list_count = chan_count;
7386
7387 return 0;
7388}
7389
7390bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7391 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7392{
7393 int i, j;
7394
7395 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7396 return true;
7397 if (local_unsafe_list_count == 0)
7398 return false;
7399 for (i = 0; i < local_unsafe_list_count; i++) {
7400 for (j = 0; j < local_unsafe_list_count; j++)
7401 if (local_unsafe_list[i] ==
7402 hdd_ctx->unsafe_channel_list[j])
7403 break;
7404 if (j >= local_unsafe_list_count)
7405 break;
7406 }
7407 if (i >= local_unsafe_list_count) {
7408 hdd_info("unsafe chan list same");
7409 return false;
7410 }
7411
7412 return true;
7413}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007414#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007415static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007416{
7417}
Dustin Brown676a2322017-08-15 13:16:13 -07007418
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007419static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007420{
7421}
Dustin Brown676a2322017-08-15 13:16:13 -07007422
Jeff Johnson9d295242017-08-29 14:39:48 -07007423static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007424 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007425{
7426 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7427}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007428#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007429
7430/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007431 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7432 * user space
7433 * @frame_ind: Management frame data to be informed.
7434 *
7435 * This function is used to indicate management frame to
7436 * user space
7437 *
7438 * Return: None
7439 *
7440 */
7441void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7442{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007443 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007444 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007445 int i;
7446
Rajeev Kumard004abc2016-02-17 12:09:56 -08007447 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007448 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007449
7450 if (0 != wlan_hdd_validate_context(hdd_ctx))
7451 return;
7452
7453 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7454 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7455 adapter =
7456 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7457 if (adapter)
7458 break;
7459 }
7460 } else {
7461 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7462 frame_ind->sessionId);
7463 }
7464
7465 if ((NULL != adapter) &&
7466 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7467 __hdd_indicate_mgmt_frame(adapter,
7468 frame_ind->frame_len,
7469 frame_ind->frameBuf,
7470 frame_ind->frameType,
7471 frame_ind->rxChan,
7472 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007473}
7474
Kapil Gupta8878ad92017-02-13 11:56:04 +05307475void hdd_acs_response_timeout_handler(void *context)
7476{
7477 struct hdd_external_acs_timer_context *timer_context =
7478 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007479 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007480 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307481 uint8_t reason;
7482
7483 ENTER();
7484 if (!timer_context) {
7485 hdd_err("invlaid timer context");
7486 return;
7487 }
7488 adapter = timer_context->adapter;
7489 reason = timer_context->reason;
7490
7491
7492 if ((!adapter) ||
7493 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7494 hdd_err("invalid adapter or adapter has invalid magic");
7495 return;
7496 }
7497 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7498 if (wlan_hdd_validate_context(hdd_ctx))
7499 return;
7500
7501 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7502 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7503 else
7504 return;
7505
7506 hdd_err("ACS timeout happened for %s reason %d",
7507 adapter->dev->name, reason);
7508 switch (reason) {
7509 /* SAP init case */
7510 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7511 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7512 false);
7513 wlan_hdd_cfg80211_start_acs(adapter);
7514 break;
7515 /* DFS detected on current channel */
7516 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7517 wlan_sap_update_next_channel(
7518 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7519 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7520 adapter->sessionId);
7521 break;
7522 /* LTE coex event on current channel */
7523 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7524 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7525 break;
7526 default:
7527 hdd_info("invalid reason for timer invoke");
7528
7529 }
7530}
7531
Rajeev Kumard004abc2016-02-17 12:09:56 -08007532/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007533 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7534 * @hdd_ctx: HDD context
7535 *
7536 * Disables all the dual mac features like DBS, Agile DFS etc.
7537 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307538 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007539 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007540static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007541{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007542 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307543 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007544
7545 if (!hdd_ctx) {
7546 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307547 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007548 }
7549
7550 cfg.scan_config = 0;
7551 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007552 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007553
7554 hdd_debug("Disabling all dual mac features...");
7555
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007556 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307557 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007558 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7559 return status;
7560 }
7561
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307562 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007563}
7564
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007565static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007566wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007567{
7568 struct policy_mgr_dual_mac_config cfg = {0};
7569 QDF_STATUS status;
7570
7571 if (!hdd_ctx) {
7572 hdd_err("HDD context is NULL");
7573 return QDF_STATUS_E_FAILURE;
7574 }
7575
7576 cfg.scan_config = 0;
7577 cfg.fw_mode_config = 0;
7578 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7579 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7580 hdd_ctx->hdd_psoc, &cfg.scan_config,
7581 &cfg.fw_mode_config,
7582 hdd_ctx->config->dual_mac_feature_disable);
7583
7584 if (status != QDF_STATUS_SUCCESS) {
7585 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7586 status);
7587 return status;
7588 }
7589
7590 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7591 cfg.scan_config, cfg.fw_mode_config);
7592
7593 status = sme_soc_set_dual_mac_config(cfg);
7594 if (status != QDF_STATUS_SUCCESS) {
7595 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7596 return status;
7597 }
7598
7599 return QDF_STATUS_SUCCESS;
7600}
7601
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007602/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007603 * hdd_override_ini_config - Override INI config
7604 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007605 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007606 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007607 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007608 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007609 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007610static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007611{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007612
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007613 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7614 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007615 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007616 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007617 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007618 if (0 == enable_11d || 1 == enable_11d) {
7619 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007620 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007621 }
Leo Chang11545d62016-10-17 14:53:50 -07007622
7623 if (!hdd_ipa_is_present(hdd_ctx))
7624 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007625}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007626
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007627/**
7628 * hdd_set_trace_level_for_each - Set trace level for each INI config
7629 * @hdd_ctx - HDD context
7630 *
7631 * Set trace level for each module based on INI config.
7632 *
7633 * Return: None
7634 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007635static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007636{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307637 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7638 hdd_ctx->config->qdf_trace_enable_wdi);
7639 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7640 hdd_ctx->config->qdf_trace_enable_hdd);
7641 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7642 hdd_ctx->config->qdf_trace_enable_sme);
7643 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7644 hdd_ctx->config->qdf_trace_enable_pe);
7645 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7646 hdd_ctx->config->qdf_trace_enable_wma);
7647 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7648 hdd_ctx->config->qdf_trace_enable_sys);
7649 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7650 hdd_ctx->config->qdf_trace_enable_qdf);
7651 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7652 hdd_ctx->config->qdf_trace_enable_sap);
7653 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7654 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7655 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7656 hdd_ctx->config->qdf_trace_enable_bmi);
7657 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7658 hdd_ctx->config->qdf_trace_enable_cfg);
7659 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7660 hdd_ctx->config->qdf_trace_enable_epping);
7661 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7662 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7663 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007664 hdd_ctx->config->qdf_trace_enable_txrx);
7665 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7666 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307667 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7668 hdd_ctx->config->qdf_trace_enable_htc);
7669 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7670 hdd_ctx->config->qdf_trace_enable_hif);
7671 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7672 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7673 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7674 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007675 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7676 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007677 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7678 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007679 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7680 hdd_ctx->config->qdf_trace_enable_regulatory);
7681
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007682 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007683}
7684
7685/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007686 * hdd_context_init() - Initialize HDD context
7687 * @hdd_ctx: HDD context.
7688 *
7689 * Initialize HDD context along with all the feature specific contexts.
7690 *
7691 * return: 0 on success and errno on failure.
7692 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007693static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007694{
7695 int ret;
7696
7697 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7698 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7699
7700 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307701 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007702
7703 init_completion(&hdd_ctx->mc_sus_event_var);
7704 init_completion(&hdd_ctx->ready_to_suspend);
7705
7706 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307707 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007708 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307709
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007710 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7711
7712 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7713
7714 ret = hdd_scan_context_init(hdd_ctx);
7715 if (ret)
7716 goto list_destroy;
7717
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007718 hdd_rx_wake_lock_create(hdd_ctx);
7719
7720 ret = hdd_sap_context_init(hdd_ctx);
7721 if (ret)
7722 goto scan_destroy;
7723
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007724 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7725
7726 hdd_init_offloaded_packets_ctx(hdd_ctx);
7727
7728 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7729 hdd_ctx->config);
7730 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08007731 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007732
7733 return 0;
7734
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007735sap_destroy:
7736 hdd_sap_context_destroy(hdd_ctx);
7737
7738scan_destroy:
7739 hdd_scan_context_destroy(hdd_ctx);
7740 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007741list_destroy:
7742 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007743
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007744 return ret;
7745}
7746
7747/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307748 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7749 * @hdd_ctx: pointer to hdd context
7750 *
7751 * Return: status of initialization
7752 * 0 - success
7753 * negative value - failure
7754 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007755static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307756{
7757 int ret;
7758
7759 if (!hdd_ctx->config->probe_req_ie_whitelist)
7760 return 0;
7761
7762 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7763 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7764 hdd_ctx->config->probe_req_ie_whitelist = false;
7765 return -EINVAL;
7766 }
7767
7768 /* parse ini string probe req oui */
7769 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7770 if (ret) {
7771 hdd_err("parsing error: disable ie whitelisting");
7772 hdd_ctx->config->probe_req_ie_whitelist = false;
7773 }
7774
7775 return ret;
7776}
7777
7778/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007779 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307780 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007781 *
7782 * Allocate and initialize HDD context. HDD context is allocated as part of
7783 * wiphy allocation and then context is initialized.
7784 *
7785 * Return: HDD context on success and ERR_PTR on failure
7786 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007787static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007788{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307789 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007790 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007791 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007792
7793 ENTER();
7794
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007795 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007796 if (hdd_ctx == NULL) {
7797 ret = -ENOMEM;
7798 goto err_out;
7799 }
7800
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007801 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307802 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007803
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307804 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007805 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007806 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007807 ret = -ENOMEM;
7808 goto err_free_hdd_context;
7809 }
7810
7811 /* Read and parse the qcom_cfg.ini file */
7812 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307813 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307814 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007815 WLAN_INI_FILE);
7816 ret = -EINVAL;
7817 goto err_free_config;
7818 }
7819
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307820 ie_whitelist_attrs_init(hdd_ctx);
7821
Dustin Brown7f939932017-05-18 15:02:17 -07007822 hdd_debug("setting timer multiplier: %u",
7823 hdd_ctx->config->timer_multiplier);
7824 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7825
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007826
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307827 if (hdd_ctx->config->fhostNSOffload)
7828 hdd_ctx->ns_offload_enable = true;
7829
Abhishek Singh5ea86532016-04-27 14:10:53 +05307830 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7831
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007832 hdd_override_ini_config(hdd_ctx);
7833
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007834 ret = hdd_context_init(hdd_ctx);
7835
7836 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007837 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007838
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007839 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307840 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007841
Anurag Chouhan6d760662016-02-20 16:05:43 +05307842 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007843 goto skip_multicast_logging;
7844
7845 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7846
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007847 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7848 if (ret)
7849 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307850
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007851 ret = hdd_init_netlink_services(hdd_ctx);
7852 if (ret)
7853 goto err_deinit_txrx_histogram;
7854
Dustin Brown7b3dea22017-07-10 13:02:47 -07007855 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7856 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307857
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007858skip_multicast_logging:
7859 hdd_set_trace_level_for_each(hdd_ctx);
7860
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007861 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7862
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007863 EXIT();
7864
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007865 return hdd_ctx;
7866
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007867err_deinit_txrx_histogram:
7868 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7869
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007870err_deinit_hdd_context:
7871 hdd_context_deinit(hdd_ctx);
7872
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007873err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307874 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007875
7876err_free_hdd_context:
7877 wiphy_free(hdd_ctx->wiphy);
7878
7879err_out:
7880 return ERR_PTR(ret);
7881}
7882
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007883#ifdef WLAN_OPEN_P2P_INTERFACE
7884/**
7885 * hdd_open_p2p_interface - Open P2P interface
7886 * @hdd_ctx: HDD context
7887 * @rtnl_held: True if RTNL lock held
7888 *
7889 * Open P2P interface during probe. This function called to open the P2P
7890 * interface at probe along with STA interface.
7891 *
7892 * Return: 0 on success and errno on failure
7893 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007894static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007895{
Jeff Johnson9d295242017-08-29 14:39:48 -07007896 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007897 uint8_t *p2p_dev_addr;
7898
7899 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7900 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307901 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007902 hdd_ctx->config->intfMacAddr[0].bytes,
7903 sizeof(tSirMacAddr));
7904
7905 /*
7906 * Generate the P2P Device Address. This consists of
7907 * the device's primary MAC address with the locally
7908 * administered bit set.
7909 */
7910 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7911 } else {
7912 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7913 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007914 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007915 return -ENOSPC;
7916 }
7917
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307918 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307919 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007920 }
7921
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007922 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007923 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007924 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007925
7926 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007927 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007928 return -ENOSPC;
7929 }
7930
7931 return 0;
7932}
7933#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007934static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007935 bool rtnl_held)
7936{
7937 return 0;
7938}
7939#endif
7940
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007941static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007942{
Jeff Johnson9d295242017-08-29 14:39:48 -07007943 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007944 int ret = 0;
7945
7946 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7947 wlan_hdd_get_intf_addr(hdd_ctx),
7948 NET_NAME_UNKNOWN, rtnl_held);
7949 if (adapter == NULL) {
7950 hdd_err("Failed to open 802.11p interface");
7951 ret = -ENOSPC;
7952 }
7953
7954 return ret;
7955}
7956
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007957/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307958 * hdd_start_station_adapter()- Start the Station Adapter
7959 * @adapter: HDD adapter
7960 *
7961 * This function initializes the adapter for the station mode.
7962 *
7963 * Return: 0 on success or errno on failure.
7964 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007965int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307966{
7967 QDF_STATUS status;
7968
7969 ENTER_DEV(adapter->dev);
7970
7971 status = hdd_init_station_mode(adapter);
7972
7973 if (QDF_STATUS_SUCCESS != status) {
7974 hdd_err("Error Initializing station mode: %d", status);
7975 return qdf_status_to_os_return(status);
7976 }
7977
Arun Khandavallifae92942016-08-01 13:31:08 +05307978 hdd_register_tx_flow_control(adapter,
7979 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007980 hdd_tx_resume_cb,
7981 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307982
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307983 EXIT();
7984 return 0;
7985}
7986
7987/**
7988 * hdd_start_ap_adapter()- Start AP Adapter
7989 * @adapter: HDD adapter
7990 *
7991 * This function initializes the adapter for the AP mode.
7992 *
7993 * Return: 0 on success errno on failure.
7994 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007995int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307996{
7997 QDF_STATUS status;
7998
7999 ENTER();
8000
Arun Khandavallicc544b32017-01-30 19:52:16 +05308001 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308002
8003 if (QDF_STATUS_SUCCESS != status) {
8004 hdd_err("Error Initializing the AP mode: %d", status);
8005 return qdf_status_to_os_return(status);
8006 }
8007
Arun Khandavallifae92942016-08-01 13:31:08 +05308008 hdd_register_tx_flow_control(adapter,
8009 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008010 hdd_softap_tx_resume_cb,
8011 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308012
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308013 EXIT();
8014 return 0;
8015}
8016
8017/**
8018 * hdd_start_ftm_adapter()- Start FTM adapter
8019 * @adapter: HDD adapter
8020 *
8021 * This function initializes the adapter for the FTM mode.
8022 *
8023 * Return: 0 on success or errno on failure.
8024 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008025int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308026{
8027 QDF_STATUS qdf_status;
8028
8029 ENTER_DEV(adapter->dev);
8030
8031 qdf_status = hdd_init_tx_rx(adapter);
8032
8033 if (QDF_STATUS_SUCCESS != qdf_status) {
8034 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8035 return qdf_status_to_os_return(qdf_status);
8036 }
8037
8038 return 0;
8039 EXIT();
8040}
8041
8042/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008043 * hdd_open_interfaces - Open all required interfaces
8044 * hdd_ctx: HDD context
8045 * rtnl_held: True if RTNL lock is held
8046 *
8047 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8048 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008049 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008050 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008051static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008052{
Jeff Johnson9d295242017-08-29 14:39:48 -07008053 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008054 int ret;
8055
Ravi Joshia307f632017-07-17 23:41:41 -07008056 /* open monitor mode adapter if con_mode is monitor mode */
8057 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8058 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8059 wlan_hdd_get_intf_addr(hdd_ctx),
8060 NET_NAME_UNKNOWN, rtnl_held);
8061 if (!adapter) {
8062 hdd_err("open adapter failed");
8063 return -ENOSPC;
8064 }
8065 return 0;
8066 }
8067
Jeff Johnson957bc272017-02-02 08:54:48 -08008068 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308069 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008070 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008071
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008072 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008073 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008074 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008075
8076 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008077 return -ENOSPC;
8078
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008079 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8080 adapter->fast_roaming_allowed = true;
8081
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008082 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8083 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008084 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008085
8086 /* Open 802.11p Interface */
8087 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008088 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8089 if (ret)
8090 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008091 }
8092
Jeff Johnson957bc272017-02-02 08:54:48 -08008093 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008094
Jeff Johnson957bc272017-02-02 08:54:48 -08008095err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008096 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008097 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008098}
8099
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008100/**
8101 * hdd_update_country_code - Update country code
8102 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008103 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008104 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008105 *
8106 * Return: 0 on success and errno on failure
8107 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008108static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008109{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008110 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008111 return 0;
8112
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008113 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008114}
8115
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308116#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8117/**
8118 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8119 * @cds_cfg: CDS Configuration
8120 * @hdd_ctx: Pointer to hdd context
8121 *
8122 * Return: none
8123 */
8124static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8125 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008126 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308127{
8128 cds_cfg->tx_flow_stop_queue_th =
8129 hdd_ctx->config->TxFlowStopQueueThreshold;
8130 cds_cfg->tx_flow_start_queue_offset =
8131 hdd_ctx->config->TxFlowStartQueueOffset;
8132}
8133#else
8134static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8135 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008136 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308137{
8138}
8139#endif
8140
8141#ifdef FEATURE_WLAN_RA_FILTERING
8142/**
8143 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8144 * @cds_cfg: CDS Configuration
8145 * @hdd_ctx: Pointer to hdd context
8146 *
8147 * Return: none
8148 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308149static inline void hdd_ra_populate_cds_config(struct cds_config_info *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->ra_ratelimit_interval =
8153 hdd_ctx->config->RArateLimitInterval;
8154 cds_cfg->is_ra_ratelimit_enabled =
8155 hdd_ctx->config->IsRArateLimitEnabled;
8156}
8157#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308158static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008159 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308160{
8161}
8162#endif
8163
8164/**
8165 * hdd_update_cds_config() - API to update cds configuration parameters
8166 * @hdd_ctx: HDD Context
8167 *
8168 * Return: 0 for Success, errno on failure
8169 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008170static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308171{
8172 struct cds_config_info *cds_cfg;
8173
8174 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8175 if (!cds_cfg) {
8176 hdd_err("failed to allocate cds config");
8177 return -ENOMEM;
8178 }
8179
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008180 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008181 if (!hdd_ctx->config->nMaxPsPoll ||
8182 !hdd_ctx->config->enablePowersaveOffload) {
8183 cds_cfg->powersave_offload_enabled =
8184 hdd_ctx->config->enablePowersaveOffload;
8185 } else {
8186 if ((hdd_ctx->config->enablePowersaveOffload ==
8187 PS_QPOWER_NODEEPSLEEP) ||
8188 (hdd_ctx->config->enablePowersaveOffload ==
8189 PS_LEGACY_NODEEPSLEEP))
8190 cds_cfg->powersave_offload_enabled =
8191 PS_LEGACY_NODEEPSLEEP;
8192 else
8193 cds_cfg->powersave_offload_enabled =
8194 PS_LEGACY_DEEPSLEEP;
8195 hdd_info("Qpower disabled in cds config, %d",
8196 cds_cfg->powersave_offload_enabled);
8197 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308198 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8199 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8200 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8201 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8202 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8203
8204 /* Here ol_ini_info is used to store ini status of arp offload
8205 * ns offload and others. Currently 1st bit is used for arp
8206 * off load and 2nd bit for ns offload currently, rest bits are unused
8207 */
8208 if (hdd_ctx->config->fhostArpOffload)
8209 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8210 if (hdd_ctx->config->fhostNSOffload)
8211 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8212
8213 /*
8214 * Copy the DFS Phyerr Filtering Offload status.
8215 * This parameter reflects the value of the
8216 * dfs_phyerr_filter_offload flag as set in the ini.
8217 */
8218 cds_cfg->dfs_phyerr_filter_offload =
8219 hdd_ctx->config->fDfsPhyerrFilterOffload;
8220 if (hdd_ctx->config->ssdp)
8221 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8222
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308223 cds_cfg->force_target_assert_enabled =
8224 hdd_ctx->config->crash_inject_enabled;
8225
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308226 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8227 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8228
8229 cds_cfg->ap_maxoffload_reorderbuffs =
8230 hdd_ctx->config->apMaxOffloadReorderBuffs;
8231
8232 cds_cfg->ap_disable_intrabss_fwd =
8233 hdd_ctx->config->apDisableIntraBssFwd;
8234
8235 cds_cfg->dfs_pri_multiplier =
8236 hdd_ctx->config->dfsRadarPriMultiplier;
8237 cds_cfg->reorder_offload =
8238 hdd_ctx->config->reorderOffloadSupport;
8239
8240 /* IPA micro controller data path offload resource config item */
8241 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008242 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8243 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008244 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008245 hdd_ctx->config->IpaUcTxBufCount);
8246 hdd_ctx->config->IpaUcTxBufCount =
8247 rounddown_pow_of_two(
8248 hdd_ctx->config->IpaUcTxBufCount);
8249 if (!hdd_ctx->config->IpaUcTxBufCount) {
8250 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308251 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008252 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008253 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008254 hdd_ctx->config->IpaUcTxBufCount);
8255 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308256 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8257 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008258 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8259 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008260 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008261 hdd_ctx->config->IpaUcRxIndRingCount);
8262 hdd_ctx->config->IpaUcRxIndRingCount =
8263 rounddown_pow_of_two(
8264 hdd_ctx->config->IpaUcRxIndRingCount);
8265 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8266 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308267 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008268 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008269 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008270 hdd_ctx->config->IpaUcRxIndRingCount);
8271 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308272 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008273 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308274 cds_cfg->uc_tx_partition_base =
8275 hdd_ctx->config->IpaUcTxPartitionBase;
8276 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8277
8278 cds_cfg->ip_tcp_udp_checksum_offload =
8279 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308280 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308281 cds_cfg->ce_classify_enabled =
8282 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008283 cds_cfg->bpf_packet_filter_enable =
8284 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308285 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8286 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8287 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008288 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008289 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008290 cds_cfg->max_msdus_per_rxinorderind =
8291 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008292 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008293 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308294 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8295 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308296 cds_cfg->auto_power_save_fail_mode =
8297 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308298
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308299 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008300 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308301
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308302 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8303 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8304 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008305 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308306 cds_init_ini_config(cds_cfg);
8307 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308308
8309exit:
8310 qdf_mem_free(cds_cfg);
8311 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308312}
8313
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008314/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008315 * hdd_update_user_config() - API to update user configuration
8316 * parameters to obj mgr which are used by multiple components
8317 * @hdd_ctx: HDD Context
8318 *
8319 * Return: 0 for Success, errno on failure
8320 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008321static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008322{
8323 struct wlan_objmgr_psoc_user_config *user_config;
8324
8325 user_config = qdf_mem_malloc(sizeof(*user_config));
8326 if (user_config == NULL) {
8327 hdd_alert("Failed to alloc memory for user_config!");
8328 return -ENOMEM;
8329 }
8330
8331 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8332 user_config->dual_mac_feature_disable =
8333 hdd_ctx->config->dual_mac_feature_disable;
8334 user_config->indoor_channel_support =
8335 hdd_ctx->config->indoor_channel_support;
8336 user_config->is_11d_support_enabled =
8337 hdd_ctx->config->Is11dSupportEnabled;
8338 user_config->is_11h_support_enabled =
8339 hdd_ctx->config->Is11hSupportEnabled;
8340 user_config->optimize_chan_avoid_event =
8341 hdd_ctx->config->goptimize_chan_avoid_event;
8342 user_config->skip_dfs_chnl_in_p2p_search =
8343 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008344 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008345 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8346
8347 qdf_mem_free(user_config);
8348 return 0;
8349}
8350
8351/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008352 * hdd_init_thermal_info - Initialize thermal level
8353 * @hdd_ctx: HDD context
8354 *
8355 * Initialize thermal level at SME layer and set the thermal level callback
8356 * which would be called when a configured thermal threshold is hit.
8357 *
8358 * Return: 0 on success and errno on failure
8359 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008360static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008361{
8362 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308363 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008364
8365 thermal_param.smeThermalMgmtEnabled =
8366 hdd_ctx->config->thermalMitigationEnable;
8367 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8368
Poddar, Siddarth83905022016-04-16 17:56:08 -07008369 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8370 hdd_ctx->config->throttle_dutycycle_level0;
8371 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8372 hdd_ctx->config->throttle_dutycycle_level1;
8373 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8374 hdd_ctx->config->throttle_dutycycle_level2;
8375 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8376 hdd_ctx->config->throttle_dutycycle_level3;
8377
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008378 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8379 hdd_ctx->config->thermalTempMinLevel0;
8380 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8381 hdd_ctx->config->thermalTempMaxLevel0;
8382 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8383 hdd_ctx->config->thermalTempMinLevel1;
8384 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8385 hdd_ctx->config->thermalTempMaxLevel1;
8386 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8387 hdd_ctx->config->thermalTempMinLevel2;
8388 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8389 hdd_ctx->config->thermalTempMaxLevel2;
8390 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8391 hdd_ctx->config->thermalTempMinLevel3;
8392 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8393 hdd_ctx->config->thermalTempMaxLevel3;
8394
8395 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8396
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308397 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308398 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008399
8400 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8401 hdd_set_thermal_level_cb);
8402
8403 return 0;
8404
8405}
8406
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008407#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8408/**
8409 * hdd_hold_rtnl_lock - Hold RTNL lock
8410 *
8411 * Hold RTNL lock
8412 *
8413 * Return: True if held and false otherwise
8414 */
8415static inline bool hdd_hold_rtnl_lock(void)
8416{
8417 rtnl_lock();
8418 return true;
8419}
8420
8421/**
8422 * hdd_release_rtnl_lock - Release RTNL lock
8423 *
8424 * Release RTNL lock
8425 *
8426 * Return: None
8427 */
8428static inline void hdd_release_rtnl_lock(void)
8429{
8430 rtnl_unlock();
8431}
8432#else
8433static inline bool hdd_hold_rtnl_lock(void) { return false; }
8434static inline void hdd_release_rtnl_lock(void) { }
8435#endif
8436
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008437#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008438
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308439/* MAX iwpriv command support */
8440#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308441#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308442#define MAX_PKTLOG_SIZE 16
8443
8444/**
8445 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8446 * @hdd_ctx: hdd context
8447 * @set_value2: pktlog buffer size value
8448 *
8449 *
8450 * Return: 0 for success or error.
8451 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008452static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308453{
8454 struct sir_wifi_start_log start_log = { 0 };
8455 QDF_STATUS status;
8456
8457 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8458 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8459 start_log.ini_triggered = cds_is_packet_log_enabled();
8460 start_log.user_triggered = 1;
8461 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308462 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308463
8464 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8465 if (!QDF_IS_STATUS_SUCCESS(status)) {
8466 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8467 EXIT();
8468 return -EINVAL;
8469 }
8470
8471 return 0;
8472}
8473
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008474/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308475 * hdd_pktlog_clear_buff() - clear pktlog buffer
8476 * @hdd_ctx: hdd context
8477 *
8478 * Return: 0 for success or error.
8479 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008480static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308481{
8482 struct sir_wifi_start_log start_log;
8483 QDF_STATUS status;
8484
8485 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8486 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8487 start_log.ini_triggered = cds_is_packet_log_enabled();
8488 start_log.user_triggered = 1;
8489 start_log.size = 0;
8490 start_log.is_pktlog_buff_clear = true;
8491
8492 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8493 if (!QDF_IS_STATUS_SUCCESS(status)) {
8494 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8495 EXIT();
8496 return -EINVAL;
8497 }
8498
8499 return 0;
8500}
8501
8502
8503/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008504 * hdd_process_pktlog_command() - process pktlog command
8505 * @hdd_ctx: hdd context
8506 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308507 * @set_value2: pktlog buffer size value
8508 *
8509 * This function process pktlog command.
8510 * set_value2 only matters when set_value is 3 (set buff size)
8511 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008512 *
8513 * Return: 0 for success or error.
8514 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008515int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308516 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008517{
8518 int ret;
8519 bool enable;
8520 uint8_t user_triggered = 0;
8521
8522 ret = wlan_hdd_validate_context(hdd_ctx);
8523 if (0 != ret)
8524 return ret;
8525
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008526 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008527
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308528 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008529 hdd_err("invalid pktlog value %d", set_value);
8530 return -EINVAL;
8531 }
8532
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308533 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8534 if (set_value2 <= 0) {
8535 hdd_err("invalid pktlog size %d", set_value2);
8536 return -EINVAL;
8537 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8538 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8539 return -EINVAL;
8540 }
8541 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308542 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8543 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308544 }
8545
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008546 /*
8547 * set_value = 0 then disable packetlog
8548 * set_value = 1 enable packetlog forcefully
8549 * set_vlaue = 2 then disable packetlog if disabled through ini or
8550 * enable packetlog with AUTO type.
8551 */
8552 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8553 true : false;
8554
8555 if (1 == set_value) {
8556 enable = true;
8557 user_triggered = 1;
8558 }
8559
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308560 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008561}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008562
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008563/**
8564 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8565 * @hdd_ctx: HDD context
8566 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308567 * @user_triggered: triggered through iwpriv
8568 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008569 *
8570 * Return: 0 on success; error number otherwise
8571 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008572int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308573 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008574{
8575 struct sir_wifi_start_log start_log;
8576 QDF_STATUS status;
8577
8578 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8579 start_log.verbose_level =
8580 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008581 start_log.ini_triggered = cds_is_packet_log_enabled();
8582 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308583 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308584 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308585 /*
8586 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8587 * commands. Host uses this flag to decide whether to send pktlog
8588 * disable command to fw without sending pktlog enable command
8589 * previously. For eg, If vendor sends pktlog disable command without
8590 * sending pktlog enable command, then host discards the packet
8591 * but for iwpriv command, host will send it to fw.
8592 */
8593 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008594 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8595 if (!QDF_IS_STATUS_SUCCESS(status)) {
8596 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8597 EXIT();
8598 return -EINVAL;
8599 }
8600
8601 return 0;
8602}
8603#endif /* REMOVE_PKT_LOG */
8604
Komal Seelam92fff912016-03-24 11:51:41 +05308605/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008606 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8607 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308608 * @dev: Device Pointer
8609 * @num: Number of Valid Mac address
8610 *
8611 * Return: Pointer to MAC address buffer
8612 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008613static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8614 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308615{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008616 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308617}
Komal Seelam92fff912016-03-24 11:51:41 +05308618
8619/**
8620 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8621 * @hdd_ctx: HDD Context
8622 * @num: Number of random mac addresses needed
8623 *
8624 * Generate random addresses using bit manipulation on the base mac address
8625 *
8626 * Return: None
8627 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008628void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308629{
8630 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8631 uint32_t iter;
8632 struct hdd_config *ini = hdd_ctx->config;
8633 uint8_t *buf = NULL;
8634 uint8_t macaddr_b3, tmp_br3;
8635 uint8_t *src = ini->intfMacAddr[0].bytes;
8636
8637 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8638 buf = ini->intfMacAddr[iter].bytes;
8639 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8640 macaddr_b3 = buf[3];
8641 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8642 INTF_MACADDR_MASK;
8643 macaddr_b3 += tmp_br3;
8644 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8645 buf[0] |= 0x02;
8646 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008647 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308648 }
8649}
8650
8651/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008652 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308653 * @hdd_ctx: HDD Context
8654 *
8655 * API to get mac addresses from platform driver and update the driver
8656 * structures and configure FW with the base mac address.
8657 * Return: int
8658 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008659static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308660{
8661 uint32_t no_of_mac_addr, iter;
8662 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8663 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8664 uint8_t *addr, *buf;
8665 struct device *dev = hdd_ctx->parent_dev;
8666 struct hdd_config *ini = hdd_ctx->config;
8667 tSirMacAddr mac_addr;
8668 QDF_STATUS status;
8669
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008670 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308671
8672 if (no_of_mac_addr == 0 || !addr) {
8673 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8674 return -EINVAL;
8675 }
8676
8677 if (no_of_mac_addr > max_mac_addr)
8678 no_of_mac_addr = max_mac_addr;
8679
8680 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8681
8682 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8683 buf = ini->intfMacAddr[iter].bytes;
8684 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008685 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308686 }
8687
8688 status = sme_set_custom_mac_addr(mac_addr);
8689
8690 if (!QDF_IS_STATUS_SUCCESS(status))
8691 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008692
Komal Seelam92fff912016-03-24 11:51:41 +05308693 if (no_of_mac_addr < max_mac_addr)
8694 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8695 no_of_mac_addr);
8696 return 0;
8697}
8698
8699/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008700 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8701 * @hdd_ctx: HDD Context
8702 *
8703 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8704 * will generate its own MAC and update it to FW.
8705 *
8706 * Return: 0 for success
8707 * Non-zero error code for failure
8708 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008709static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008710{
8711 tSirMacAddr customMacAddr;
8712 QDF_STATUS status;
8713
8714 qdf_mem_copy(&customMacAddr,
8715 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8716 sizeof(tSirMacAddr));
8717 status = sme_set_custom_mac_addr(customMacAddr);
8718 if (!QDF_IS_STATUS_SUCCESS(status))
8719 return -EAGAIN;
8720 return 0;
8721}
8722
8723/**
Komal Seelam92fff912016-03-24 11:51:41 +05308724 * hdd_initialize_mac_address() - API to get wlan mac addresses
8725 * @hdd_ctx: HDD Context
8726 *
8727 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8728 * is provisioned with mac addresses, driver uses it, else it will use
8729 * wlan_mac.bin to update HW MAC addresses.
8730 *
8731 * Return: None
8732 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008733static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308734{
8735 QDF_STATUS status;
8736 int ret;
8737
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008738 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308739 if (ret == 0)
8740 return;
8741
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008742 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8743 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308744
8745 status = hdd_update_mac_config(hdd_ctx);
8746
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008747 if (QDF_IS_STATUS_SUCCESS(status))
8748 return;
8749
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008750 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8751 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008752
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008753 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008754 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008755 if (ret != 0) {
8756 hdd_err("MAC address out-of-sync, ret:%d", ret);
8757 QDF_ASSERT(ret);
8758 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008759 }
Komal Seelam92fff912016-03-24 11:51:41 +05308760}
8761
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008762static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008763{
8764 int vdev_id = 0;
8765 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8766 int value = hdd_ctx->config->smart_chainmask_enabled;
8767 int vpdev = PDEV_CMD;
8768 int ret;
8769
Naveen Rawat247a8682017-06-05 15:00:31 -07008770 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008771 if (ret)
8772 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8773
8774 return ret;
8775}
8776
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008777static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008778{
8779 int vdev_id = 0;
8780 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8781 int value = hdd_ctx->config->alternative_chainmask_enabled;
8782 int vpdev = PDEV_CMD;
8783 int ret;
8784
Naveen Rawat247a8682017-06-05 15:00:31 -07008785 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008786 if (ret)
8787 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8788 ret);
8789
8790 return ret;
8791}
8792
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008793static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008794{
8795 int vdev_id = 0;
8796 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8797 int value = hdd_ctx->config->ani_enabled;
8798 int vpdev = PDEV_CMD;
8799 int ret;
8800
Naveen Rawat247a8682017-06-05 15:00:31 -07008801 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008802 if (ret)
8803 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8804
8805 return ret;
8806}
8807
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008808/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008809 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8810 * @hdd_ctx: HDD context
8811 *
8812 * Pre configurations to be done at lower layer before calling cds enable.
8813 *
8814 * Return: 0 on success and errno on failure.
8815 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008816static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008817{
8818 int ret;
8819 QDF_STATUS status;
8820 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008821 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008822
Leo Changfdb45c32016-10-28 11:09:23 -07008823 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008824 /*
8825 * Set 802.11p config
8826 * TODO-OCB: This has been temporarily added here to ensure this
8827 * parameter is set in CSR when we init the channel list. This should
8828 * be removed once the 5.9 GHz channels are added to the regulatory
8829 * domain.
8830 */
8831 hdd_set_dot11p_config(hdd_ctx);
8832
8833 /*
8834 * Note that the cds_pre_enable() sequence triggers the cfg download.
8835 * The cfg download must occur before we update the SME config
8836 * since the SME config operation must access the cfg database
8837 */
8838 status = hdd_set_sme_config(hdd_ctx);
8839
8840 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008841 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008842 ret = qdf_status_to_os_return(status);
8843 goto out;
8844 }
8845
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008846 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8847 if (QDF_STATUS_SUCCESS != status) {
8848 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8849 ret = qdf_status_to_os_return(status);
8850 goto out;
8851 }
8852
Naveen Rawat247a8682017-06-05 15:00:31 -07008853 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008854 hdd_ctx->config->tx_chain_mask_1ss,
8855 PDEV_CMD);
8856 if (0 != ret) {
8857 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8858 goto out;
8859 }
8860
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008861 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8862 if (ret)
8863 goto out;
8864
8865 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8866 if (ret)
8867 goto out;
8868
Jeff Johnson12a744b2017-04-04 08:19:37 -07008869 ret = hdd_set_ani_enabled(hdd_ctx);
8870 if (ret)
8871 goto out;
8872
Naveen Rawat247a8682017-06-05 15:00:31 -07008873 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008874 hdd_ctx->config->arp_ac_category,
8875 PDEV_CMD);
8876 if (0 != ret) {
8877 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8878 hdd_ctx->config->arp_ac_category, ret);
8879 goto out;
8880 }
8881
8882
Prashanth Bhatta07998752016-04-28 12:35:33 -07008883 status = hdd_set_sme_chan_list(hdd_ctx);
8884 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008885 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008886 ret = qdf_status_to_os_return(status);
8887 goto out;
8888 }
8889
8890 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008891 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008892 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008893 ret = -EINVAL;
8894 goto out;
8895 }
8896
Prashanth Bhatta07998752016-04-28 12:35:33 -07008897 /*
8898 * Set the MAC Address Currently this is used by HAL to add self sta.
8899 * Remove this once self sta is added as part of session open.
8900 */
8901 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8902 hdd_ctx->config->intfMacAddr[0].bytes,
8903 sizeof(hdd_ctx->config->intfMacAddr[0]));
8904
8905 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8906 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8907 hal_status, hal_status);
8908 ret = -EINVAL;
8909 goto out;
8910 }
8911
8912 hdd_init_channel_avoidance(hdd_ctx);
8913
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308914 /* update enable sap mandatory chan list */
8915 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8916 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008917out:
8918 return ret;
8919}
8920
8921/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008922 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8923 * @context_ptr - hdd context pointer
8924 * @event_ptr - event structure pointer
8925 *
8926 * This is the p2p listen offload stop event handler, it sends vendor
8927 * event back to supplicant to notify the stop reason.
8928 *
8929 * Return: None
8930 */
8931static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8932 void *event_ptr)
8933{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008934 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008935 struct sir_p2p_lo_event *evt = event_ptr;
8936 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008937 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008938
8939 ENTER();
8940
8941 if (hdd_ctx == NULL) {
8942 hdd_err("Invalid HDD context pointer");
8943 return;
8944 }
8945
Peng Xu5c682812017-08-06 07:39:13 -07008946 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8947 if (!adapter) {
8948 hdd_err("Cannot find adapter by vdev_id = %d",
8949 evt->vdev_id);
8950 return;
8951 }
8952
Peng Xu8fdaa492016-06-22 10:20:47 -07008953 vendor_event =
8954 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008955 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008956 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8957 GFP_KERNEL);
8958
8959 if (!vendor_event) {
8960 hdd_err("cfg80211_vendor_event_alloc failed");
8961 return;
8962 }
8963
8964 if (nla_put_u32(vendor_event,
8965 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8966 evt->reason_code)) {
8967 hdd_err("nla put failed");
8968 kfree_skb(vendor_event);
8969 return;
8970 }
8971
8972 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008973 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8974 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008975}
8976
8977/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308978 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8979 * @hdd_ctx: HDD context
8980 *
8981 * This function sends the adaptive dwell time config configuration to the
8982 * firmware via WMA
8983 *
8984 * Return: 0 - success, < 0 - failure
8985 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008986static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308987{
8988 QDF_STATUS status;
8989 struct adaptive_dwelltime_params dwelltime_params;
8990
8991 dwelltime_params.is_enabled =
8992 hdd_ctx->config->adaptive_dwell_mode_enabled;
8993 dwelltime_params.dwelltime_mode =
8994 hdd_ctx->config->global_adapt_dwelltime_mode;
8995 dwelltime_params.lpf_weight =
8996 hdd_ctx->config->adapt_dwell_lpf_weight;
8997 dwelltime_params.passive_mon_intval =
8998 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8999 dwelltime_params.wifi_act_threshold =
9000 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9001
9002 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9003 &dwelltime_params);
9004
9005 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9006 if (!QDF_IS_STATUS_SUCCESS(status)) {
9007 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9008 return -EAGAIN;
9009 }
9010 return 0;
9011}
9012
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009013int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309014{
9015 QDF_STATUS status;
9016 struct wmi_dbs_scan_sel_params dbs_scan_params;
9017 uint32_t i = 0;
9018 uint8_t count = 0, numentries = 0;
9019 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9020 * CDS_DBS_SCAN_CLIENTS_MAX];
9021
9022 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009023 if (hdd_ctx->config->dual_mac_feature_disable ==
9024 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309025 return -EINVAL;
9026
9027 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9028 dbs_scan_config, &numentries,
9029 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9030 * CDS_DBS_SCAN_CLIENTS_MAX));
9031
9032 hdd_info("numentries %hu", numentries);
9033 if (!numentries) {
9034 hdd_info("Donot send scan_selection_config");
9035 return 0;
9036 }
9037
9038 /* hdd_set_fw_log_params */
9039 dbs_scan_params.num_clients = 0;
9040 while (count < (numentries - 2)) {
9041 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9042 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9043 dbs_scan_params.num_non_dbs_scans[i] =
9044 dbs_scan_config[count + 2];
9045 dbs_scan_params.num_clients++;
9046 hdd_debug("module:%d NDS:%d NNDS:%d",
9047 dbs_scan_params.module_id[i],
9048 dbs_scan_params.num_dbs_scans[i],
9049 dbs_scan_params.num_non_dbs_scans[i]);
9050 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9051 i++;
9052 }
9053
9054 dbs_scan_params.pdev_id = 0;
9055
9056 hdd_debug("clients:%d pdev:%d",
9057 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9058
9059 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9060 &dbs_scan_params);
9061 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9062 if (!QDF_IS_STATUS_SUCCESS(status)) {
9063 hdd_err("Failed to send DBS Scan selection configuration!");
9064 return -EAGAIN;
9065 }
9066 return 0;
9067}
9068
Arun Khandavallid4349a92016-07-25 11:10:43 +05309069#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9070/**
9071 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9072 * @hdd_ctx: HDD context
9073 *
9074 * Set auto shutdown callback to get indications from firmware to indicate
9075 * userspace to shutdown WLAN after a configured amount of inactivity.
9076 *
9077 * Return: 0 on success and errno on failure.
9078 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009079static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309080{
9081 QDF_STATUS status;
9082
9083 if (!hdd_ctx->config->WlanAutoShutdown)
9084 return 0;
9085
9086 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9087 wlan_hdd_auto_shutdown_cb);
9088 if (status != QDF_STATUS_SUCCESS)
9089 hdd_err("Auto shutdown feature could not be enabled: %d",
9090 status);
9091
9092 return qdf_status_to_os_return(status);
9093}
9094#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009095static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309096{
9097 return 0;
9098}
9099#endif
9100
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009101static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009102{
9103 QDF_STATUS status = QDF_STATUS_SUCCESS;
9104
9105 switch (hdd_ctx->config->dual_mac_feature_disable) {
9106 case DISABLE_DBS_CXN_AND_SCAN:
9107 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9108 if (status != QDF_STATUS_SUCCESS)
9109 hdd_err("Failed to disable dual mac features");
9110 break;
9111 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9112 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9113 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9114 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9115 if (status != QDF_STATUS_SUCCESS)
9116 hdd_err("Failed to set dbs scan and fw mode config");
9117 break;
9118 default:
9119 break;
9120 }
9121
9122 return status;
9123}
9124
Arun Khandavallid4349a92016-07-25 11:10:43 +05309125/**
9126 * hdd_features_init() - Init features
9127 * @hdd_ctx: HDD context
9128 * @adapter: Primary adapter context
9129 *
9130 * Initialize features and their feature context after WLAN firmware is up.
9131 *
9132 * Return: 0 on success and errno on failure.
9133 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009134static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309135{
9136 tSirTxPowerLimit hddtxlimit;
9137 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309138 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309139 int ret;
9140
9141 ENTER();
9142
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009143 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309144 if (ret) {
9145 hdd_err("Failed to update country code: %d", ret);
9146 goto out;
9147 }
9148
9149 /* FW capabilities received, Set the Dot11 mode */
9150 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009151 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9152 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309153
Arun Khandavallid4349a92016-07-25 11:10:43 +05309154
9155 if (hdd_ctx->config->fIsImpsEnabled)
9156 hdd_set_idle_ps_config(hdd_ctx, true);
9157 else
9158 hdd_set_idle_ps_config(hdd_ctx, false);
9159
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309160 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009161 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309162
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309163 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9164 hdd_warn("Error in setting Voltage Corner mode config to FW");
9165
Arun Khandavallid4349a92016-07-25 11:10:43 +05309166 if (hdd_lro_init(hdd_ctx))
9167 hdd_err("Unable to initialize LRO in fw");
9168
9169 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9170 hdd_err("Unable to send adaptive dwelltime setting to FW");
9171
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309172 if (hdd_dbs_scan_selection_init(hdd_ctx))
9173 hdd_err("Unable to send DBS scan selection setting to FW");
9174
Arun Khandavallid4349a92016-07-25 11:10:43 +05309175 ret = hdd_init_thermal_info(hdd_ctx);
9176 if (ret) {
9177 hdd_err("Error while initializing thermal information");
9178 goto deregister_frames;
9179 }
9180
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309181 if (cds_is_packet_log_enabled())
9182 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9183
Arun Khandavallid4349a92016-07-25 11:10:43 +05309184 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9185 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9186 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9187 if (!QDF_IS_STATUS_SUCCESS(status))
9188 hdd_err("Error setting txlimit in sme: %d", status);
9189
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009190 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309191
Arun Khandavallid4349a92016-07-25 11:10:43 +05309192 ret = hdd_register_cb(hdd_ctx);
9193 if (ret) {
9194 hdd_err("Failed to register HDD callbacks!");
9195 goto deregister_frames;
9196 }
9197
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009198 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9199 if (!QDF_IS_STATUS_SUCCESS(status)) {
9200 hdd_err("Failed to set dbs scan and fw mode cfg");
9201 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309202 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009203
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309204 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9205 status = sme_enable_disable_chanavoidind_event(
9206 hdd_ctx->hHal, 0);
9207 if (!QDF_IS_STATUS_SUCCESS(status)) {
9208 hdd_err("Failed to disable Chan Avoidance Indication");
9209 goto deregister_cb;
9210 }
9211 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309212
Manjeet Singha9cae432017-02-28 11:58:22 +05309213 if (hdd_ctx->config->enable_5g_band_pref) {
9214 band_pref_params.rssi_boost_threshold_5g =
9215 hdd_ctx->config->rssi_boost_threshold_5g;
9216 band_pref_params.rssi_boost_factor_5g =
9217 hdd_ctx->config->rssi_boost_factor_5g;
9218 band_pref_params.max_rssi_boost_5g =
9219 hdd_ctx->config->max_rssi_boost_5g;
9220 band_pref_params.rssi_penalize_threshold_5g =
9221 hdd_ctx->config->rssi_penalize_threshold_5g;
9222 band_pref_params.rssi_penalize_factor_5g =
9223 hdd_ctx->config->rssi_penalize_factor_5g;
9224 band_pref_params.max_rssi_penalize_5g =
9225 hdd_ctx->config->max_rssi_penalize_5g;
9226 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9227 }
9228
Arun Khandavallid4349a92016-07-25 11:10:43 +05309229 /* register P2P Listen Offload event callback */
9230 if (wma_is_p2p_lo_capable())
9231 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9232 wlan_hdd_p2p_lo_event_callback);
9233
9234 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9235
9236 if (ret)
9237 goto deregister_cb;
9238
9239 EXIT();
9240 return 0;
9241
9242deregister_cb:
9243 hdd_deregister_cb(hdd_ctx);
9244deregister_frames:
9245 wlan_hdd_cfg80211_deregister_frames(adapter);
9246out:
9247 return -EINVAL;
9248
9249}
9250
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009251/**
9252 * hdd_features_deinit() - Deinit features
9253 * @hdd_ctx: HDD context
9254 *
9255 * De-Initialize features and their feature context.
9256 *
9257 * Return: none.
9258 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009259static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009260{
9261 wlan_hdd_tsf_deinit(hdd_ctx);
9262}
9263
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309264/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009265 * hdd_register_bcn_cb() - register scan beacon callback
9266 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309267 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009268 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309269 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009270static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309271{
9272 QDF_STATUS status;
9273
9274 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9275 wlan_cfg80211_inform_bss_frame,
9276 SCAN_CB_TYPE_INFORM_BCN);
9277 if (!QDF_IS_STATUS_SUCCESS(status)) {
9278 hdd_err("failed with status code %08d [x%08x]",
9279 status, status);
9280 return status;
9281 }
9282
9283 return QDF_STATUS_SUCCESS;
9284}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309285
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309286/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309287 * hdd_configure_cds() - Configure cds modules
9288 * @hdd_ctx: HDD context
9289 * @adapter: Primary adapter context
9290 *
9291 * Enable Cds modules after WLAN firmware is up.
9292 *
9293 * Return: 0 on success and errno on failure.
9294 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009295int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309296{
9297 int ret;
9298 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309299 int set_value;
9300 uint32_t num_abg_tx_chains = 0;
9301 uint32_t num_11b_tx_chains = 0;
9302 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009303 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309304
9305 if (hdd_ctx->config->sifs_burst_duration) {
9306 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9307 hdd_ctx->config->sifs_burst_duration;
9308
9309 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9310 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9311 set_value, PDEV_CMD);
9312 }
9313
9314 if (hdd_ctx->config->is_force_1x1)
9315 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9316 1, PDEV_CMD);
9317 /* set chip power save failure detected callback */
9318 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9319 hdd_chip_pwr_save_fail_detected_cb);
9320
9321 if (hdd_ctx->config->max_mpdus_inampdu) {
9322 set_value = hdd_ctx->config->max_mpdus_inampdu;
9323 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9324 set_value, PDEV_CMD);
9325 }
9326
9327 if (hdd_ctx->config->enable_rts_sifsbursting) {
9328 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9329 sme_cli_set_command(0,
9330 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9331 set_value, PDEV_CMD);
9332 }
9333
9334 if (hdd_ctx->config->sap_get_peer_info) {
9335 set_value = hdd_ctx->config->sap_get_peer_info;
9336 sme_cli_set_command(0,
9337 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9338 set_value, PDEV_CMD);
9339 }
9340
9341 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9342 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9343 if (!hdd_ctx->config->enable2x2) {
9344 if (num_11b_tx_chains > 1)
9345 num_11b_tx_chains = 1;
9346 if (num_11ag_tx_chains > 1)
9347 num_11ag_tx_chains = 1;
9348 }
9349 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9350 num_11b_tx_chains);
9351 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9352 num_11ag_tx_chains);
9353 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9354 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309355
9356 ret = hdd_pre_enable_configure(hdd_ctx);
9357 if (ret) {
9358 hdd_err("Failed to pre-configure cds");
9359 goto out;
9360 }
9361
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009362 /* Always get latest IPA resources allocated from cds_open and configure
9363 * IPA module before configuring them to FW. Sequence required as crash
9364 * observed otherwise.
9365 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009366 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9367 hdd_err("Failed to setup pipes");
9368 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009369 }
9370
Arun Khandavallifae92942016-08-01 13:31:08 +05309371 /*
9372 * Start CDS which starts up the SME/MAC/HAL modules and everything
9373 * else
9374 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009375 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309376
9377 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009378 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309379 goto out;
9380 }
9381
9382 status = hdd_post_cds_enable_config(hdd_ctx);
9383 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009384 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009385 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309386 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309387 status = hdd_register_bcn_cb(hdd_ctx);
9388 if (!QDF_IS_STATUS_SUCCESS(status)) {
9389 hdd_alert("hdd_post_cds_enable_config failed");
9390 goto cds_disable;
9391 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309392
9393 ret = hdd_features_init(hdd_ctx, adapter);
9394 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009395 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309396
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009397 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009398 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009399 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9400 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009401 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009402 goto cds_disable;
9403 }
9404
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309405 if (hdd_enable_egap(hdd_ctx))
9406 hdd_debug("enhance green ap is not enabled");
9407
Nachiket Kukadedd302662017-07-13 17:31:44 +05309408 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9409 hdd_debug("Failed to set wow pulse");
9410
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309411 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9412 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9413
Arun Khandavallifae92942016-08-01 13:31:08 +05309414 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009415
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009416cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009417 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009418
Arun Khandavallifae92942016-08-01 13:31:08 +05309419out:
9420 return -EINVAL;
9421}
9422
9423/**
9424 * hdd_deconfigure_cds() -De-Configure cds
9425 * @hdd_ctx: HDD context
9426 *
9427 * Deconfigure Cds modules before WLAN firmware is down.
9428 *
9429 * Return: 0 on success and errno on failure.
9430 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009431static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309432{
9433 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009434 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309435
9436 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009437
9438 /* De-init features */
9439 hdd_features_deinit(hdd_ctx);
9440
Arun Khandavallifae92942016-08-01 13:31:08 +05309441 /* De-register the SME callbacks */
9442 hdd_deregister_cb(hdd_ctx);
9443
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009444 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309445 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9446 hdd_err("Failed to Disable the CDS Modules! :%d",
9447 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009448 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309449 }
9450
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309451 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9452 hdd_err("Failed to disconnect pipes");
9453 ret = -EINVAL;
9454 }
9455
Arun Khandavallifae92942016-08-01 13:31:08 +05309456 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009457 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309458}
9459
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009460#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9461static void hdd_deregister_policy_manager_callback(
9462 struct wlan_objmgr_psoc *psoc)
9463{
9464 if (QDF_STATUS_SUCCESS !=
9465 policy_mgr_deregister_hdd_cb(psoc)) {
9466 hdd_err("HDD callback deregister with policy manager failed");
9467 }
9468}
9469#else
9470static void hdd_deregister_policy_manager_callback(
9471 struct wlan_objmgr_psoc *psoc)
9472{
9473}
9474#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309475
9476/**
9477 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9478 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009479 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309480 *
9481 * This function maintains the driver state machine it will be invoked from
9482 * exit, shutdown and con_mode change handler. Depending on the driver state
9483 * shall perform the stopping/closing of the modules.
9484 *
9485 * Return: 0 for success; non-zero for failure
9486 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009487int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309488{
9489 void *hif_ctx;
9490 qdf_device_t qdf_ctx;
9491 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309492 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009493 bool is_idle_stop = !cds_is_driver_unloading() &&
9494 !cds_is_driver_recovering();
9495 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309496
9497 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009498 hdd_alert("stop WLAN module: entering driver status=%d",
9499 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309500
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009501 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9502
Arun Khandavallifae92942016-08-01 13:31:08 +05309503 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9504 if (!qdf_ctx) {
9505 hdd_err("QDF device context NULL");
9506 return -EINVAL;
9507 }
9508
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309509 mutex_lock(&hdd_ctx->iface_change_lock);
9510 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309511
Dustin Brown70111822017-03-30 15:31:40 -07009512 active_threads = cds_return_external_threads_count();
9513 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009514 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009515 active_threads, hdd_ctx->isWiphySuspended);
9516
9517 cds_print_external_threads();
9518
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009519 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009520 mutex_unlock(&hdd_ctx->iface_change_lock);
9521 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009522 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309523 hdd_prevent_suspend_timeout(
9524 hdd_ctx->config->iface_change_wait_time,
9525 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009526 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009527 return 0;
9528 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009529 }
9530
Arun Khandavallifae92942016-08-01 13:31:08 +05309531 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9532
9533 switch (hdd_ctx->driver_status) {
9534 case DRIVER_MODULES_UNINITIALIZED:
9535 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309536 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309537 case DRIVER_MODULES_CLOSED:
9538 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309539 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309540 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309541 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309542 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009543 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309544 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309545 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309546 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009547 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309548 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9549 break;
9550 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009551 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309552 break;
9553 default:
9554 hdd_err("Trying to stop wlan in a wrong state: %d",
9555 hdd_ctx->driver_status);
9556 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309557 ret = -EINVAL;
9558 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309559 }
9560
Rajeev Kumarbe021242017-02-16 16:12:23 -08009561 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309562 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9563 hdd_err("Failed to process post CDS disable Modules! :%d",
9564 qdf_status);
9565 ret = -EINVAL;
9566 QDF_ASSERT(0);
9567 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07009568
9569 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
9570 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9571 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
9572 ret = -EINVAL;
9573 QDF_ASSERT(0);
9574 }
9575
Jeff Johnsone4b14592017-09-13 14:23:33 -07009576 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309577 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009578 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309579 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309580 QDF_ASSERT(0);
9581 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009582
Arun Khandavallifae92942016-08-01 13:31:08 +05309583 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9584 if (!hif_ctx) {
9585 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309586 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309587 }
9588
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309589 hdd_runtime_suspend_context_deinit(hdd_ctx);
9590
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309591 if (hdd_ctx->target_hw_name) {
9592 qdf_mem_free(hdd_ctx->target_hw_name);
9593 hdd_ctx->target_hw_name = NULL;
9594 }
9595
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309596 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309597
9598 ol_cds_free();
9599
Dustin Brown70111822017-03-30 15:31:40 -07009600 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309601 ret = pld_power_off(qdf_ctx->dev);
9602 if (ret)
9603 hdd_err("CNSS power down failed put device into Low power mode:%d",
9604 ret);
9605 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309606
9607 /* Once the firmware sequence is completed reset this flag */
9608 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309609 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009610 /*
9611 * Reset total mac phy during module stop such that during
9612 * next module start same psoc is used to populate new service
9613 * ready data
9614 */
9615 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309616
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309617done:
9618 hdd_ctx->stop_modules_in_progress = false;
9619 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07009620 hdd_alert("stop WLAN module: exit driver status=%d",
9621 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309622 EXIT();
9623
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309624 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309625
9626}
9627
9628/**
9629 * hdd_iface_change_callback() - Function invoked when stop modules expires
9630 * @priv: pointer to hdd context
9631 *
9632 * This function is invoked when the timer waiting for the interface change
9633 * expires, it shall cut-down the power to wlan and stop all the modules.
9634 *
9635 * Return: void
9636 */
9637static void hdd_iface_change_callback(void *priv)
9638{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009639 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309640 int ret;
9641 int status = wlan_hdd_validate_context(hdd_ctx);
9642
9643 if (status)
9644 return;
9645
9646 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009647 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009648 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309649 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009650 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309651 EXIT();
9652}
9653
9654/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309655 * hdd_state_info_dump() - prints state information of hdd layer
9656 * @buf: buffer pointer
9657 * @size: size of buffer to be filled
9658 *
9659 * This function is used to dump state information of hdd layer
9660 *
9661 * Return: None
9662 */
9663static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9664{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009665 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309666 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9667 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009668 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009669 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309670 uint16_t len = 0;
9671 char *buf = *buf_ptr;
9672
9673 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9674 if (!hdd_ctx) {
9675 hdd_err("Failed to get hdd context ");
9676 return;
9677 }
9678
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009679 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309680
9681 len += scnprintf(buf + len, *size - len,
9682 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9683 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009684 "\n is_scheduler_suspended %d",
9685 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309686
9687 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9688
9689 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009690 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309691 if (adapter->dev)
9692 len += scnprintf(buf + len, *size - len,
9693 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009694 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309695 "\n device_mode: %d", adapter->device_mode);
9696 switch (adapter->device_mode) {
9697 case QDF_STA_MODE:
9698 case QDF_P2P_CLIENT_MODE:
9699 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9700 len += scnprintf(buf + len, *size - len,
9701 "\n connState: %d",
9702 hdd_sta_ctx->conn_info.connState);
9703 break;
9704
9705 default:
9706 break;
9707 }
9708 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9709 adapter_node = next;
9710 }
9711
9712 *size -= len;
9713 *buf_ptr += len;
9714}
9715
9716/**
9717 * hdd_register_debug_callback() - registration function for hdd layer
9718 * to print hdd state information
9719 *
9720 * Return: None
9721 */
9722static void hdd_register_debug_callback(void)
9723{
9724 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9725}
9726
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309727/*
9728 * wlan_init_bug_report_lock() - Initialize bug report lock
9729 *
9730 * This function is used to create bug report lock
9731 *
9732 * Return: None
9733 */
9734static void wlan_init_bug_report_lock(void)
9735{
9736 p_cds_contextType p_cds_context;
9737
9738 p_cds_context = cds_get_global_context();
9739 if (!p_cds_context) {
9740 hdd_err("cds context is NULL");
9741 return;
9742 }
9743
9744 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9745}
9746
Mohit Khannaf8f96822017-05-17 17:11:59 -07009747void hdd_dp_trace_init(struct hdd_config *config)
9748{
9749
9750 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9751 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9752 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9753 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9754 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9755 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9756 uint8_t num_entries = 0;
9757
9758 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9759 &num_entries, sizeof(config_params));
9760
9761 /* calculating, num bw timer intervals in a second (1000ms) */
9762 if (config->busBandwidthComputeInterval)
9763 thresh_time_limit =
9764 (1000 / config->busBandwidthComputeInterval);
9765 else
9766 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9767
9768 switch (num_entries) {
9769 case 4:
9770 proto_bitmap = config_params[3];
9771 case 3:
9772 verbosity = config_params[2];
9773 case 2:
9774 thresh = config_params[1];
9775 case 1:
9776 live_mode = config_params[0];
9777 default:
9778 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9779 live_mode, thresh, thresh_time_limit,
9780 verbosity, proto_bitmap);
9781 };
9782
9783 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9784 verbosity, proto_bitmap);
9785
9786}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309787/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009788 * hdd_wlan_startup() - HDD init function
9789 * @dev: Pointer to the underlying device
9790 *
9791 * This is the driver startup code executed once a WLAN device has been detected
9792 *
9793 * Return: 0 for success, < 0 for failure
9794 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309795int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009796{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309797 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009798 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009799 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009800 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009801
9802 ENTER();
9803
Arun Khandavallifae92942016-08-01 13:31:08 +05309804 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009805
9806 if (IS_ERR(hdd_ctx))
9807 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009808
Abhishek Singhe9068f12017-03-31 14:14:52 +05309809 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9810 DEFAULT_PSOC_ID);
9811 if (ret) {
9812 hdd_err("Psoc creation fails!");
9813 QDF_BUG(0);
9814 goto err_hdd_free_context;
9815 }
9816
Arun Khandavallifae92942016-08-01 13:31:08 +05309817 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9818 hdd_iface_change_callback, (void *)hdd_ctx);
9819
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309820 qdf_nbuf_init_replenish_timer();
9821
Arun Khandavallifae92942016-08-01 13:31:08 +05309822 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309823#ifdef FEATURE_WLAN_CH_AVOID
9824 mutex_init(&hdd_ctx->avoid_freq_lock);
9825#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309826
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009827 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009828 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309829
Jeff Johnson957bc272017-02-02 08:54:48 -08009830 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309831 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009832 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009833 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009834 }
9835
Yingying Tang80e15f32016-09-27 18:23:01 +08009836 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009837
Anurag Chouhan6d760662016-02-20 16:05:43 +05309838 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009839
9840 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009841 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309842 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009843 }
9844
Prashanth Bhatta07998752016-04-28 12:35:33 -07009845 ret = hdd_wiphy_init(hdd_ctx);
9846 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009847 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309848 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009849 }
9850
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309851 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009852 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309853
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309854 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009855 goto err_wiphy_unregister;
9856
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309857 wlan_hdd_init_chan_info(hdd_ctx);
9858
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009859 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009860
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309861 ret = hdd_register_notifiers(hdd_ctx);
9862 if (ret)
9863 goto err_ipa_cleanup;
9864
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009865 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009866
Jeff Johnson957bc272017-02-02 08:54:48 -08009867 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9868 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009869 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009870 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009871 }
9872
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009873 hdd_release_rtnl_lock();
9874 rtnl_held = false;
9875
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009876 wlan_hdd_update_11n_mode(hdd_ctx->config);
9877
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009878#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309879 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309880 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009881 hdd_skip_acs_scan_timer_handler,
9882 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309883 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009884 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009885 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009886#endif
9887
Prashanth Bhattaab004382016-10-11 16:08:11 -07009888 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009889
Jeff Johnson9afc5012016-09-23 13:56:27 -07009890 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009891
Nirav Shahbd36b062016-07-18 11:12:59 +05309892 if (hdd_ctx->rps)
9893 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009894
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309895 status = wlansap_global_init();
9896 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009897 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009898
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009899 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309900 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009901
Arun Khandavallifae92942016-08-01 13:31:08 +05309902 if (hdd_ctx->config->fIsImpsEnabled)
9903 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -07009904 else
9905 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309906
Mukul Sharma07bd8752017-10-10 16:58:14 +05309907 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309908 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309909 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309910 hdd_prevent_suspend_timeout(
9911 hdd_ctx->config->iface_change_wait_time,
9912 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
9913 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309914
Sachin Ahujadddd2632017-03-07 19:07:24 +05309915 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009916 goto success;
9917
Jeff Johnson957bc272017-02-02 08:54:48 -08009918err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009919 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009920
Jeff Johnson46bde382017-02-01 15:31:16 -08009921err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309922 if (rtnl_held)
9923 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009924
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309925 unregister_netdevice_notifier(&hdd_netdev_notifier);
9926
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309927err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309928 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009929
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009930err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009931 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009932
Arun Khandavallifae92942016-08-01 13:31:08 +05309933err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009934 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309935
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009936err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309937 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009938 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309939 if (!QDF_IS_STATUS_SUCCESS(status)) {
9940 hdd_err("Failed to close CDS Scheduler");
9941 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9942 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009943 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009944
Houston Hoffman47a4a052016-11-14 23:22:44 -08009945 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009946 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009947 hdd_exit_netlink_services(hdd_ctx);
9948
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309949 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009950
Dustin Brown20912462017-06-07 13:48:25 -07009951 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9952
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009953err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309954 if (cds_is_fw_down())
9955 hdd_err("Not setting the complete event as fw is down");
9956 else
9957 hdd_start_complete(ret);
9958
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309959 qdf_nbuf_deinit_replenish_timer();
Arun Khandavallifae92942016-08-01 13:31:08 +05309960 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9961 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009962 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07009963 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009964
9965success:
9966 EXIT();
9967 return 0;
9968}
9969
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009970/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309971 * hdd_wlan_update_target_info() - update target type info
9972 * @hdd_ctx: HDD context
9973 * @context: hif context
9974 *
9975 * Update target info received from firmware in hdd context
9976 * Return:None
9977 */
9978
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009979void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309980{
9981 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9982
9983 if (!tgt_info) {
9984 hdd_err("Target info is Null");
9985 return;
9986 }
9987
9988 hdd_ctx->target_type = tgt_info->target_type;
9989}
9990
9991/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05309992 * hdd_get_nud_stats_cb() - callback api to update the stats
9993 * received from the firmware
9994 * @data: pointer to adapter.
9995 * @rsp: pointer to data received from FW.
9996 *
9997 * This is called when wlan driver received response event for
9998 * get arp stats to firmware.
9999 *
10000 * Return: None
10001 */
10002static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10003{
10004 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10005 struct hdd_nud_stats_context *context;
10006 int status;
10007 struct hdd_adapter *adapter = NULL;
10008
10009 ENTER();
10010
10011 if (!rsp) {
10012 hdd_err("data is null");
10013 return;
10014 }
10015
10016 status = wlan_hdd_validate_context(hdd_ctx);
10017 if (0 != status)
10018 return;
10019
10020 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10021 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10022 hdd_err("Invalid adapter or adapter has invalid magic");
10023 return;
10024 }
10025
10026 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10027 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10028 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10029 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10030 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10031 rsp->out_of_order_arp_rsp_drop_cnt);
10032 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10033 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10034 hdd_notice("rsp->ba_session_establishment_status :%x",
10035 rsp->ba_session_establishment_status);
10036
10037 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10038 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10039 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10040 adapter->dad |= rsp->dad_detected;
10041 adapter->con_status = rsp->connect_status;
10042
10043 spin_lock(&hdd_context_lock);
10044 context = &hdd_ctx->nud_stats_context;
10045 complete(&context->response_event);
10046 spin_unlock(&hdd_context_lock);
10047
10048 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010049}
10050
10051/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010052 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010053 * @hdd_ctx: HDD context
10054 *
10055 * Register the HDD callbacks to CDS/SME.
10056 *
10057 * Return: 0 for success or Error code for failure
10058 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010059int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010060{
10061 QDF_STATUS status;
10062 int ret = 0;
10063
10064 ENTER();
10065
10066 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10067
10068 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10069 hdd_send_oem_data_rsp_msg);
10070
10071 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10072 wlan_hdd_cfg80211_fw_mem_dump_cb);
10073 if (!QDF_IS_STATUS_SUCCESS(status)) {
10074 hdd_err("Failed to register memdump callback");
10075 ret = -EINVAL;
10076 return ret;
10077 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010078 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10079 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010080 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10081 sme_nan_register_callback(hdd_ctx->hHal,
10082 wlan_hdd_cfg80211_nan_callback);
10083 sme_stats_ext_register_callback(hdd_ctx->hHal,
10084 wlan_hdd_cfg80211_stats_ext_callback);
10085
10086 sme_ext_scan_register_callback(hdd_ctx->hHal,
10087 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010088 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10089 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010090
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010091 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10092 hdd_rssi_threshold_breached);
10093
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010094 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10095
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010096 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10097 wlan_hdd_cfg80211_link_layer_stats_callback);
10098
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010099 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10100
Zhang Qianca38fb12016-12-23 11:10:48 +080010101 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10102 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10103
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010104 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10105 hdd_lost_link_info_cb);
10106 /* print error and not block the startup process */
10107 if (!QDF_IS_STATUS_SUCCESS(status))
10108 hdd_err("set lost link info callback failed");
10109
Poddar, Siddarth34872782017-08-10 14:08:51 +053010110 ret = hdd_register_data_stall_detect_cb();
10111 if (ret) {
10112 hdd_err("Register data stall detect detect callback failed.");
10113 return ret;
10114 }
10115
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010116 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10117
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010118 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010119 hdd_set_connection_in_progress,
10120 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010121
10122 status = sme_congestion_register_callback(hdd_ctx->hHal,
10123 hdd_update_cca_info_cb);
10124 if (!QDF_IS_STATUS_SUCCESS(status))
10125 hdd_err("set congestion callback failed");
10126
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010127 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10128 hdd_bt_activity_cb);
10129 if (!QDF_IS_STATUS_SUCCESS(status))
10130 hdd_err("set bt activity info callback failed");
10131
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010132 EXIT();
10133
10134 return ret;
10135}
10136
10137/**
10138 * hdd_deregister_cb() - De-Register HDD callbacks.
10139 * @hdd_ctx: HDD context
10140 *
10141 * De-Register the HDD callbacks to CDS/SME.
10142 *
10143 * Return: void
10144 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010145void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010146{
10147 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010148 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010149
10150 ENTER();
10151
10152 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10153 if (!QDF_IS_STATUS_SUCCESS(status))
10154 hdd_err("De-register of dcc stats callback failed: %d",
10155 status);
10156
10157 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010158 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10159
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010160 sme_stats_ext_register_callback(hdd_ctx->hHal,
10161 wlan_hdd_cfg80211_stats_ext_callback);
10162
10163 sme_nan_deregister_callback(hdd_ctx->hHal);
10164 status = sme_reset_tsfcb(hdd_ctx->hHal);
10165 if (!QDF_IS_STATUS_SUCCESS(status))
10166 hdd_err("Failed to de-register tsfcb the callback:%d",
10167 status);
10168 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10169 if (!QDF_IS_STATUS_SUCCESS(status))
10170 hdd_err("Failed to de-register the fw mem dump callback: %d",
10171 status);
10172
Poddar, Siddarth34872782017-08-10 14:08:51 +053010173 ret = hdd_deregister_data_stall_detect_cb();
10174 if (ret)
10175 hdd_err("Failed to de-register data stall detect event callback");
10176
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010177 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10178 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10179
10180 EXIT();
10181}
10182
10183/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010184 * hdd_softap_sta_deauth() - handle deauth req from HDD
10185 * @adapter: Pointer to the HDD
10186 * @enable: bool value
10187 *
10188 * This to take counter measure to handle deauth req from HDD
10189 *
10190 * Return: None
10191 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010192QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010193 struct tagCsrDelStaParams *pDelStaParams)
10194{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010195 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010196
10197 ENTER();
10198
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010199 /* Ignore request to deauth bcmc station */
10200 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010201 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010202
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010203 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010204 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10205 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010206
10207 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010208 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010209}
10210
10211/**
10212 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10213 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010214 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010215 *
10216 * This to take counter measure to handle deauth req from HDD
10217 *
10218 * Return: None
10219 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010220void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010221 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010222{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010223 ENTER();
10224
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010225 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010226 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010227 return;
10228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010229 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010230 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010231}
10232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010233/**
10234 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10235 * @hdd_ctx: HDD Context
10236 *
10237 * API to find if there is any STA or P2P-Client is connected
10238 *
10239 * Return: true if connected; false otherwise
10240 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010241QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010242{
10243 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10244}
10245
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010246/**
10247 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10248 * @adapter: HDD adapter pointer
10249 *
10250 * This function loop through each adapter and disable roaming on each STA
10251 * device mode except the input adapter.
10252 *
10253 * Note: On the input adapter roaming is not enabled yet hence no need to
10254 * disable.
10255 *
10256 * Return: None
10257 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010258void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010259{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010260 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010261 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010262 hdd_adapter_list_node_t *adapterNode = NULL;
10263 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010264 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010265
10266 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010267 hdd_ctx->config->isRoamOffloadScanEnabled &&
10268 QDF_STA_MODE == adapter->device_mode &&
10269 policy_mgr_is_sta_active_connection_exists(
10270 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010271 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010272 adapter->sessionId);
10273 /*
10274 * Loop through adapter and disable roaming for each STA device
10275 * mode except the input adapter.
10276 */
10277 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10278
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010279 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010280 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010281
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010282 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010283 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010284 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010285 adapterIdx->sessionId);
10286 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10287 (adapterIdx),
10288 adapterIdx->sessionId, 0);
10289 }
10290
10291 status = hdd_get_next_adapter(hdd_ctx,
10292 adapterNode,
10293 &pNext);
10294 adapterNode = pNext;
10295 }
10296 }
10297}
10298
10299/**
10300 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10301 * @adapter: HDD adapter pointer
10302 *
10303 * This function loop through each adapter and enable roaming on each STA
10304 * device mode except the input adapter.
10305 * Note: On the input adapter no need to enable roaming because link got
10306 * disconnected on this.
10307 *
10308 * Return: None
10309 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010310void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010311{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010312 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010313 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010314 hdd_adapter_list_node_t *adapterNode = NULL;
10315 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010316 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010317
10318 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010319 hdd_ctx->config->isRoamOffloadScanEnabled &&
10320 QDF_STA_MODE == adapter->device_mode &&
10321 policy_mgr_is_sta_active_connection_exists(
10322 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010323 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010324 adapter->sessionId);
10325 /*
10326 * Loop through adapter and enable roaming for each STA device
10327 * mode except the input adapter.
10328 */
10329 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10330
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010331 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010332 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010333
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010334 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010335 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010336 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010337 adapterIdx->sessionId);
10338 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10339 (adapterIdx),
10340 adapterIdx->sessionId,
10341 REASON_CONNECT);
10342 }
10343
10344 status = hdd_get_next_adapter(hdd_ctx,
10345 adapterNode,
10346 &pNext);
10347 adapterNode = pNext;
10348 }
10349 }
10350}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010351
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010352/**
10353 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10354 * @skb: sk buffer pointer
10355 *
10356 * Sends the bcast message to SVC multicast group with generic nl socket
10357 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10358 *
10359 * Return: None
10360 */
10361static void nl_srv_bcast_svc(struct sk_buff *skb)
10362{
10363#ifdef CNSS_GENL
10364 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10365#else
10366 nl_srv_bcast(skb);
10367#endif
10368}
10369
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010370void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010371{
10372 struct sk_buff *skb;
10373 struct nlmsghdr *nlh;
10374 tAniMsgHdr *ani_hdr;
10375 void *nl_data = NULL;
10376 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010377 struct radio_index_tlv *radio_info;
10378 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010379
10380 if (in_interrupt() || irqs_disabled() || in_atomic())
10381 flags = GFP_ATOMIC;
10382
10383 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10384
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010385 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010386 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010387
10388 nlh = (struct nlmsghdr *)skb->data;
10389 nlh->nlmsg_pid = 0; /* from kernel */
10390 nlh->nlmsg_flags = 0;
10391 nlh->nlmsg_seq = 0;
10392 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10393
10394 ani_hdr = NLMSG_DATA(nlh);
10395 ani_hdr->type = type;
10396
10397 switch (type) {
10398 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010399 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010400 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010401 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010402 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010403 ani_hdr->length = 0;
10404 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010405 break;
10406 case WLAN_SVC_WLAN_STATUS_IND:
10407 case WLAN_SVC_WLAN_VERSION_IND:
10408 case WLAN_SVC_DFS_CAC_START_IND:
10409 case WLAN_SVC_DFS_CAC_END_IND:
10410 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10411 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10412 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010413 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010414 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010415 ani_hdr->length = len;
10416 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10417 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10418 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010419 break;
10420
10421 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010422 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010423 type);
10424 kfree_skb(skb);
10425 return;
10426 }
10427
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010428 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010429 * Add radio index at the end of the svc event in TLV format
10430 * to maintain the backward compatibility with userspace
10431 * applications.
10432 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010433
10434 tlv_len = 0;
10435
10436 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10437 < WLAN_NL_MAX_PAYLOAD) {
10438 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10439 sizeof(*ani_hdr) + len);
10440 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10441 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10442 radio_info->radio = radio;
10443 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010444 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010445 "Added radio index tlv - radio index %d",
10446 radio_info->radio);
10447 }
10448
10449 nlh->nlmsg_len += tlv_len;
10450 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10451
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010452 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010453}
10454
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010455#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10456void wlan_hdd_auto_shutdown_cb(void)
10457{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010458 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010459
10460 if (!hdd_ctx)
10461 return;
10462
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010463 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010464 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10465 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010466}
10467
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010468void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010469{
10470 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010471 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010472 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010473 bool ap_connected = false, sta_connected = false;
10474 tHalHandle hal_handle;
10475
10476 hal_handle = hdd_ctx->hHal;
10477 if (hal_handle == NULL)
10478 return;
10479
10480 if (hdd_ctx->config->WlanAutoShutdown == 0)
10481 return;
10482
10483 if (enable == false) {
10484 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010485 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010486 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010487 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010488 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010489 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010490 return;
10491 }
10492
10493 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010494 if (policy_mgr_concurrent_open_sessions_running(
10495 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010496 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10497
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010498 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010499 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010500 if (adapter
10501 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010502 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010503 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10504 conn_info.connState ==
10505 eConnectionState_Associated) {
10506 sta_connected = true;
10507 break;
10508 }
10509 }
10510 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010511 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010512 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10513 bApActive == true) {
10514 ap_connected = true;
10515 break;
10516 }
10517 }
10518 status = hdd_get_next_adapter(hdd_ctx,
10519 adapterNode,
10520 &pNext);
10521 adapterNode = pNext;
10522 }
10523 }
10524
10525 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010526 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010527 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010528 }
Jeff Johnson68755312017-02-10 11:46:55 -080010529
10530 if (sme_set_auto_shutdown_timer(hal_handle,
10531 hdd_ctx->config->WlanAutoShutdown)
10532 != QDF_STATUS_SUCCESS)
10533 hdd_err("Failed to start wlan auto shutdown timer");
10534 else
10535 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10536 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010537}
10538#endif
10539
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010540struct hdd_adapter *
10541hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10542 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010543{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010544 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010545 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010546 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010547 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10548
10549 con_sap_adapter = NULL;
10550
10551 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010552 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010553 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010554 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10555 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010556 adapter != this_sap_adapter) {
10557 if (check_start_bss) {
10558 if (test_bit(SOFTAP_BSS_STARTED,
10559 &adapter->event_flags)) {
10560 con_sap_adapter = adapter;
10561 break;
10562 }
10563 } else {
10564 con_sap_adapter = adapter;
10565 break;
10566 }
10567 }
10568 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10569 adapterNode = pNext;
10570 }
10571
10572 return con_sap_adapter;
10573}
10574
10575#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010576static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010577{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010578 return adapter->device_mode == QDF_STA_MODE ||
10579 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010580}
10581
Jeff Johnson9d295242017-08-29 14:39:48 -070010582static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010583{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010584 return adapter->device_mode == QDF_SAP_MODE ||
10585 adapter->device_mode == QDF_P2P_GO_MODE;
10586}
10587
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010588static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010589{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010590 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010591 hdd_adapter_list_node_t *node;
10592
10593 status = hdd_get_front_adapter(hdd_ctx, &node);
10594 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010595 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010596
10597 if (adapter &&
10598 hdd_adapter_is_sta(adapter) &&
10599 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10600 conn_info.connState == eConnectionState_Associated) {
10601 return true;
10602 }
10603
10604 if (adapter &&
10605 hdd_adapter_is_ap(adapter) &&
10606 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10607 return true;
10608 }
10609
10610 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10611 }
10612
10613 return false;
10614}
10615
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010616static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010617{
10618 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010619
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010620 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010621 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010622 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010623
Dustin Brown5ec6b552017-03-31 12:11:40 -070010624 return is_running;
10625}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010626
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010627static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010628{
10629 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10630 hdd_ctx->bus_bw_timer_running = true;
10631 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10632 hdd_ctx->config->busBandwidthComputeInterval);
10633 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10634}
10635
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010636void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010637{
10638 ENTER();
10639
10640 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10641 hdd_debug("Bandwidth compute timer already started");
10642 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010643 }
10644
Dustin Brown5ec6b552017-03-31 12:11:40 -070010645 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10646
10647 EXIT();
10648}
10649
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010650void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010651{
10652 ENTER();
10653
10654 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10655 hdd_debug("Bandwidth compute timer already started");
10656 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010657 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010658
10659 if (hdd_any_adapter_is_assoc(hdd_ctx))
10660 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10661
10662 EXIT();
10663}
10664
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010665static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010666{
10667 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10668
10669 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10670 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10671 hdd_ctx->bus_bw_timer_running = false;
10672 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10673
10674 hdd_reset_tcp_delack(hdd_ctx);
10675}
10676
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010677void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010678{
10679 ENTER();
10680
10681 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10682 hdd_debug("Bandwidth compute timer already stopped");
10683 return;
10684 }
10685
10686 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10687
10688 EXIT();
10689}
10690
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010691void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010692{
10693 ENTER();
10694
10695 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10696 hdd_debug("Bandwidth compute timer already stopped");
10697 return;
10698 }
10699
10700 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10701 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10702
10703 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010704}
10705#endif
10706
10707/**
10708 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10709 * and sta's operating channel.
10710 * @sta_adapter: Describe the first argument to foobar.
10711 * @ap_adapter: Describe the second argument to foobar.
10712 * @roam_profile: Roam profile of AP to which STA wants to connect.
10713 * @concurrent_chnl_same: If both SAP and STA channels are same then
10714 * set this flag to true else false.
10715 *
10716 * This function checks the sap's operating channel and sta's operating channel.
10717 * if both are same then it will return false else it will restart the sap in
10718 * sta's channel and return true.
10719 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010720 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010721 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010722QDF_STATUS
10723wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10724 struct hdd_adapter *ap_adapter,
10725 tCsrRoamProfile *roam_profile,
10726 tScanResultHandle *scan_cache,
10727 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010728{
Jeff Johnson87251032017-08-29 13:31:11 -070010729 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010730 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010731 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010732 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010733 *concurrent_chnl_same = true;
10734
10735 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10736 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010737 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010738 scan_cache,
10739 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010740 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010741 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010742 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10743 if (hdd_ap_ctx->operatingChannel != channel_id) {
10744 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010745 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010746 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010747 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010748 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10749 if (hdd_ap_ctx->operatingChannel != channel_id) {
10750 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010751 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010752 }
10753 }
10754 } else {
10755 /*
10756 * Lets handle worst case scenario here, Scan cache lookup is
10757 * failed so we have to stop the SAP to avoid any channel
10758 * discrepancy between SAP's channel and STA's channel.
10759 * Return the status as failure so caller function could know
10760 * that scan look up is failed.
10761 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010762 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010763 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010764 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010765 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010766}
10767
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010768/**
10769 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10770 * @ap_adapter: SAP adapter
10771 *
10772 * This function will process the stopping of sap adapter.
10773 *
10774 * Return: None
10775 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010776void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010777{
Jeff Johnson87251032017-08-29 13:31:11 -070010778 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010779 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010780 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010781 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010782
10783 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010784 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010785 return;
10786 }
10787
10788 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10789 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010790 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010791 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010792
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010793 mutex_lock(&hdd_ctx->sap_lock);
10794 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010795 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010796 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10797 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010798 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010799 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010800 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010801 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010802 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010803 qdf_stop_bss_event,
10804 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010805 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010806 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010807 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010808 return;
10809 }
10810 }
10811 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010812 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10813 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010814 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010815 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010816 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010817 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010818 }
10819 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010820}
10821
10822/**
10823 * wlan_hdd_start_sap() - this function starts bss of SAP.
10824 * @ap_adapter: SAP adapter
10825 *
10826 * This function will process the starting of sap adapter.
10827 *
10828 * Return: None
10829 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010830void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010831{
Jeff Johnson87251032017-08-29 13:31:11 -070010832 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010833 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010834 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010835 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010836 tsap_Config_t *sap_config;
10837
10838 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010839 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010840 return;
10841 }
10842
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010843 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010844 hdd_err("SoftAp role has not been enabled");
10845 return;
10846 }
10847
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010848 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10849 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10850 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10851 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10852
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010853 mutex_lock(&hdd_ctx->sap_lock);
10854 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10855 goto end;
10856
10857 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010858 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010859 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10860 goto end;
10861 }
10862
Wei Song2f76f642016-11-18 16:32:53 +080010863 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010864 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10865 &hdd_ap_ctx->sapConfig,
10866 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010867 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010868 goto end;
10869
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010870 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010871 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010872 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010873 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010874 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010875 goto end;
10876 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010877 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010878 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010879 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010880 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10881 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010882 ap_adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010883end:
10884 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010885 /* SAP context and beacon cleanup will happen during driver unload
10886 * in hdd_stop_adapter
10887 */
10888 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10889
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010890}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010891
10892/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010893 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10894 * mac scan config
10895 * @status: Status of set antenna mode
10896 *
10897 * Callback on setting the dual mac configuration
10898 *
10899 * Return: None
10900 */
10901void wlan_hdd_soc_set_antenna_mode_cb(
10902 enum set_antenna_mode_status status)
10903{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010904 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010905
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010906 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010907
10908 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10909 if (0 != wlan_hdd_validate_context(hdd_ctx))
10910 return;
10911
10912 /* Signal the completion of set dual mac config */
10913 complete(&hdd_ctx->set_antenna_mode_cmpl);
10914}
10915
10916/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010917 * hdd_get_fw_version() - Get FW version
10918 * @hdd_ctx: pointer to HDD context.
10919 * @major_spid: FW version - major spid.
10920 * @minor_spid: FW version - minor spid
10921 * @ssid: FW version - ssid
10922 * @crmid: FW version - crmid
10923 *
10924 * This function is called to get the firmware build version stored
10925 * as part of the HDD context
10926 *
10927 * Return: None
10928 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010929void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010930 uint32_t *major_spid, uint32_t *minor_spid,
10931 uint32_t *siid, uint32_t *crmid)
10932{
10933 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10934 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10935 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10936 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10937}
10938
10939#ifdef QCA_CONFIG_SMP
10940/**
10941 * wlan_hdd_get_cpu() - get cpu_index
10942 *
10943 * Return: cpu_index
10944 */
10945int wlan_hdd_get_cpu(void)
10946{
10947 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010948
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010949 put_cpu();
10950 return cpu_index;
10951}
10952#endif
10953
10954/**
10955 * hdd_get_fwpath() - get framework path
10956 *
10957 * This function is used to get the string written by
10958 * userspace to start the wlan driver
10959 *
10960 * Return: string
10961 */
10962const char *hdd_get_fwpath(void)
10963{
10964 return fwpath.string;
10965}
10966
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010967static int hdd_qdf_print_init(void)
10968{
10969 int qdf_print_idx;
10970 QDF_STATUS status;
10971
10972 status = qdf_print_setup();
10973 if (status != QDF_STATUS_SUCCESS) {
10974 pr_err("qdf_print_setup failed\n");
10975 return -EINVAL;
10976 }
10977
10978 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10979
10980 if (qdf_print_idx < 0) {
10981 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10982 qdf_print_idx);
10983 return -EINVAL;
10984 }
10985
10986 qdf_set_pidx(qdf_print_idx);
10987
10988 return 0;
10989}
10990
10991static void hdd_qdf_print_deinit(void)
10992{
10993 int qdf_print_idx;
10994
10995 qdf_print_idx = qdf_get_pidx();
10996 qdf_print_ctrl_cleanup(qdf_print_idx);
10997}
10998
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010999/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011000 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011001 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011002 * This function initilizes CDS global context with the help of cds_init. This
11003 * has to be the first function called after probe to get a valid global
11004 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011005 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011006 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011007 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011008int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011009{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011010 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011011 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011012
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011013 status = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011014
11015 wlan_init_bug_report_lock();
11016
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011017#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11018 wlan_logging_sock_init_svc();
11019#endif
11020
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011021 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011022 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011023 ret = -ENOMEM;
11024 goto err_out;
11025 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011026
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011027 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11028 (void *)hdd_drv_ops_inactivity_handler, NULL,
11029 QDF_TIMER_TYPE_SW);
11030
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011031 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011032 hdd_qdf_print_init();
11033
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011034 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011035
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011036err_out:
11037 return ret;
11038}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011039
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011040/**
11041 * hdd_deinit() - Deinitialize Driver
11042 *
11043 * This function frees CDS global context with the help of cds_deinit. This
11044 * has to be the last function call in remove callback to free the global
11045 * context.
11046 */
11047void hdd_deinit(void)
11048{
Dustin Brownedce4a52017-05-10 11:59:15 -070011049 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011050 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011051
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011052 hdd_qdf_print_deinit();
11053
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011054#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11055 wlan_logging_sock_deinit_svc();
11056#endif
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011057
11058 wlan_destroy_bug_report_lock();
11059 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011060}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011061
Yue Ma6e7b1a02017-04-03 14:17:46 -070011062#ifdef QCA_WIFI_NAPIER_EMULATION
11063#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11064#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011065#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011066#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011067
Sachin Ahujadddd2632017-03-07 19:07:24 +053011068static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11069 struct file *file)
11070{
11071 return 0;
11072}
11073
11074static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11075 const char __user *user_buf,
11076 size_t count,
11077 loff_t *f_pos)
11078{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011079 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011080 static const char wlan_off_str[] = "OFF";
11081 static const char wlan_on_str[] = "ON";
11082 int ret;
11083 unsigned long rc;
11084
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011085 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011086 pr_err("Failed to read buffer\n");
11087 return -EINVAL;
11088 }
11089
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011090 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011091 pr_debug("Wifi turning off from UI\n");
11092 goto exit;
11093 }
11094
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011095 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011096 pr_err("Invalid value received from framework");
11097 goto exit;
11098 }
11099
11100 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011101 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011102 rc = wait_for_completion_timeout(&wlan_start_comp,
11103 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11104 if (!rc) {
11105 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11106 ret = -EINVAL;
11107 hdd_start_complete(ret);
11108 return ret;
11109 }
11110
11111 hdd_start_complete(0);
11112 }
11113
11114exit:
11115 return count;
11116}
11117
11118
11119const struct file_operations wlan_hdd_state_fops = {
11120 .owner = THIS_MODULE,
11121 .open = wlan_hdd_state_ctrl_param_open,
11122 .write = wlan_hdd_state_ctrl_param_write,
11123};
11124
11125static int wlan_hdd_state_ctrl_param_create(void)
11126{
11127 unsigned int wlan_hdd_state_major = 0;
11128 int ret;
11129 struct device *dev;
11130
11131 device = MKDEV(wlan_hdd_state_major, 0);
11132
11133 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11134 if (ret) {
11135 pr_err("Failed to register qcwlanstate");
11136 goto dev_alloc_err;
11137 }
11138 wlan_hdd_state_major = MAJOR(device);
11139
11140 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11141 if (IS_ERR(class)) {
11142 pr_err("wlan_hdd_state class_create error");
11143 goto class_err;
11144 }
11145
11146 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11147 if (IS_ERR(dev)) {
11148 pr_err("wlan_hdd_statedevice_create error");
11149 goto err_class_destroy;
11150 }
11151
11152 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11153 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11154 if (ret) {
11155 pr_err("Failed to add cdev error");
11156 goto cdev_add_err;
11157 }
11158
11159 pr_info("wlan_hdd_state %s major(%d) initialized",
11160 WLAN_MODULE_NAME, wlan_hdd_state_major);
11161
11162 return 0;
11163
11164cdev_add_err:
11165 device_destroy(class, device);
11166err_class_destroy:
11167 class_destroy(class);
11168class_err:
11169 unregister_chrdev_region(device, dev_num);
11170dev_alloc_err:
11171 return -ENODEV;
11172}
11173
11174static void wlan_hdd_state_ctrl_param_destroy(void)
11175{
11176 cdev_del(&wlan_hdd_state_cdev);
11177 device_destroy(class, device);
11178 class_destroy(class);
11179 unregister_chrdev_region(device, dev_num);
11180
11181 pr_info("Device node unregistered");
11182}
11183
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011184/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011185 * component_init - API to init cld component's
11186 *
11187 * Return: None
11188 */
11189static void component_init(void)
11190{
11191 pmo_init();
11192}
11193
11194/**
11195 * component_deinit - API to deinit cld component's
11196 *
11197 * Return: None
11198 */
11199static void component_deinit(void)
11200{
11201 pmo_deinit();
11202}
11203
11204/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011205 * __hdd_module_init - Module init helper
11206 *
11207 * Module init helper function used by both module and static driver.
11208 *
11209 * Return: 0 for success, errno on failure
11210 */
11211static int __hdd_module_init(void)
11212{
11213 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011214
Dustin Brownab482ac2017-06-09 17:00:44 -070011215 pr_err("%s: Loading driver v%s (%s)%s\n",
11216 WLAN_MODULE_NAME,
11217 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011218 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011219 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011220
Sachin Ahujadddd2632017-03-07 19:07:24 +053011221 ret = wlan_hdd_state_ctrl_param_create();
11222 if (ret) {
11223 pr_err("wlan_hdd_state_create:%x\n", ret);
11224 goto err_dev_state;
11225 }
11226
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011227 pld_init();
11228
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011229 ret = hdd_init();
11230 if (ret) {
11231 pr_err("hdd_init failed %x\n", ret);
11232 goto err_hdd_init;
11233 }
11234
Rajeev Kumar97767a02016-11-30 11:20:40 -080011235 dispatcher_init();
11236
Mukul Sharmad75a6672017-06-22 15:40:53 +053011237 /* Ensure to call post objmgr init */
11238 component_init();
11239
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011240 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011241
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011242 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011243
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011244 ret = wlan_hdd_register_driver();
11245 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011246 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11247 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011248 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011249 }
11250
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011251 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011252
11253 return 0;
11254out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011255 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011256 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011257 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011258
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011259err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011260 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011261 wlan_hdd_state_ctrl_param_destroy();
11262err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011263 return ret;
11264}
11265
11266/**
11267 * __hdd_module_exit - Module exit helper
11268 *
11269 * Module exit helper function used by both module and static driver.
11270 */
11271static void __hdd_module_exit(void)
11272{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011273
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011274 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11275 QWLAN_VERSIONSTR);
11276
bings6028ee82017-03-29 07:51:40 +080011277 cds_set_unload_in_progress(true);
11278
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011279 hdd_wait_for_recovery_completion();
11280
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011281 wlan_hdd_unregister_driver();
11282
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011283 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011284
Mukul Sharmad75a6672017-06-22 15:40:53 +053011285 /* Ensure to call prior to objmgr deinit */
11286 component_deinit();
11287
Rajeev Kumar97767a02016-11-30 11:20:40 -080011288 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011289 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011290 pld_deinit();
11291
Sachin Ahujadddd2632017-03-07 19:07:24 +053011292 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011293}
11294
Arun Khandavallifae92942016-08-01 13:31:08 +053011295#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011296/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011297 * wlan_boot_cb() - Wlan boot callback
11298 * @kobj: object whose directory we're creating the link in.
11299 * @attr: attribute the user is interacting with
11300 * @buff: the buffer containing the user data
11301 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011302 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011303 * This callback is invoked when the fs is ready to start the
11304 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011305 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011306 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011307 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011308static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011309 struct kobj_attribute *attr,
11310 const char *buf,
11311 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011312{
Arun Khandavallifae92942016-08-01 13:31:08 +053011313
Arun Khandavallifae92942016-08-01 13:31:08 +053011314 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011315 pr_err("%s: wlan driver already initialized\n", __func__);
11316 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011317 }
11318
Arun Khandavallifae92942016-08-01 13:31:08 +053011319 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011320 pr_err("%s: wlan driver initialization failed\n", __func__);
11321 return -EIO;
11322 }
11323
11324 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011325
11326 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011327}
Arun Khandavallifae92942016-08-01 13:31:08 +053011328
11329/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011330 * hdd_sysfs_cleanup() - cleanup sysfs
11331 *
11332 * Return: None
11333 *
11334 */
11335static void hdd_sysfs_cleanup(void)
11336{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011337 /* remove from group */
11338 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11339 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11340 wlan_loader->attr_group);
11341
11342 /* unlink the object from parent */
11343 kobject_del(wlan_loader->boot_wlan_obj);
11344
11345 /* free the object */
11346 kobject_put(wlan_loader->boot_wlan_obj);
11347
11348 kfree(wlan_loader->attr_group);
11349 kfree(wlan_loader);
11350
11351 wlan_loader = NULL;
11352}
11353
11354/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011355 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11356 * ready
11357 *
11358 * This is creates the syfs entry boot_wlan. Which shall be invoked
11359 * when the filesystem is ready.
11360 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011361 * QDF API cannot be used here since this function is called even before
11362 * initializing WLAN driver.
11363 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011364 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011365 */
11366static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011367{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011368 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011369
11370 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011371 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011372 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011373
11374 wlan_loader->boot_wlan_obj = NULL;
11375 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11376 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011377 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011378 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011379
11380 wlan_loader->loaded_state = 0;
11381 wlan_loader->attr_group->attrs = attrs;
11382
11383 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11384 kernel_kobj);
11385 if (!wlan_loader->boot_wlan_obj) {
11386 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011387 goto error_return;
11388 }
11389
11390 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11391 wlan_loader->attr_group);
11392 if (ret) {
11393 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11394 goto error_return;
11395 }
11396
11397 return 0;
11398
11399error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011400 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011401
11402 return ret;
11403}
11404
11405/**
11406 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11407 *
11408 * Return: 0 on success or errno on failure
11409 */
11410static int wlan_deinit_sysfs(void)
11411{
Arun Khandavallifae92942016-08-01 13:31:08 +053011412 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011413 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011414 return -EINVAL;
11415 }
11416
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011417 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011418 return 0;
11419}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011420
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011421#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011422
11423#ifdef MODULE
11424/**
11425 * __hdd_module_init - Module init helper
11426 *
11427 * Module init helper function used by both module and static driver.
11428 *
11429 * Return: 0 for success, errno on failure
11430 */
11431static int hdd_module_init(void)
11432{
Arun Khandavallifae92942016-08-01 13:31:08 +053011433 if (__hdd_module_init()) {
11434 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011435 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011436 }
11437
Dustin Brownab482ac2017-06-09 17:00:44 -070011438 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011439}
11440#else
11441static int __init hdd_module_init(void)
11442{
11443 int ret = -EINVAL;
11444
11445 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011446 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011447 pr_err("Failed to create sysfs entry for loading wlan");
11448
11449 return ret;
11450}
11451#endif
11452
11453
11454#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011455/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011456 * hdd_module_exit() - Exit function
11457 *
11458 * This is the driver exit point (invoked when module is unloaded using rmmod)
11459 *
11460 * Return: None
11461 */
11462static void __exit hdd_module_exit(void)
11463{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011464 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011465}
Arun Khandavallifae92942016-08-01 13:31:08 +053011466#else
11467static void __exit hdd_module_exit(void)
11468{
11469 __hdd_module_exit();
11470 wlan_deinit_sysfs();
11471}
11472#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011473
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011474static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11475{
11476 return param_set_copystring(kmessage, kp);
11477}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011478
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011479/**
11480 * is_con_mode_valid() check con mode is valid or not
11481 * @mode: global con mode
11482 *
11483 * Return: TRUE on success FALSE on failure
11484 */
11485static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11486{
11487 switch (mode) {
11488 case QDF_GLOBAL_MONITOR_MODE:
11489 case QDF_GLOBAL_FTM_MODE:
11490 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011491 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011492 return true;
11493 default:
11494 return false;
11495 }
11496}
11497
11498/**
11499 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11500 * @mode: global con mode
11501 *
11502 * Return: adapter mode
11503 */
11504static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11505 enum tQDF_GLOBAL_CON_MODE mode)
11506{
11507
11508 switch (mode) {
11509 case QDF_GLOBAL_MISSION_MODE:
11510 return QDF_STA_MODE;
11511 case QDF_GLOBAL_MONITOR_MODE:
11512 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011513 case QDF_GLOBAL_EPPING_MODE:
11514 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011515 case QDF_GLOBAL_FTM_MODE:
11516 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011517 case QDF_GLOBAL_QVIT_MODE:
11518 return QDF_QVIT_MODE;
11519 default:
11520 return QDF_MAX_NO_OF_MODE;
11521 }
11522}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011523
Dustin Brown27cd9942017-09-27 16:11:44 -070011524static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11525 enum tQDF_GLOBAL_CON_MODE curr_mode)
11526{
11527 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11528 return;
11529
11530 switch (curr_mode) {
11531 case QDF_GLOBAL_MISSION_MODE:
11532 case QDF_GLOBAL_MONITOR_MODE:
11533 case QDF_GLOBAL_FTM_MODE:
11534 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11535 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11536
11537 /* re-use the existing session */
11538 hdd_stop_all_adapters(hdd_ctx, false);
11539 break;
11540 default:
11541 break;
11542 }
11543}
11544
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011545static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011546 enum tQDF_GLOBAL_CON_MODE curr_mode)
11547{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011548 int driver_status;
11549
11550 driver_status = hdd_ctx->driver_status;
11551
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011552 switch (curr_mode) {
11553 case QDF_GLOBAL_MISSION_MODE:
11554 case QDF_GLOBAL_MONITOR_MODE:
11555 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011556 hdd_deinit_all_adapters(hdd_ctx, false);
11557 hdd_close_all_adapters(hdd_ctx, false);
11558 break;
11559 case QDF_GLOBAL_EPPING_MODE:
11560 epping_disable();
11561 epping_close();
11562 break;
11563 default:
11564 return;
11565 }
11566}
11567
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011568static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011569 enum tQDF_GLOBAL_CON_MODE mode)
11570{
Jeff Johnson9d295242017-08-29 14:39:48 -070011571 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011572 int ret = 0;
11573 bool rtnl_held;
11574 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11575 QDF_STATUS status;
11576
11577 if (!qdf_dev) {
11578 hdd_err("qdf device context is Null return!");
11579 return -EINVAL;
11580 }
11581
11582 rtnl_held = hdd_hold_rtnl_lock();
11583 switch (mode) {
11584 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011585 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11586 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011587 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011588 break;
11589 case QDF_GLOBAL_FTM_MODE:
11590 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11591 wlan_hdd_get_intf_addr(hdd_ctx),
11592 NET_NAME_UNKNOWN, rtnl_held);
11593 if (adapter == NULL)
11594 ret = -EINVAL;
11595 break;
11596 case QDF_GLOBAL_MONITOR_MODE:
11597 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11598 wlan_hdd_get_intf_addr(hdd_ctx),
11599 NET_NAME_UNKNOWN, rtnl_held);
11600 if (adapter == NULL)
11601 ret = -EINVAL;
11602 break;
11603 case QDF_GLOBAL_EPPING_MODE:
11604 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011605 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011606 hdd_err("Failed to open in eeping mode: %d", status);
11607 ret = -EINVAL;
11608 break;
11609 }
11610 ret = epping_enable(qdf_dev->dev);
11611 if (ret) {
11612 hdd_err("Failed to enable in epping mode : %d", ret);
11613 epping_close();
11614 }
11615 break;
11616 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011617 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011618 ret = -ENOTSUPP;
11619 break;
11620 }
11621 hdd_release_rtnl_lock();
11622 rtnl_held = false;
11623 return ret;
11624}
11625
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011626/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011627 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011628 * @kmessage: con mode name on which driver to be bring up
11629 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011630 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011631 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011632 * This function is invoked when user updates con mode using sys entry,
11633 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011634 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011635 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011636 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011637static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011638 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011639{
11640 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011641 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011642 enum tQDF_GLOBAL_CON_MODE curr_mode;
11643 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011644
Dustin Brownab6029b2017-05-24 13:04:19 -070011645 hdd_info("con_mode handler: %s", kmessage);
11646
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011647 ret = wlan_hdd_validate_context(hdd_ctx);
11648 if (ret)
11649 return ret;
11650
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011651 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011652
11653 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011654
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011655 if (!(is_con_mode_valid(con_mode))) {
11656 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011657 ret = -EINVAL;
11658 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011659 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011660
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011661 curr_mode = hdd_get_conparam();
11662 if (curr_mode == con_mode) {
11663 hdd_err("curr mode: %d is same as user triggered mode %d",
11664 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011665 ret = 0;
11666 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011667 }
11668
Dustin Brown27cd9942017-09-27 16:11:44 -070011669 /* ensure adapters are stopped */
11670 hdd_stop_present_mode(hdd_ctx, curr_mode);
11671
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011672 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011673 if (ret) {
11674 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011675 goto reset_flags;
11676 }
11677
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011678 /* Cleanup present mode before switching to new mode */
11679 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11680
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011681 hdd_set_conparam(con_mode);
11682
11683 /* Register for new con_mode & then kick_start modules again */
11684 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11685 if (ret) {
11686 hdd_err("Failed to register for new mode");
11687 goto reset_flags;
11688 }
11689
11690 adapter_mode = hdd_get_adpter_mode(con_mode);
11691 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11692 hdd_err("invalid adapter");
11693 ret = -EINVAL;
11694 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011695 }
11696
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011697 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011698 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011699 hdd_err("Failed to get adapter:%d", adapter_mode);
11700 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011701 }
11702
11703 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11704 if (ret) {
11705 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011706 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011707 }
11708
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011709 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011710 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011711 if (hdd_start_adapter(adapter)) {
11712 hdd_err("Failed to start %s adapter", kmessage);
11713 ret = -EINVAL;
11714 goto reset_flags;
11715 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011716 }
11717
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011718 hdd_info("Mode successfully changed to %s", kmessage);
11719 ret = 0;
11720
11721reset_flags:
11722 cds_set_load_in_progress(false);
11723 return ret;
11724}
11725
11726
11727static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11728{
11729 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011730 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011731
11732 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11733 ret = wlan_hdd_validate_context(hdd_ctx);
11734 if (ret)
11735 return ret;
11736
11737 cds_ssr_protect(__func__);
11738 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11739 cds_ssr_unprotect(__func__);
11740
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011741 return ret;
11742}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011743
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011744static int con_mode_handler_ftm(const char *kmessage,
11745 struct kernel_param *kp)
11746{
11747 int ret;
11748
11749 ret = param_set_int(kmessage, kp);
11750
11751 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11752 pr_err("Only FTM mode supported!");
11753 return -ENOTSUPP;
11754 }
11755
11756 hdd_set_conparam(con_mode_ftm);
11757 con_mode = con_mode_ftm;
11758
11759 return ret;
11760}
11761
Ravi Joshia307f632017-07-17 23:41:41 -070011762static int con_mode_handler_monitor(const char *kmessage,
11763 struct kernel_param *kp)
11764{
11765 int ret;
11766
11767 ret = param_set_int(kmessage, kp);
11768
11769 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11770 pr_err("Only Monitor mode supported!");
11771 return -ENOTSUPP;
11772 }
11773
11774 hdd_set_conparam(con_mode_monitor);
11775 con_mode = con_mode_monitor;
11776
11777 return ret;
11778}
11779
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011780/**
11781 * hdd_get_conparam() - driver exit point
11782 *
11783 * This is the driver exit point (invoked when module is unloaded using rmmod)
11784 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011785 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011786 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011787enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011788{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011789 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011790}
11791
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011792void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011793{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011794 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011795}
11796
Komal Seelamc11bb222016-01-27 18:57:10 +053011797/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011798 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11799 * @hdd_ctx: HDD context
11800 *
11801 * Cleans up the pre cac interface, if it exists
11802 *
11803 * Return: None
11804 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011805void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011806{
11807 uint8_t session_id;
11808 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011809 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011810
11811 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11812 if (QDF_IS_STATUS_ERROR(status)) {
11813 hdd_err("failed to get pre cac vdev id");
11814 return;
11815 }
11816
11817 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11818 if (!precac_adapter) {
11819 hdd_err("invalid pre cac adapater");
11820 return;
11821 }
11822
11823 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11824 wlan_hdd_sap_pre_cac_failure,
11825 (void *)precac_adapter);
11826 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11827
11828}
11829
11830/**
Komal Seelamec702b02016-02-24 18:42:16 +053011831 * hdd_update_ol_config - API to update ol configuration parameters
11832 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011833 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011834 * Return: void
11835 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011836static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011837{
Komal Seelamec702b02016-02-24 18:42:16 +053011838 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011839 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011840
Komal Seelamec702b02016-02-24 18:42:16 +053011841 if (!ol_ctx)
11842 return;
11843
11844 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11845 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11846 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11847 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011848 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011849
11850 ol_init_ini_config(ol_ctx, &cfg);
11851}
11852
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011853#ifdef FEATURE_RUNTIME_PM
11854/**
11855 * hdd_populate_runtime_cfg() - populate runtime configuration
11856 * @hdd_ctx: hdd context
11857 * @cfg: pointer to the configuration memory being populated
11858 *
11859 * Return: void
11860 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011861static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011862 struct hif_config_info *cfg)
11863{
11864 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11865 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11866}
11867#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011868static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011869 struct hif_config_info *cfg)
11870{
11871}
11872#endif
11873
Komal Seelamec702b02016-02-24 18:42:16 +053011874/**
11875 * hdd_update_hif_config - API to update HIF configuration parameters
11876 * @hdd_ctx: HDD Context
11877 *
11878 * Return: void
11879 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011880static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011881{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011882 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011883 struct hif_config_info cfg;
11884
11885 if (!scn)
11886 return;
11887
11888 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011889 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011890 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011891
11892 if (hdd_ctx->config->prevent_link_down)
11893 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011894}
11895
11896/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011897 * hdd_update_dp_config() - Propagate config parameters to Lithium
11898 * datapath
11899 * @hdd_ctx: HDD Context
11900 *
11901 * Return: 0 for success/errno for failure
11902 */
11903static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
11904{
11905 struct cdp_config_params params;
11906 QDF_STATUS status;
11907
11908 params.tso_enable = hdd_ctx->config->tso_enable;
11909 params.lro_enable = hdd_ctx->config->lro_enable;
11910#ifdef QCA_LL_TX_FLOW_CONTROL_V2
11911 params.tx_flow_stop_queue_threshold =
11912 hdd_ctx->config->TxFlowStopQueueThreshold;
11913 params.tx_flow_start_queue_offset =
11914 hdd_ctx->config->TxFlowStartQueueOffset;
11915#endif
11916 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
11917 params.napi_enable = hdd_ctx->napi_enable;
11918 params.tcp_udp_checksumoffload =
11919 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
11920
11921 status = cdp_update_config_parameters(
11922 cds_get_context(QDF_MODULE_ID_SOC),
11923 &params);
11924 if (status) {
11925 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
11926 "%s: Failed to attach config parameters", __func__);
11927 return status;
11928 }
11929
11930 return 0;
11931}
11932
11933/**
Komal Seelamec702b02016-02-24 18:42:16 +053011934 * hdd_update_config() - Initialize driver per module ini parameters
11935 * @hdd_ctx: HDD Context
11936 *
11937 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011938 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011939 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011940int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011941{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011942 int ret;
11943
Komal Seelamec702b02016-02-24 18:42:16 +053011944 hdd_update_ol_config(hdd_ctx);
11945 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011946 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11947 ret = hdd_update_cds_config_ftm(hdd_ctx);
11948 else
11949 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011950 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011951
11952 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011953}
11954
Mukul Sharma9d797a02017-01-05 20:26:03 +053011955#ifdef FEATURE_WLAN_RA_FILTERING
11956/**
11957 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11958 * @psoc_cfg: pmo psoc Configuration
11959 * @hdd_ctx: Pointer to hdd context
11960 *
11961 * Return: none
11962 */
11963static inline void hdd_ra_populate_pmo_config(
11964 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011965 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011966{
11967 psoc_cfg->ra_ratelimit_interval =
11968 hdd_ctx->config->RArateLimitInterval;
11969 psoc_cfg->ra_ratelimit_enable =
11970 hdd_ctx->config->IsRArateLimitEnabled;
11971}
11972#else
11973static inline void hdd_ra_populate_pmo_config(
11974 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011975 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011976{
11977}
11978#endif
11979/**
11980 * hdd_update_pmo_config - API to update pmo configuration parameters
11981 * @hdd_ctx: HDD context
11982 *
11983 * Return: void
11984 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011985static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011986{
11987 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11988 struct pmo_psoc_cfg psoc_cfg;
11989 QDF_STATUS status;
11990
11991 /*
11992 * Value of hdd_ctx->wowEnable can be,
11993 * 0 - Disable both magic pattern match and pattern byte match.
11994 * 1 - Enable magic pattern match on all interfaces.
11995 * 2 - Enable pattern byte match on all interfaces.
11996 * 3 - Enable both magic patter and pattern byte match on
11997 * all interfaces.
11998 */
11999 psoc_cfg.magic_ptrn_enable =
12000 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12001 psoc_cfg.ptrn_match_enable_all_vdev =
12002 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012003 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12004 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012005 psoc_cfg.bpf_enable =
12006 hdd_ctx->config->bpf_packet_filter_enable;
12007 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012008 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012009 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12010 if (hdd_ctx->config->fhostNSOffload)
12011 psoc_cfg.ns_offload_enable_dynamic = true;
12012 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12013 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12014 psoc_cfg.active_mode_offload =
12015 hdd_ctx->config->active_mode_offload;
12016 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
12017 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012018 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12019 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12020 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12021 psoc_cfg.power_save_mode =
12022 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012023 psoc_cfg.auto_power_save_fail_mode =
12024 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012025
12026 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012027 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12028 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012029 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
12030 if (status != QDF_STATUS_SUCCESS) {
12031 hdd_err("failed pmo psoc configuration");
12032 return -EINVAL;
12033 }
12034
12035 return 0;
12036}
12037
Abhishek Singhb20db962017-03-03 21:28:46 +053012038#ifdef FEATURE_WLAN_SCAN_PNO
12039static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12040 struct hdd_config *cfg)
12041{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012042 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12043
Abhishek Singhb20db962017-03-03 21:28:46 +053012044 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12045 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12046 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12047 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12048 pno_cfg->channel_prediction_full_scan =
12049 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012050 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12051 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12052 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12053 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012054}
12055#else
12056static inline void
12057hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012058 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012059{
Abhishek Singhb20db962017-03-03 21:28:46 +053012060}
12061#endif
12062
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012063void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12064 struct hdd_config *cfg)
12065{
12066 uint8_t i = 0;
12067
12068 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12069 if (!ie_whitelist->white_list)
12070 return;
12071
12072 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12073 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12074 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12075 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12076 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12077 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12078 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12079 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12080
12081 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12082 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12083 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12084}
12085
Abhishek Singh257a9482017-03-06 16:52:39 +053012086/**
12087 * hdd_update_scan_config - API to update scan configuration parameters
12088 * @hdd_ctx: HDD context
12089 *
12090 * Return: 0 if success else err
12091 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012092static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012093{
12094 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12095 struct scan_user_cfg scan_cfg;
12096 struct hdd_config *cfg = hdd_ctx->config;
12097 QDF_STATUS status;
12098
12099 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12100 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12101 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12102 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12103 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12104 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12105 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012106 /* convert to ms */
12107 scan_cfg.scan_cache_aging_time =
12108 cfg->scanAgingTimeout * 1000;
12109 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12110 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12111 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12112 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012113 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012114 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012115 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Abhishek Singh257a9482017-03-06 16:52:39 +053012116
Abhishek Singhb20db962017-03-03 21:28:46 +053012117 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012118 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012119
Abhishek Singh257a9482017-03-06 16:52:39 +053012120 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12121 if (status != QDF_STATUS_SUCCESS) {
12122 hdd_err("failed pmo psoc configuration");
12123 return -EINVAL;
12124 }
12125
12126 return 0;
12127}
Abhishek Singh257a9482017-03-06 16:52:39 +053012128
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012129static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012130{
12131 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12132 struct tdls_start_params tdls_cfg;
12133 struct tdls_user_config *config = &tdls_cfg.config;
12134 struct hdd_config *cfg = hdd_ctx->config;
12135 QDF_STATUS status;
12136
12137 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12138 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12139 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12140 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12141 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12142 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12143 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12144 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12145 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12146 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12147 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12148 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12149 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12150 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12151 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12152 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12153 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12154 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12155 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12156 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12157 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12158 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12159 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12160 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12161 (cfg->fEnableTDLSImplicitTrigger ?
12162 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12163 (cfg->fTDLSExternalControl ?
12164 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12165
12166 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12167 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12168 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12169 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012170 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012171 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012172 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12173 tdls_cfg.tdls_evt_cb_data = psoc;
12174 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12175 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12176 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012177 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12178 tdls_cfg.tdls_wmm_cb_data = psoc;
12179 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12180 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012181 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012182
12183 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12184 if (status != QDF_STATUS_SUCCESS) {
12185 hdd_err("failed pmo psoc configuration");
12186 return -EINVAL;
12187 }
12188
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012189 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012190 /* enable napier specific tdls data path */
12191 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012192
Frank Liud4b2fa02017-03-29 11:46:48 +080012193 return 0;
12194}
Frank Liud4b2fa02017-03-29 11:46:48 +080012195
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012196int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012197{
12198 int ret;
12199
12200 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012201 if (ret)
12202 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012203
Abhishek Singh257a9482017-03-06 16:52:39 +053012204 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012205 if (ret)
12206 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012207
Frank Liud4b2fa02017-03-29 11:46:48 +080012208 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012209 if (ret)
12210 return ret;
12211
12212 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012213
12214 return ret;
12215}
12216
Agrawal Ashish65634612016-08-18 13:24:32 +053012217/**
12218 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12219 * @mode : cfg80211 DFS mode
12220 *
12221 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12222 */
12223enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12224{
12225 switch (mode) {
12226 case DFS_MODE_ENABLE:
12227 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012228 case DFS_MODE_DISABLE:
12229 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012230 case DFS_MODE_DEPRIORITIZE:
12231 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012232 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012233 hdd_debug("ACS dfs mode is NONE");
12234 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012235 }
12236}
12237
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012238/**
12239 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12240 * @hddctx: pointer to hdd context
12241 * @set_value: enable/disable
12242 *
12243 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12244 * Host(even though it is duplicate). When Host send vendor command
12245 * disable,FW doesn't perform any action. Whenever any change in
12246 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12247 *
12248 * return - 0 on success, appropriate error values on failure.
12249 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012250int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012251{
12252 QDF_STATUS status;
12253
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012254 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012255 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012256
12257 if (!hddctx->config->goptimize_chan_avoid_event) {
12258 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12259 return -EINVAL;
12260 }
12261
12262 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12263 if (!QDF_IS_STATUS_SUCCESS(status)) {
12264 hdd_err("Failed to send chan avoid command to SME");
12265 return -EINVAL;
12266 }
12267 return 0;
12268}
Agrawal Ashish65634612016-08-18 13:24:32 +053012269
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012270/**
12271 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12272 * @value: value to set
12273 *
12274 * This function will set the passed value to roaming in progress flag.
12275 *
12276 * Return: None
12277 */
12278void hdd_set_roaming_in_progress(bool value)
12279{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012280 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012281
12282 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12283 if (!hdd_ctx) {
12284 hdd_err("HDD context is NULL");
12285 return;
12286 }
12287
12288 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012289 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012290}
12291
12292/**
12293 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012294 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012295 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012296 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012297 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012298bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012299{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012300 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012301 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012302
12303 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12304 if (!hdd_ctx) {
12305 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012306 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012307 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012308 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12309 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012310 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12311 hdd_ctx->roaming_in_progress);
12312
12313 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012314}
12315
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012316/**
12317 * hdd_is_connection_in_progress() - check if connection is in
12318 * progress
12319 * @session_id: session id
12320 * @reason: scan reject reason
12321 *
12322 * Go through each adapter and check if Connection is in progress
12323 *
12324 * Return: true if connection is in progress else false
12325 */
12326bool hdd_is_connection_in_progress(uint8_t *session_id,
12327 enum scan_reject_states *reason)
12328{
12329 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012330 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012331 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012332 QDF_STATUS status = 0;
12333 uint8_t sta_id = 0;
12334 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012335 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012336
12337 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12338 if (!hdd_ctx) {
12339 hdd_err("HDD context is NULL");
12340 return false;
12341 }
12342
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012343 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12344 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012345 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012346 if (!adapter)
12347 goto end;
12348
12349 hdd_info("Adapter with device mode %s(%d) exists",
12350 hdd_device_mode_to_string(adapter->device_mode),
12351 adapter->device_mode);
12352 if (((QDF_STA_MODE == adapter->device_mode)
12353 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12354 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12355 && (eConnectionState_Connecting ==
12356 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12357 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012358 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012359 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12360 adapter->sessionId);
12361 if (session_id && reason) {
12362 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012363 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012364 }
12365 return true;
12366 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012367 /*
12368 * sme_neighbor_middle_of_roaming is for LFR2
12369 * hdd_is_roaming_in_progress is for LFR3
12370 */
12371 if (((QDF_STA_MODE == adapter->device_mode) &&
12372 sme_neighbor_middle_of_roaming(
12373 WLAN_HDD_GET_HAL_CTX(adapter),
12374 adapter->sessionId)) ||
12375 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012376 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012377 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12378 adapter->sessionId);
12379 if (session_id && reason) {
12380 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012381 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012382 }
12383 return true;
12384 }
12385 if ((QDF_STA_MODE == adapter->device_mode) ||
12386 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12387 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12388 hdd_sta_ctx =
12389 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12390 if ((eConnectionState_Associated ==
12391 hdd_sta_ctx->conn_info.connState)
12392 && (false ==
12393 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12394 sta_mac = (uint8_t *)
12395 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012396 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012397 " is in middle of WPS/EAPOL exchange.",
12398 MAC_ADDR_ARRAY(sta_mac));
12399 if (session_id && reason) {
12400 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012401 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012402 }
12403 return true;
12404 }
12405 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12406 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12407 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12408 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012409 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012410 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012411 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012412 continue;
12413
12414 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012415 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070012416 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012417 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012418 " of SAP/GO is in middle of WPS/EAPOL exchange",
12419 MAC_ADDR_ARRAY(sta_mac));
12420 if (session_id && reason) {
12421 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012422 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012423 }
12424 return true;
12425 }
12426 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012427 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012428 return true;
12429 }
12430 }
12431end:
12432 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12433 adapter_node = next;
12434 }
12435 return false;
12436}
12437
12438/**
12439 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012440 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012441 *
12442 * Return: None
12443 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012444void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012445{
Jeff Johnson87251032017-08-29 13:31:11 -070012446 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012447 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012448 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012449 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012450 tsap_Config_t *sap_config;
12451 void *sap_ctx;
12452
12453 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12454 sap_config = &hdd_ap_ctx->sapConfig;
12455 sap_ctx = hdd_ap_ctx->sapContext;
12456
12457 mutex_lock(&hdd_ctx->sap_lock);
12458 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12459 wlan_hdd_del_station(ap_adapter);
12460 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12461 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12462 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12463 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12464 qdf_status =
12465 qdf_wait_single_event(&hostapd_state->
12466 qdf_stop_bss_event,
12467 SME_CMD_TIMEOUT_VALUE);
12468
12469 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012470 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012471 goto end;
12472 }
12473 }
12474 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012475 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012476 ap_adapter->device_mode, ap_adapter->sessionId);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012477 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012478
12479 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012480 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012481 wlansap_reset_sap_config_add_ie(sap_config,
12482 eUPDATE_IE_ALL);
12483 goto end;
12484 }
12485
12486 qdf_event_reset(&hostapd_state->qdf_event);
12487 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12488 sap_config,
12489 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012490 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012491 wlansap_reset_sap_config_add_ie(sap_config,
12492 eUPDATE_IE_ALL);
12493 goto end;
12494 }
12495
Jeff Johnson6867ec32017-09-29 20:30:20 -070012496 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012497 qdf_status =
12498 qdf_wait_single_event(&hostapd_state->qdf_event,
12499 SME_CMD_TIMEOUT_VALUE);
12500 wlansap_reset_sap_config_add_ie(sap_config,
12501 eUPDATE_IE_ALL);
12502 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012503 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012504 goto end;
12505 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012506 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012507 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12508 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012509 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12510 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012511 ap_adapter->sessionId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012512 }
12513end:
12514 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012515}
12516
12517/**
12518 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12519 * with non dfs acs
12520 *
12521 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12522 *
12523 * Return: None
12524 */
12525void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12526{
Jeff Johnson9d295242017-08-29 14:39:48 -070012527 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012528 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012529 cds_context_type *cds_ctx;
12530
12531 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12532 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012533 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012534 return;
12535 }
12536
12537 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12538 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012539 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012540 return;
12541 }
12542
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012543 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12544 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012545 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012546 return;
12547 }
12548
12549 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012550 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12551 &ap_adapter->event_flags) &&
12552 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12553 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012554
Jeff Johnson6867ec32017-09-29 20:30:20 -070012555 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012556 ap_adapter->sessionCtx.ap.sapConfig.channel =
12557 AUTO_CHANNEL_SELECT;
12558 ap_adapter->sessionCtx.ap.sapConfig.
12559 acs_cfg.acs_mode = true;
12560
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012561 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012562 }
12563}
12564
12565/**
12566 * hdd_set_connection_in_progress() - to set the connection in
12567 * progress flag
12568 * @value: value to set
12569 *
12570 * This function will set the passed value to connection in progress flag.
12571 * If value is previously being set to true then no need to set it again.
12572 *
12573 * Return: true if value is being set correctly and false otherwise.
12574 */
12575bool hdd_set_connection_in_progress(bool value)
12576{
12577 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012578 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012579
12580 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12581 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012582 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012583 return false;
12584 }
12585
12586 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12587 /*
12588 * if the value is set to true previously and if someone is
12589 * trying to make it true again then it could be some race
12590 * condition being triggered. Avoid this situation by returning
12591 * false
12592 */
12593 if (hdd_ctx->connection_in_progress && value)
12594 status = false;
12595 else
12596 hdd_ctx->connection_in_progress = value;
12597 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12598 return status;
12599}
12600
Jeff Johnson9d295242017-08-29 14:39:48 -070012601int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012602{
12603 if (!adapter) {
12604 hdd_err("Invalid adapter");
12605 return -EINVAL;
12606 }
12607 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012608 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012609 WMA_VDEV_MCC_SET_TIME_QUOTA,
12610 set_value, VDEV_CMD);
12611 return 0;
12612
12613}
12614
Jeff Johnson9d295242017-08-29 14:39:48 -070012615int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012616{
12617 if (!adapter) {
12618 hdd_err("Invalid adapter");
12619 return -EINVAL;
12620 }
12621
12622 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012623 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012624 WMA_VDEV_MCC_SET_TIME_LATENCY,
12625 set_value, VDEV_CMD);
12626 return 0;
12627}
12628
Jeff Johnson9d295242017-08-29 14:39:48 -070012629struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012630 *psoc, uint8_t vdev_id)
12631{
Jeff Johnson9d295242017-08-29 14:39:48 -070012632 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012633 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012634
12635 /*
12636 * Currently PSOC is not being used. But this logic will
12637 * change once we have the converged implementation of
12638 * HDD context per PSOC in place. This would break if
12639 * multiple vdev objects reuse the vdev id.
12640 */
12641 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12642 if (!adapter)
12643 hdd_err("Get adapter by vdev id failed");
12644
12645 return adapter;
12646}
12647
Jeff Johnson9d295242017-08-29 14:39:48 -070012648int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012649 int8_t *rssi, int8_t *snr)
12650{
12651 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012652 struct hdd_wext_state *wext_state =
12653 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012654 tCsrRoamProfile *profile = &wext_state->roamProfile;
12655
12656 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12657 profile, bssid, rssi, snr);
12658 if (QDF_STATUS_SUCCESS != status) {
12659 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12660 return -EINVAL;
12661 }
12662
12663 return 0;
12664}
12665
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012666/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012667 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12668 * @adapter - HDD adapter
12669 * @tos - type of service
12670 * @status - status of the traffic
12671 *
12672 * Return: 0 on success and non zero value on failure
12673 */
12674
12675int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12676 bool is_tos_active)
12677{
12678 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012679 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012680 uint32_t max_off_chan_time = 0;
12681 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012682 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012683 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012684
12685 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12686 ret = wlan_hdd_validate_context(hdd_ctx);
12687
12688 if (ret < 0) {
12689 hdd_err("failed to set limit off chan params");
12690 return ret;
12691 }
12692
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012693 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12694
12695 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012696 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012697 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012698 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012699
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012700 if (adapter->active_ac) {
12701 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012702 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012703 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12704 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12705 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012706 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012707 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012708 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12709 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12710 PM_LATENCY);
12711 } else {
12712 /*ignore this command if only BE/BK is active */
12713 is_tos_active = false;
12714 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12715 hdd_ctx->config->conc_system_pref);
12716 }
12717 } else {
12718 /* No active tos */
12719 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12720 hdd_ctx->config->conc_system_pref);
12721 }
12722
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012723 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12724 is_tos_active, max_off_chan_time,
12725 hdd_ctx->config->nRestTimeConc, true);
12726 if (!QDF_IS_STATUS_SUCCESS(status)) {
12727 hdd_err("failed to set limit off chan params");
12728 ret = -EINVAL;
12729 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012730
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012731 return ret;
12732}
12733
12734/**
12735 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
12736 * @adapter - HDD adapter
12737 *
12738 * Return: 0 on success and non zero value on failure
12739 */
12740int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
12741{
12742 struct hdd_context *hdd_ctx;
12743 int ret;
12744 QDF_STATUS status;
12745 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
12746
12747 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12748 ret = wlan_hdd_validate_context(hdd_ctx);
12749 if (ret < 0)
12750 return ret;
12751
12752 /* set the system preferece to default */
12753 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12754 hdd_ctx->config->conc_system_pref);
12755
12756 /* clear the bitmap */
12757 adapter->active_ac = 0;
12758
12759 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
12760 adapter->sessionId, adapter->active_ac);
12761
12762 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12763 false, 0, 0, false);
12764 if (!QDF_IS_STATUS_SUCCESS(status)) {
12765 hdd_err("failed to reset limit off chan params");
12766 ret = -EINVAL;
12767 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012768
12769 return ret;
12770}
12771
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012772/**
12773 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12774 * @drv_op: Enum indicating driver op
12775 *
12776 * Return: none
12777 */
12778void hdd_start_driver_ops_timer(int drv_op)
12779{
12780 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12781 switch (drv_op) {
12782 case eHDD_DRV_OP_PROBE:
12783 memcpy(drv_ops_string, "probe", sizeof("probe"));
12784 break;
12785 case eHDD_DRV_OP_REMOVE:
12786 memcpy(drv_ops_string, "remove", sizeof("remove"));
12787 break;
12788 case eHDD_DRV_OP_SHUTDOWN:
12789 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12790 break;
12791 case eHDD_DRV_OP_REINIT:
12792 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12793 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053012794 case eHDD_DRV_OP_IFF_UP:
12795 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
12796 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012797 }
12798
12799 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12800 HDD_OPS_INACTIVITY_TIMEOUT);
12801}
12802
12803/**
12804 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12805 *
12806 * Return: none
12807 */
12808void hdd_stop_driver_ops_timer(void)
12809{
12810 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12811}
12812
12813/**
12814 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12815 * inactivity timer
12816 *
12817 * Return: None
12818 */
12819void hdd_drv_ops_inactivity_handler(void)
12820{
12821 hdd_err("%s: %d Sec timer expired while in .%s",
12822 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12823
12824 /* Driver shutdown is stuck, no recovery possible at this point */
12825 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12826 sizeof("shutdown")))
12827 QDF_BUG(0);
12828
12829 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012830 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012831 else
12832 QDF_BUG(0);
12833}
12834
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012835void hdd_pld_ipa_uc_shutdown_pipes(void)
12836{
12837 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12838
12839 if (!hdd_ctx)
12840 return;
12841
12842 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12843}
12844
Yun Parkff6a16a2017-09-26 16:38:18 -070012845/**
12846 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
12847 * @struct hdd_context *hdd_ctx
12848 * @struct hdd_adapter *padapter
12849 * @bool enble
12850 *
12851 * Return: none
12852 */
12853void hdd_set_rx_mode_rps(bool enable)
12854{
12855 struct cds_config_info *cds_cfg = cds_get_ini_config();
12856 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12857 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
12858
12859 if (adapter && hdd_ctx &&
12860 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
12861 if (enable && !cds_cfg->rps_enabled)
12862 hdd_send_rps_ind(adapter);
12863 else if (!enable && cds_cfg->rps_enabled)
12864 hdd_send_rps_disable_ind(adapter);
12865 }
12866}
12867
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012868/* Register the module init/exit functions */
12869module_init(hdd_module_init);
12870module_exit(hdd_module_exit);
12871
12872MODULE_LICENSE("Dual BSD/GPL");
12873MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12874MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12875
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012876module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12877 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012878
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012879module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12880 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12881
Ravi Joshia307f632017-07-17 23:41:41 -070012882module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12883 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12884
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012885module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12886 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12887
12888module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12889
12890module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12891
12892module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);