blob: f12f7f45c1c6cbc36484f75c67d4aea826be4560 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnsond9f08602016-12-02 11:31:30 -08002 * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_main.c
30 *
31 * WLAN Host Device Driver implementation
32 *
33 */
34
35/* Include Files */
36#include <wlan_hdd_includes.h>
37#include <cds_api.h>
38#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053039#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include <linux/etherdevice.h>
41#include <linux/firmware.h>
42#include <wlan_hdd_tx_rx.h>
43#include <wni_api.h>
44#include <wlan_hdd_cfg.h>
45#include <wlan_ptt_sock_svc.h>
46#include <dbglog_host.h>
47#include <wlan_logging_sock_svc.h>
48#include <wlan_hdd_wowl.h>
49#include <wlan_hdd_misc.h>
50#include <wlan_hdd_wext.h>
51#include "wlan_hdd_trace.h"
52#include "wlan_hdd_ioctl.h"
53#include "wlan_hdd_ftm.h"
54#include "wlan_hdd_power.h"
55#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070056#include "wlan_hdd_scan.h"
Jeff Johnsonce0032c2017-01-20 07:18:27 -080057#include "wlan_hdd_request_manager.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053058#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053059#include "qdf_trace.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070060#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080061#include <cdp_txrx_misc.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062
63#include <net/addrconf.h>
64#include <linux/wireless.h>
65#include <net/cfg80211.h>
66#include <linux/inetdevice.h>
67#include <net/addrconf.h>
68#include "wlan_hdd_cfg80211.h"
69#include "wlan_hdd_ext_scan.h"
70#include "wlan_hdd_p2p.h"
71#include <linux/rtnetlink.h>
72#include "sap_api.h"
73#include <linux/semaphore.h>
74#include <linux/ctype.h>
75#include <linux/compat.h>
76#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077#include <soc/qcom/subsystem_restart.h>
78#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#include <wlan_hdd_hostapd.h>
80#include <wlan_hdd_softap_tx_rx.h>
81#include "cfg_api.h"
82#include "qwlan_version.h"
83#include "wma_types.h"
84#include "wlan_hdd_tdls.h"
85#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053086#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070088#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070089#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080090#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#include "wlan_hdd_nan.h"
92#include "wlan_hdd_debugfs.h"
93#include "wlan_hdd_driver_ops.h"
94#include "epping_main.h"
95#include "wlan_hdd_memdump.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053096#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097
98#include <wlan_hdd_ipa.h>
99#include "hif.h"
100#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800101#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700102#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800103#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530104#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700105#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700106#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530107#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700108#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530109#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800110#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800111#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530112#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800113#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800114#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530115#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530116#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800117#include "os_if_wifi_pos.h"
118#include "wifi_pos_api.h"
119#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800120#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700121#include "os_if_nan.h"
122#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700123#include "wlan_reg_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700124#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530125#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530126#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700127#include <cdp_txrx_cmn_struct.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800128
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530129#ifdef CNSS_GENL
130#include <net/cnss_nl.h>
131#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800132#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800134#ifdef MODULE
135#define WLAN_MODULE_NAME module_name(THIS_MODULE)
136#else
137#define WLAN_MODULE_NAME "wlan"
138#endif
139
140#ifdef TIMER_MANAGER
141#define TIMER_MANAGER_STR " +TIMER_MANAGER"
142#else
143#define TIMER_MANAGER_STR ""
144#endif
145
146#ifdef MEMORY_DEBUG
147#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
148#else
149#define MEMORY_DEBUG_STR ""
150#endif
151
Sachin Ahujadddd2632017-03-07 19:07:24 +0530152int wlan_start_ret_val;
153static DECLARE_COMPLETION(wlan_start_comp);
154static unsigned int dev_num = 1;
155static struct cdev wlan_hdd_state_cdev;
156static struct class *class;
157static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530158#ifndef MODULE
159static struct gwlan_loader *wlan_loader;
160static ssize_t wlan_boot_cb(struct kobject *kobj,
161 struct kobj_attribute *attr,
162 const char *buf, size_t count);
163struct gwlan_loader {
164 bool loaded_state;
165 struct kobject *boot_wlan_obj;
166 struct attribute_group *attr_group;
167};
168
169static struct kobj_attribute wlan_boot_attribute =
170 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
171
172static struct attribute *attrs[] = {
173 &wlan_boot_attribute.attr,
174 NULL,
175};
176
177#define MODULE_INITIALIZED 1
178#endif
179
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530180#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
181#define MAX_OPS_NAME_STRING_SIZE 20
182
183static qdf_timer_t hdd_drv_ops_inactivity_timer;
184static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
185
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800186/* the Android framework expects this param even though we don't use it */
187#define BUF_LEN 20
188static char fwpath_buffer[BUF_LEN];
189static struct kparam_string fwpath = {
190 .string = fwpath_buffer,
191 .maxlen = BUF_LEN,
192};
193
194static char *country_code;
195static int enable_11d = -1;
196static int enable_dfs_chan_scan = -1;
197
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800198/*
199 * spinlock for synchronizing asynchronous request/response
200 * (full description of use in wlan_hdd_main.h)
201 */
202DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530203DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800204
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800205#define WLAN_NLINK_CESIUM 30
206
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530207static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800208
209#define WOW_MAX_FILTER_LISTS 1
210#define WOW_MAX_FILTERS_PER_LIST 4
211#define WOW_MIN_PATTERN_SIZE 6
212#define WOW_MAX_PATTERN_SIZE 64
213
214#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
215static const struct wiphy_wowlan_support wowlan_support_reg_init = {
216 .flags = WIPHY_WOWLAN_ANY |
217 WIPHY_WOWLAN_MAGIC_PKT |
218 WIPHY_WOWLAN_DISCONNECT |
219 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
220 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
221 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
222 WIPHY_WOWLAN_4WAY_HANDSHAKE |
223 WIPHY_WOWLAN_RFKILL_RELEASE,
224 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
225 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
226 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
227};
228#endif
229
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700230static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
231 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
232 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
233 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
234 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
235 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
236 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
237 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
243 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
244 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
245 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
246 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
247 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700265 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700266 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700267};
268
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530269int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
270 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
271 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
272 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
273 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
274};
275
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800276/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530277struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800278
279struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800280#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700281static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800282#endif
283
Sachin Ahujadddd2632017-03-07 19:07:24 +0530284void hdd_start_complete(int ret)
285{
286 wlan_start_ret_val = ret;
287
288 complete(&wlan_start_comp);
289}
290
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800291/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530292 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700293 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530294 *
295 * Return: none
296 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700297static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530298{
Jeff Johnson9d295242017-08-29 14:39:48 -0700299 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530300 hdd_adapter_list_node_t *adapter_node, *next;
301 QDF_STATUS status = QDF_STATUS_SUCCESS;
302
303 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
304 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -0700305 adapter = adapter_node->adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530306 if (NULL != adapter)
307 hdd_send_rps_ind(adapter);
308 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
309 adapter_node = next;
310 }
311}
312
313/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800314 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
315 * @vdev_id: vdev_id
316 * @action: action type
317 * @reason: reason type
318 *
319 * Return: none
320 */
321void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
322 enum netif_action_type action, enum netif_reason_type reason)
323{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700324 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700325 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800326
327 if (!hdd_ctx) {
328 hdd_err("hdd ctx is NULL");
329 return;
330 }
331 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
332
333 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800334}
335
336/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700337 * Store WLAN driver version and timestamp info in global variables such that
338 * crash debugger can extract them from driver debug symbol and crashdump for
339 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800340 */
341uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700342
343#ifndef BUILD_TIMESTAMP
344#define BUILD_TIMESTAMP ""
345#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700346uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800347
348/**
349 * hdd_device_mode_to_string() - return string conversion of device mode
350 * @device_mode: device mode
351 *
352 * This utility function helps log string conversion of device mode.
353 *
354 * Return: string conversion of device mode, if match found;
355 * "Unknown" otherwise.
356 */
357const char *hdd_device_mode_to_string(uint8_t device_mode)
358{
359 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800360 CASE_RETURN_STRING(QDF_STA_MODE);
361 CASE_RETURN_STRING(QDF_SAP_MODE);
362 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
363 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
364 CASE_RETURN_STRING(QDF_FTM_MODE);
365 CASE_RETURN_STRING(QDF_IBSS_MODE);
366 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
367 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700368 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800369 default:
370 return "Unknown";
371 }
372}
373
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530374/**
375 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
376 * @adapter: HDD adapter
377 * @chan_number: Channel number
378 * @chan_bw: Bandwidth
379 *
380 * Checks if the given bandwidth is valid for the given channel number.
381 *
382 * Return: 0 for success, non-zero for failure
383 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700384int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530385 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800386 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530387{
388 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
389 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
390 bool found = false;
391 tHalHandle hal;
392
393 hal = WLAN_HDD_GET_HAL_CTX(adapter);
394 if (!hal) {
395 hdd_err("Invalid HAL context");
396 return -EINVAL;
397 }
398
399 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
400 hdd_err("No valid channel list");
401 return -EOPNOTSUPP;
402 }
403
404 for (i = 0; i < len; i++) {
405 if (chan[i] == chan_number) {
406 found = true;
407 break;
408 }
409 }
410
411 if (found == false) {
412 hdd_err("Channel not in driver's valid channel list");
413 return -EOPNOTSUPP;
414 }
415
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700416 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
417 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530418 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
419 return -EINVAL;
420 }
421
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700422 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530423 if (chan_bw == CH_WIDTH_80MHZ) {
424 hdd_err("BW80 not possible in 2.4GHz band");
425 return -EINVAL;
426 }
427 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
428 (chan_bw != CH_WIDTH_MAX)) {
429 hdd_err("Only BW20 possible on channel 14");
430 return -EINVAL;
431 }
432 }
433
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700434 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530435 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
436 (chan_bw != CH_WIDTH_MAX)) {
437 hdd_err("Only BW20 possible on channel 165");
438 return -EINVAL;
439 }
440 }
441
442 return 0;
443}
444
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530445/**
446 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
447 *
448 * Block the unloading of the driver (or) interface up until the
449 * cds recovery is completed
450 *
451 * Return: true for recovery completion else false
452 */
453static bool hdd_wait_for_recovery_completion(void)
454{
455 int retry = 0;
456
457 /* Wait for recovery to complete */
458 while (cds_is_driver_recovering()) {
459 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
460 hdd_err("Recovery in progress; wait here!!!");
461 msleep(1000);
462 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
463 hdd_err("SSR never completed, error");
464 /*
465 * Trigger the bug_on in the internal builds, in the
466 * customer builds self-recovery will be enabled
467 * in those cases just return error.
468 */
469 if (cds_is_self_recovery_enabled())
470 return false;
471 QDF_BUG(0);
472 }
473 }
474
475 hdd_info("Recovery completed successfully!");
476 return true;
477}
478
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800479static int __hdd_netdev_notifier_call(struct notifier_block *nb,
480 unsigned long state, void *data)
481{
482#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
483 struct netdev_notifier_info *dev_notif_info = data;
484 struct net_device *dev = dev_notif_info->dev;
485#else
486 struct net_device *dev = data;
487#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700488 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700489 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800490
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800491 ENTER_DEV(dev);
492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800493 /* Make sure that this callback corresponds to our device. */
494 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
495 return NOTIFY_DONE;
496
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530497 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700499 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800500 return NOTIFY_DONE;
501 }
502
503 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700504 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800505 return NOTIFY_DONE;
506 }
507
508 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
509 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800510 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530511 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800512 return NOTIFY_DONE;
513 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800514
515 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
516 hdd_err("%s: Driver module is closed", __func__);
517 return NOTIFY_DONE;
518 }
519
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530520 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800521 return NOTIFY_DONE;
522
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800523 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800524 dev->name, state);
525
526 switch (state) {
527 case NETDEV_REGISTER:
528 break;
529
530 case NETDEV_UNREGISTER:
531 break;
532
533 case NETDEV_UP:
534 sme_ch_avoid_update_req(hdd_ctx->hHal);
535 break;
536
537 case NETDEV_DOWN:
538 break;
539
540 case NETDEV_CHANGE:
541 if (true == adapter->isLinkUpSvcNeeded)
542 complete(&adapter->linkup_event_var);
543 break;
544
545 case NETDEV_GOING_DOWN:
546 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530547 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
548 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800549 } else {
hqueaa33ee2017-05-04 17:56:35 +0800550 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800551 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800552 }
553 break;
554
555 default:
556 break;
557 }
558
559 return NOTIFY_DONE;
560}
561
562/**
563 * hdd_netdev_notifier_call() - netdev notifier callback function
564 * @nb: pointer to notifier block
565 * @state: state
566 * @ndev: ndev pointer
567 *
568 * Return: 0 on success, error number otherwise.
569 */
570static int hdd_netdev_notifier_call(struct notifier_block *nb,
571 unsigned long state,
572 void *ndev)
573{
574 int ret;
575
576 cds_ssr_protect(__func__);
577 ret = __hdd_netdev_notifier_call(nb, state, ndev);
578 cds_ssr_unprotect(__func__);
579
580 return ret;
581}
582
583struct notifier_block hdd_netdev_notifier = {
584 .notifier_call = hdd_netdev_notifier_call,
585};
586
587/* variable to hold the insmod parameters */
588static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800589
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530590static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700591int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530592
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800593/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800594static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800595
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530596/**
597 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
598 * @ch_width: NL channel width
599 *
600 * Converts the NL channel width to the driver's internal representation
601 *
602 * Return: Converted channel width. In case of non matching NL channel width,
603 * CH_WIDTH_MAX will be returned.
604 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800605enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530606{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800607 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700608
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800609 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530610 switch (ch_width) {
611 case NL80211_CHAN_WIDTH_20_NOHT:
612 case NL80211_CHAN_WIDTH_20:
613 return CH_WIDTH_20MHZ;
614 case NL80211_CHAN_WIDTH_40:
615 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530616 case NL80211_CHAN_WIDTH_80:
617 return CH_WIDTH_80MHZ;
618 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800619 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
620 return CH_WIDTH_80P80MHZ;
621 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
622 return CH_WIDTH_160MHZ;
623 else
624 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530625 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800626 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
627 return CH_WIDTH_160MHZ;
628 else
629 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530630 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800631 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530632 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800633 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530634 default:
635 hdd_err("Invalid channel width %d, setting to default",
636 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800637 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530638 }
639}
640
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530641/* wlan_hdd_find_opclass() - Find operating class for a channel
642 * @hal: handler to HAL
643 * @channel: channel id
644 * @bw_offset: bandwidth offset
645 *
646 * Function invokes sme api to find the operating class
647 *
648 * Return: operating class
649 */
650uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
651 uint8_t bw_offset)
652{
653 uint8_t opclass = 0;
654
655 sme_get_opclass(hal, channel, bw_offset, &opclass);
656 return opclass;
657}
658
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800659/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530660 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530661 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800662 * @bitmask: Bitmask of log levels to be enabled
663 *
664 * Called immediately after the cfg.ini is read in order to configure
665 * the desired trace levels.
666 *
667 * Return: None
668 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530669int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800670{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530671 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530672 int qdf_print_idx = -1;
673 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800674 /*
675 * if the bitmask is the default value, then a bitmask was not
676 * specified in cfg.ini, so leave the logging level alone (it
677 * will remain at the "compiled in" default value)
678 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700679 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530680 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800681
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530682 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800683
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530684 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530685 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530686 QDF_TRACE_LEVEL_NONE, 0);
687
688 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530689 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800690 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530691 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800692 while (0 != bitmask) {
693 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530694 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530695 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530696 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530697 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800698 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700699
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800700 level++;
701 bitmask >>= 1;
702 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530703 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800704}
705
706/**
Chris Guo1751acf2017-07-03 14:09:01 +0800707 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
708 * @hdd_ctx: HDD context pointer
709 *
710 * Return: 0 if the context is valid. Error code otherwise
711 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700712int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800713{
714 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
715 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
716 return -ENODEV;
717 }
718
719 if (cds_is_driver_recovering()) {
720 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
721 (void *)_RET_IP_, cds_get_driver_state());
722 return -EAGAIN;
723 }
724
725 if (hdd_ctx->start_modules_in_progress ||
726 hdd_ctx->stop_modules_in_progress) {
727 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
728 (void *)_RET_IP_);
729 return -EAGAIN;
730 }
731
732 return 0;
733}
734
735
736/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800737 * wlan_hdd_validate_context() - check the HDD context
738 * @hdd_ctx: HDD context pointer
739 *
740 * Return: 0 if the context is valid. Error code otherwise
741 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700742int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800744 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530745 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746 return -ENODEV;
747 }
748
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800749 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800750 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530751 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800752 return -EAGAIN;
753 }
754
Yue Ma9f275d92017-09-14 16:58:41 -0700755 if (cds_is_load_or_unload_in_progress()) {
756 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
757 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700759 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530760
761 if (hdd_ctx->start_modules_in_progress ||
762 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800763 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530764 (void *)_RET_IP_);
765 return -EAGAIN;
766 }
767
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530768 if (cds_is_driver_in_bad_state()) {
769 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
770 (void *)_RET_IP_, cds_get_driver_state());
771 return -ENODEV;
772 }
773
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774 return 0;
775}
776
Jeff Johnson9d295242017-08-29 14:39:48 -0700777int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700778{
779 if (!adapter) {
780 hdd_err("adapter is null");
781 return -EINVAL;
782 }
783
784 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
785 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
786 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
787 return -EINVAL;
788 }
789
790 if (!adapter->dev) {
791 hdd_err("adapter net_device is null");
792 return -EINVAL;
793 }
794
795 if (!(adapter->dev->flags & IFF_UP)) {
796 hdd_info("adapter net_device is not up");
797 return -EAGAIN;
798 }
799
800 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
801 hdd_info("adapter session is not open");
802 return -EAGAIN;
803 }
804
805 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
806 hdd_err("bad adapter session Id: %u", adapter->sessionId);
807 return -EINVAL;
808 }
809
810 return 0;
811}
812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800813/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530814 * wlan_hdd_validate_modules_state() - Check modules status
815 * @hdd_ctx: HDD context pointer
816 *
817 * Check's the driver module's state and returns true if the
818 * modules are enabled returns false if modules are closed.
819 *
820 * Return: True if modules are enabled or false.
821 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700822bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530823{
824 mutex_lock(&hdd_ctx->iface_change_lock);
825 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
826 mutex_unlock(&hdd_ctx->iface_change_lock);
827 hdd_notice("Modules not enabled, Present status: %d",
828 hdd_ctx->driver_status);
829 return false;
830 }
831 mutex_unlock(&hdd_ctx->iface_change_lock);
832 return true;
833}
834
835/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800836 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700837 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838 *
839 * This function sets the IBSS power save config parameters to WMA
840 * which will send it to firmware if FW supports IBSS power save
841 * before vdev start.
842 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530843 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800844 * on failure.
845 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700846QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847{
848 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700849 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850
851 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700852 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530853 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 }
855
Naveen Rawat247a8682017-06-05 15:00:31 -0700856 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
858 hdd_ctx->config->ibssATIMWinSize,
859 VDEV_CMD);
860 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700861 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530862 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 }
864
Naveen Rawat247a8682017-06-05 15:00:31 -0700865 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
867 hdd_ctx->config->isIbssPowerSaveAllowed,
868 VDEV_CMD);
869 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700870 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
871 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530872 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873 }
874
Naveen Rawat247a8682017-06-05 15:00:31 -0700875 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
877 hdd_ctx->config->
878 isIbssPowerCollapseAllowed, VDEV_CMD);
879 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700880 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
881 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530882 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800883 }
884
Naveen Rawat247a8682017-06-05 15:00:31 -0700885 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
887 hdd_ctx->config->isIbssAwakeOnTxRx,
888 VDEV_CMD);
889 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700890 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530891 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892 }
893
Naveen Rawat247a8682017-06-05 15:00:31 -0700894 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800895 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
896 hdd_ctx->config->ibssInactivityCount,
897 VDEV_CMD);
898 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700899 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530900 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 }
902
Naveen Rawat247a8682017-06-05 15:00:31 -0700903 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
905 hdd_ctx->config->ibssTxSpEndInactivityTime,
906 VDEV_CMD);
907 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700908 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
909 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530910 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 }
912
Naveen Rawat247a8682017-06-05 15:00:31 -0700913 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
915 hdd_ctx->config->ibssPsWarmupTime,
916 VDEV_CMD);
917 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700918 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
919 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530920 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 }
922
Naveen Rawat247a8682017-06-05 15:00:31 -0700923 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
925 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
926 VDEV_CMD);
927 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700928 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
929 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530930 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800931 }
932
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530933 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800934}
935
Yue Macd359b72017-10-03 15:21:00 -0700936#ifdef FEATURE_RUNTIME_PM
937/**
938 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
939 * @hdd_ctx: HDD context
940 *
941 * Return: None
942 */
943static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
944{
945 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
946
Yue Macd359b72017-10-03 15:21:00 -0700947 qdf_runtime_lock_init(&ctx->dfs);
948
949 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
950}
951
952/**
953 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
954 * @hdd_ctx: HDD Context
955 *
956 * Return: None
957 */
958static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
959{
960 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
961
Yue Macd359b72017-10-03 15:21:00 -0700962 qdf_runtime_lock_deinit(&ctx->dfs);
963
964 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
965}
966
967static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
968{
969 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
970
971 qdf_runtime_lock_init(&ctx->connect);
972}
973
974static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
975{
976 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
977
978 qdf_runtime_lock_deinit(&ctx->connect);
979}
980#else /* FEATURE_RUNTIME_PM */
981static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
982static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
983static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
984static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
985#endif /* FEATURE_RUNTIME_PM */
986
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800987#define INTF_MACADDR_MASK 0x7
988
989/**
990 * hdd_update_macaddr() - update mac address
991 * @config: hdd configuration
992 * @hw_macaddr: mac address
993 *
994 * Mac address for multiple virtual interface is found as following
995 * i) The mac address of the first interface is just the actual hw mac address.
996 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
997 * define the mac address for the remaining interfaces and locally
998 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
999 * supported virtual interfaces, right now this is 0x07 (meaning 8
1000 * interface).
1001 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1002 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1003 *
1004 * Return: None
1005 */
1006void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301007 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001008{
1009 int8_t i;
1010 uint8_t macaddr_b3, tmp_br3;
1011
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301012 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301013 QDF_MAC_ADDR_SIZE);
1014 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301015 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301016 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001017 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1018 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1019 INTF_MACADDR_MASK;
1020 macaddr_b3 += tmp_br3;
1021
1022 /* XOR-ing bit-24 of the mac address. This will give enough
1023 * mac address range before collision
1024 */
1025 macaddr_b3 ^= (1 << 7);
1026
1027 /* Set locally administered bit */
1028 config->intfMacAddr[i].bytes[0] |= 0x02;
1029 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001030 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001031 MAC_ADDRESS_STR, i,
1032 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1033 }
1034}
1035
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001036static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037 struct wma_tgt_services *cfg)
1038{
1039 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040
1041 /* Set up UAPSD */
1042 config->apUapsdEnabled &= cfg->uapsd;
1043
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001044 /* 11AX mode support */
1045 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1046 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1047 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1048
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001049 /* 11AC mode support */
1050 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1051 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1052 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001053
1054 /* ARP offload: override user setting if invalid */
1055 config->fhostArpOffload &= cfg->arp_offload;
1056
1057#ifdef FEATURE_WLAN_SCAN_PNO
1058 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001059 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001060 if (cfg->pno_offload)
1061 config->PnoOffload = true;
1062#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063#ifdef FEATURE_WLAN_TDLS
1064 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301065 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1066 cfg->en_tdls_offchan;
1067 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1068 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001069 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001071 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001072 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1075 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1076#endif
Will Huang496b36c2017-07-11 16:38:50 +08001077 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001078 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001079 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080
1081}
1082
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001083/**
1084 * hdd_update_vdev_nss() - sets the vdev nss
1085 * @hdd_ctx: HDD context
1086 *
1087 * Sets the Nss per vdev type based on INI
1088 *
1089 * Return: None
1090 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001091static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001092{
1093 struct hdd_config *cfg_ini = hdd_ctx->config;
1094 uint8_t max_supp_nss = 1;
1095
Naveen Rawat10b1c152017-01-18 11:16:06 -08001096 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001097 max_supp_nss = 2;
1098
1099 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1100 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1101
1102 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1103 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1104}
1105
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301106/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301107 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1108 * @hdd_ctx: HDD context
1109 *
1110 * Updates wiphy vhtcap fields
1111 *
1112 * Return: None
1113 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001114static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301115{
1116 struct ieee80211_supported_band *band_5g =
1117 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1118 uint32_t val;
1119
1120 if (!band_5g) {
1121 hdd_debug("5GHz band disabled, skipping capability population");
1122 return;
1123 }
1124
1125 val = hdd_ctx->config->txBFCsnValue;
1126 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1127
1128 val = NUM_OF_SOUNDING_DIMENSIONS;
1129 band_5g->vht_cap.cap |=
1130 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1131
1132 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1133 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1134}
1135
1136/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301137 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1138 * @hdd_ctx: HDD context
1139 *
1140 * Sets the DBS capability as per INI and firmware capability
1141 *
1142 * Return: None
1143 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001144static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301145{
1146 struct hdd_config *cfg_ini = hdd_ctx->config;
1147 uint8_t hw_dbs_capable = 0;
1148
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001149 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1150 ((cfg_ini->dual_mac_feature_disable ==
1151 ENABLE_DBS_CXN_AND_SCAN) ||
1152 (cfg_ini->dual_mac_feature_disable ==
1153 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301154 hw_dbs_capable = 1;
1155
1156 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1157}
1158
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001159static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001160 struct wma_tgt_ht_cap *cfg)
1161{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301162 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163 uint32_t value, val32;
1164 uint16_t val16;
1165 struct hdd_config *pconfig = hdd_ctx->config;
1166 tSirMacHTCapabilityInfo *phtCapInfo;
1167 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1168 uint8_t enable_tx_stbc;
1169
1170 /* check and update RX STBC */
1171 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1172 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1173
1174 /* get the MPDU density */
1175 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1176
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301177 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001178 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001179 value = 0;
1180 }
1181
1182 /*
1183 * MPDU density:
1184 * override user's setting if value is larger
1185 * than the one supported by target
1186 */
1187 if (value > cfg->mpdu_density) {
1188 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1189 cfg->mpdu_density);
1190
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301191 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001192 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193 }
1194
1195 /* get the HT capability info */
1196 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301197 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001198 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199 return;
1200 }
1201 val16 = (uint16_t) val32;
1202 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1203
1204 /* Set the LDPC capability */
1205 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1206
1207 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1208 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1209
1210 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1211 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1212
1213 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1214 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1215
1216 enable_tx_stbc = pconfig->enableTxSTBC;
1217
1218 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1219 pconfig->enable2x2 = 1;
1220 } else {
1221 pconfig->enable2x2 = 0;
1222 enable_tx_stbc = 0;
1223
1224 /* 1x1 */
1225 /* Update Rx Highest Long GI data Rate */
1226 if (sme_cfg_set_int(hdd_ctx->hHal,
1227 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001228 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301229 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001230 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001231 }
1232
1233 /* Update Tx Highest Long GI data Rate */
1234 if (sme_cfg_set_int
1235 (hdd_ctx->hHal,
1236 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001237 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301238 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001239 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240 }
1241 }
1242 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1243 enable_tx_stbc = 0;
1244 phtCapInfo->txSTBC = enable_tx_stbc;
1245
1246 val32 = val16;
1247 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301248 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001249 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001250#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1251 value = SIZE_OF_SUPPORTED_MCS_SET;
1252 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301253 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001254 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001255
1256 if (pconfig->enable2x2) {
1257 for (value = 0; value < cfg->num_rf_chains; value++)
1258 mcs_set[value] =
1259 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1260
1261 status =
1262 sme_cfg_set_str(hdd_ctx->hHal,
1263 WNI_CFG_SUPPORTED_MCS_SET,
1264 mcs_set,
1265 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301266 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001267 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001268 }
1269 }
1270#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1271}
1272
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001273static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001274 struct wma_tgt_vht_cap *cfg)
1275{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301276 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001277 uint32_t value = 0;
1278 struct hdd_config *pconfig = hdd_ctx->config;
1279 struct wiphy *wiphy = hdd_ctx->wiphy;
1280 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001281 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001282 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001283 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001284 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001285
Dustin Brown5e06bd32016-10-04 12:49:10 -07001286 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001287 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001288 return;
1289 }
1290
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001291 /* Get the current MPDU length */
1292 status =
1293 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1294 &value);
1295
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301296 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001297 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001298 value = 0;
1299 }
1300
1301 /*
1302 * VHT max MPDU length:
1303 * override if user configured value is too high
1304 * that the target cannot support
1305 */
1306 if (value > cfg->vht_max_mpdu) {
1307 status = sme_cfg_set_int(hdd_ctx->hHal,
1308 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1309 cfg->vht_max_mpdu);
1310
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001311 if (status == QDF_STATUS_E_FAILURE)
1312 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313 }
1314
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001315 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1316 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1317
1318 if (pconfig->enable2x2)
1319 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1320
1321 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1322 QDF_STATUS_E_FAILURE) {
1323 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1324 }
1325
1326 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1327 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1328 if (pconfig->enable2x2)
1329 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1330
1331 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1332 QDF_STATUS_E_FAILURE) {
1333 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1334 }
1335
1336 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1337 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1338 if (pconfig->enable2x2)
1339 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1340
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001341 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001342 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1343
1344 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1345 QDF_STATUS_E_FAILURE) {
1346 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1347 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001348 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001349 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001350 &value);
1351
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301352 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001353 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 value = 0;
1355 }
1356
jiad4a7a33c2017-08-08 15:32:24 +08001357 /* Set HW RX LDPC capability */
1358 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1359 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 status = sme_cfg_set_int(hdd_ctx->hHal,
1361 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001362 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001364 if (status == QDF_STATUS_E_FAILURE)
1365 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366 }
1367
1368 /* Get current GI 80 value */
1369 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1370 &value);
1371
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301372 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001373 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 value = 0;
1375 }
1376
1377 /* set the Guard interval 80MHz */
1378 if (value && !cfg->vht_short_gi_80) {
1379 status = sme_cfg_set_int(hdd_ctx->hHal,
1380 WNI_CFG_VHT_SHORT_GI_80MHZ,
1381 cfg->vht_short_gi_80);
1382
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001383 if (status == QDF_STATUS_E_FAILURE)
1384 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385 }
1386
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387 /* Get VHT TX STBC cap */
1388 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1389
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301390 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001391 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001392 value = 0;
1393 }
1394
1395 /* VHT TX STBC cap */
1396 if (value && !cfg->vht_tx_stbc) {
1397 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1398 cfg->vht_tx_stbc);
1399
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001400 if (status == QDF_STATUS_E_FAILURE)
1401 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402 }
1403
1404 /* Get VHT RX STBC cap */
1405 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1406
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301407 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001408 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001409 value = 0;
1410 }
1411
1412 /* VHT RX STBC cap */
1413 if (value && !cfg->vht_rx_stbc) {
1414 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1415 cfg->vht_rx_stbc);
1416
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001417 if (status == QDF_STATUS_E_FAILURE)
1418 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001419 }
1420
1421 /* Get VHT SU Beamformer cap */
1422 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1423 &value);
1424
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301425 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001426 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001427 value = 0;
1428 }
1429
1430 /* set VHT SU Beamformer cap */
1431 if (value && !cfg->vht_su_bformer) {
1432 status = sme_cfg_set_int(hdd_ctx->hHal,
1433 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1434 cfg->vht_su_bformer);
1435
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001436 if (status == QDF_STATUS_E_FAILURE)
1437 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001438 }
1439
1440 /* check and update SU BEAMFORMEE capabality */
1441 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1442 pconfig->enableTxBF = cfg->vht_su_bformee;
1443
1444 status = sme_cfg_set_int(hdd_ctx->hHal,
1445 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1446 pconfig->enableTxBF);
1447
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001448 if (status == QDF_STATUS_E_FAILURE)
1449 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001450
1451 /* Get VHT MU Beamformer cap */
1452 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1453 &value);
1454
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301455 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001456 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001457 value = 0;
1458 }
1459
1460 /* set VHT MU Beamformer cap */
1461 if (value && !cfg->vht_mu_bformer) {
1462 status = sme_cfg_set_int(hdd_ctx->hHal,
1463 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1464 cfg->vht_mu_bformer);
1465
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001466 if (status == QDF_STATUS_E_FAILURE)
1467 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 }
1469
1470 /* Get VHT MU Beamformee cap */
1471 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1472 &value);
1473
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301474 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001475 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001476 value = 0;
1477 }
1478
1479 /* set VHT MU Beamformee cap */
1480 if (value && !cfg->vht_mu_bformee) {
1481 status = sme_cfg_set_int(hdd_ctx->hHal,
1482 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1483 cfg->vht_mu_bformee);
1484
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001485 if (status == QDF_STATUS_E_FAILURE)
1486 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001487 }
1488
1489 /* Get VHT MAX AMPDU Len exp */
1490 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1491 &value);
1492
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301493 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001494 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001495 value = 0;
1496 }
1497
1498 /*
1499 * VHT max AMPDU len exp:
1500 * override if user configured value is too high
1501 * that the target cannot support.
1502 * Even though Rome publish ampdu_len=7, it can
1503 * only support 4 because of some h/w bug.
1504 */
1505
1506 if (value > cfg->vht_max_ampdu_len_exp) {
1507 status = sme_cfg_set_int(hdd_ctx->hHal,
1508 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1509 cfg->vht_max_ampdu_len_exp);
1510
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001511 if (status == QDF_STATUS_E_FAILURE)
1512 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001513 }
1514
1515 /* Get VHT TXOP PS CAP */
1516 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1517
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301518 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001519 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001520 value = 0;
1521 }
1522
1523 /* set VHT TXOP PS cap */
1524 if (value && !cfg->vht_txop_ps) {
1525 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1526 cfg->vht_txop_ps);
1527
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001528 if (status == QDF_STATUS_E_FAILURE)
1529 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001530 }
1531
1532 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1533 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1534 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1535 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1536 else
1537 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1538
1539
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001540 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1541 status = sme_cfg_set_int(hdd_ctx->hHal,
1542 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1543 VHT_CAP_160_AND_80P80_SUPP);
1544 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001545 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001546 band_5g->vht_cap.cap |=
1547 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001548 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1549 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1550 status = sme_cfg_set_int(hdd_ctx->hHal,
1551 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1552 VHT_CAP_160_SUPP);
1553 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001554 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555 band_5g->vht_cap.cap |=
1556 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001557 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1558 }
1559 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1560 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301561 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001562 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301563 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001564 &value);
1565 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301566 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001567 value = 0;
1568 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301569 /* set the Guard interval 160MHz */
1570 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001571 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301572 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1573 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001574
1575 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301576 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001577 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001578
1579 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1580 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1581
1582 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1583 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1584 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1585 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1586
1587 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1588 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1589
1590 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1591 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1592 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1593 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1594 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1595 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1596
1597 band_5g->vht_cap.cap |=
1598 (cfg->vht_max_ampdu_len_exp <<
1599 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1600
1601 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1602 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1603 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1604 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1605 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1606 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1607 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1608 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1609
1610 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1611 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1612
1613}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001615/**
1616 * hdd_generate_macaddr_auto() - Auto-generate mac address
1617 * @hdd_ctx: Pointer to the HDD context
1618 *
1619 * Auto-generate mac address using device serial number.
1620 * Keep the first 3 bytes of OUI as before and replace
1621 * the last 3 bytes with the lower 3 bytes of serial number.
1622 *
1623 * Return: 0 for success
1624 * Non zero failure code for errors
1625 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001626static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001627{
1628 unsigned int serialno = 0;
1629 struct qdf_mac_addr mac_addr = {
1630 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1631 };
1632
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001633 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001634 if (serialno == 0)
1635 return -EINVAL;
1636
1637 serialno &= 0x00ffffff;
1638
1639 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1640 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1641 mac_addr.bytes[5] = serialno & 0xff;
1642
1643 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1644 return 0;
1645}
1646
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301647/**
1648 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1649 * configuration to cfg_ini in HDD
1650 * @hdd_ctx: Pointer to hdd_ctx
1651 * @cfg: target configuration
1652 *
1653 * Return: None
1654 */
1655#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001656static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301657 struct wma_tgt_cfg *cfg)
1658{
1659 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1660}
1661#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001662static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301663 struct wma_tgt_cfg *cfg)
1664{
1665}
1666#endif
1667
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001668void hdd_update_tgt_cfg(void *context, void *param)
1669{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001670 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001671 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001672 struct wma_tgt_cfg *cfg = param;
1673 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001674 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301675 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301676
Yue Mae3e86ab2017-05-08 10:48:24 -07001677 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301678 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1679 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1680 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1681 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1682 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001683 /* Restore pdev to MAC/WMA contexts */
1684 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001685 } else {
1686 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1687 if (ret) {
1688 hdd_err("pdev creation fails!");
1689 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301690 } else
1691 hdd_debug("New pdev has been created with pdev_id = %u",
1692 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301693 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001694
Naveen Rawat64e477e2016-05-20 10:34:56 -07001695 if (cds_cfg) {
1696 if (hdd_ctx->config->enable_sub_20_channel_width !=
1697 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1698 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1699 cds_cfg->sub_20_channel_width =
1700 WLAN_SUB_20_CH_WIDTH_NONE;
1701 } else {
1702 cds_cfg->sub_20_channel_width =
1703 hdd_ctx->config->enable_sub_20_channel_width;
1704 }
1705 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001706
1707 /* first store the INI band capability */
1708 temp_band_cap = hdd_ctx->config->nBandCapability;
1709
1710 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301711 hdd_ctx->is_fils_roaming_supported =
1712 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001713
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001714 /*
1715 * now overwrite the target band capability with INI
1716 * setting if INI setting is a subset
1717 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001718
1719 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1720 (temp_band_cap != eCSR_BAND_ALL))
1721 hdd_ctx->config->nBandCapability = temp_band_cap;
1722 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1723 (temp_band_cap != eCSR_BAND_ALL) &&
1724 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001725 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001726 }
1727
Amar Singhal58b45ef2017-08-01 13:43:54 -07001728 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1729
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301730 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001731 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1732 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1733 }
1734
1735 /* This can be extended to other configurations like ht, vht cap... */
1736
Anurag Chouhanc5548422016-02-24 18:33:27 +05301737 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001739 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001740 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001741 static struct qdf_mac_addr default_mac_addr = {
1742 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1743 };
1744 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1745 &default_mac_addr)) {
1746 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1747 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1748 MAC_ADDRESS_STR,
1749 MAC_ADDR_ARRAY(hdd_ctx->config->
1750 intfMacAddr[0].bytes));
1751 } else {
1752 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1753 MAC_ADDRESS_STR,
1754 MAC_ADDR_ARRAY(hdd_ctx->config->
1755 intfMacAddr[0].bytes));
1756 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001757 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001758 }
1759
1760 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001761 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001762
1763 hdd_ctx->max_intf_count = cfg->max_intf_count;
1764
Jeff Johnsonc875e242016-09-23 18:12:34 -07001765 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001766 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001767
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001768 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1769 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1770
1771 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1772
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001773 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001774 if (cfg->services.en_11ax) {
1775 hdd_info("11AX: 11ax is enabled - update HDD config");
1776 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1777 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001778
1779 hdd_update_vdev_nss(hdd_ctx);
1780
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301781 hdd_update_hw_dbs_capable(hdd_ctx);
1782
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001783 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001784 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001785 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001786 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001787
Nitesh Shahe50711f2017-04-26 16:30:45 +05301788 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1789 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1790 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001791 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001792 hdd_ctx->current_antenna_mode);
1793
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001794 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1795 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301796 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301797
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301798 if ((hdd_ctx->config->txBFCsnValue >
1799 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1800 !cfg->tx_bfee_8ss_enabled)
1801 hdd_ctx->config->txBFCsnValue =
1802 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1803
1804 if (sme_cfg_set_int(hdd_ctx->hHal,
1805 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1806 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1807 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1808
1809
1810 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1811 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1812 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301813
1814 /*
1815 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1816 */
1817 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301818
1819 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1820
Arun Khandavallid454d422016-08-17 12:47:05 +05301821 /*
1822 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1823 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1824 * configure the STA mode wow pattern.
1825 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301826 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301827 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301828
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301829 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1830
Yue Macd359b72017-10-03 15:21:00 -07001831 /*
1832 * This needs to be done after HDD pdev is created and stored since
1833 * it will access the HDD pdev object lock.
1834 */
1835 hdd_runtime_suspend_context_init(hdd_ctx);
1836
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001837 /* Configure NAN datapath features */
1838 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001839 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840}
1841
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001842bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001843{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001844 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001845 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301846 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001847 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001848
Arif Hussaincd151632017-02-11 16:57:19 -08001849 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001850 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001851 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301852 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001853 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001854
Arif Hussaincd151632017-02-11 16:57:19 -08001855 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1856 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001857 adapter = adapterNode->adapter;
Arif Hussaincd151632017-02-11 16:57:19 -08001858 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1859
1860 if ((QDF_SAP_MODE == adapter->device_mode ||
1861 QDF_P2P_GO_MODE == adapter->device_mode) &&
1862 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1863 ap_ctx->operatingChannel))) {
1864 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1865 true;
1866 hdd_info("tx blocked for session: %d",
1867 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301868 }
Arif Hussaincd151632017-02-11 16:57:19 -08001869 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1870 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001871 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301872
1873 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001874}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001875
1876/**
1877 * hdd_is_valid_mac_address() - validate MAC address
1878 * @pMacAddr: Pointer to the input MAC address
1879 *
1880 * This function validates whether the given MAC address is valid or not
1881 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1882 * where X is the hexa decimal digit character and separated by ':'
1883 * This algorithm works even if MAC address is not separated by ':'
1884 *
1885 * This code checks given input string mac contains exactly 12 hexadecimal
1886 * digits and a separator colon : appears in the input string only after
1887 * an even number of hex digits.
1888 *
1889 * Return: 1 for valid and 0 for invalid
1890 */
1891bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1892{
1893 int xdigit = 0;
1894 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001895
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001896 while (*pMacAddr) {
1897 if (isxdigit(*pMacAddr)) {
1898 xdigit++;
1899 } else if (':' == *pMacAddr) {
1900 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1901 break;
1902
1903 ++separator;
1904 } else {
1905 /* Invalid MAC found */
1906 return 0;
1907 }
1908 ++pMacAddr;
1909 }
1910 return xdigit == 12 && (separator == 5 || separator == 0);
1911}
1912
1913/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301914 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1915 * @dev: Handle to struct net_device to be updated.
1916 *
1917 * Return: None
1918 */
1919static void hdd_mon_mode_ether_setup(struct net_device *dev)
1920{
1921 dev->header_ops = NULL;
1922 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1923 dev->hard_header_len = ETH_HLEN;
1924 dev->mtu = ETH_DATA_LEN;
1925 dev->addr_len = ETH_ALEN;
1926 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1927 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1928 dev->priv_flags |= IFF_TX_SKB_SHARING;
1929
1930 memset(dev->broadcast, 0xFF, ETH_ALEN);
1931}
1932
1933/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001934 * __hdd__mon_open() - HDD Open function
1935 * @dev: Pointer to net_device structure
1936 *
1937 * This is called in response to ifconfig up
1938 *
1939 * Return: 0 for success; non-zero for failure
1940 */
1941static int __hdd_mon_open(struct net_device *dev)
1942{
1943 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001944 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1945 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001946
1947 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001948
1949 ret = wlan_hdd_validate_context(hdd_ctx);
1950 if (ret)
1951 return ret;
1952
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301953 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001954
1955 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1956 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1957 if (ret) {
1958 hdd_err("Failed to start WLAN modules return");
1959 return ret;
1960 }
1961 hdd_err("hdd_wlan_start_modules() successful !");
1962
1963 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1964 ret = hdd_start_adapter(adapter);
1965 if (ret) {
1966 hdd_err("Failed to start adapter :%d",
1967 adapter->device_mode);
1968 return ret;
1969 }
1970 hdd_err("hdd_start_adapters() successful !");
1971 }
1972 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1973 }
1974
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001975 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001976
1977 if (!ret)
1978 ret = hdd_enable_monitor_mode(dev);
1979
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001980 return ret;
1981}
1982
1983/**
1984 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1985 * @dev: Pointer to net_device structure
1986 *
1987 * This is called in response to ifconfig up
1988 *
1989 * Return: 0 for success; non-zero for failure
1990 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001991static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001992{
1993 int ret;
1994
1995 cds_ssr_protect(__func__);
1996 ret = __hdd_mon_open(dev);
1997 cds_ssr_unprotect(__func__);
1998
1999 return ret;
2000}
2001
2002/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302003 * hdd_start_adapter() - Wrapper function for device specific adapter
2004 * @adapter: pointer to HDD adapter
2005 *
2006 * This function is called to start the device specific adapter for
2007 * the mode passed in the adapter's device_mode.
2008 *
2009 * Return: 0 for success; non-zero for failure
2010 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002011int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302012{
2013
2014 int ret;
2015 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
2016
2017 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002018 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302019
2020 switch (device_mode) {
2021 case QDF_P2P_CLIENT_MODE:
2022 case QDF_P2P_DEVICE_MODE:
2023 case QDF_OCB_MODE:
2024 case QDF_STA_MODE:
2025 case QDF_MONITOR_MODE:
2026 ret = hdd_start_station_adapter(adapter);
2027 if (ret)
2028 goto err_start_adapter;
2029 break;
2030 case QDF_P2P_GO_MODE:
2031 case QDF_SAP_MODE:
2032 ret = hdd_start_ap_adapter(adapter);
2033 if (ret)
2034 goto err_start_adapter;
2035 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302036 case QDF_IBSS_MODE:
2037 /*
2038 * For IBSS interface is initialized as part of
2039 * hdd_init_station_mode()
2040 */
2041 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302042 case QDF_FTM_MODE:
2043 ret = hdd_start_ftm_adapter(adapter);
2044 if (ret)
2045 goto err_start_adapter;
2046 break;
2047 default:
2048 hdd_err("Invalid session type %d", device_mode);
2049 QDF_ASSERT(0);
2050 goto err_start_adapter;
2051 }
2052 if (hdd_set_fw_params(adapter))
2053 hdd_err("Failed to set the FW params for the adapter!");
2054
2055 /*
2056 * Action frame registered in one adapter which will
2057 * applicable to all interfaces
2058 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302059 ret = wlan_hdd_cfg80211_register_frames(adapter);
2060 if (ret < 0) {
2061 hdd_err("Failed to register frames - ret %d", ret);
2062 goto err_start_adapter;
2063 }
2064
Arun Khandavallifae92942016-08-01 13:31:08 +05302065 EXIT();
2066 return 0;
2067err_start_adapter:
2068 return -EINVAL;
2069}
2070
2071/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302072 * hdd_enable_power_management() - API to Enable Power Management
2073 *
2074 * API invokes Bus Interface Layer power management functionality
2075 *
2076 * Return: None
2077 */
2078static void hdd_enable_power_management(void)
2079{
2080 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2081
2082 if (!hif_ctx) {
2083 hdd_err("Bus Interface Context is Invalid");
2084 return;
2085 }
2086
2087 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2088}
2089
2090/**
2091 * hdd_disable_power_management() - API to disable Power Management
2092 *
2093 * API disable Bus Interface Layer Power management functionality
2094 *
2095 * Return: None
2096 */
2097static void hdd_disable_power_management(void)
2098{
2099 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2100
2101 if (!hif_ctx) {
2102 hdd_err("Bus Interface Context is Invalid");
2103 return;
2104 }
2105
2106 hif_disable_power_management(hif_ctx);
2107}
2108
2109/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302110 * hdd_update_hw_sw_info() - API to update the HW/SW information
2111 *
2112 * API to update the HW and SW information in the driver
2113 *
2114 * Return: None
2115 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002116static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302117{
2118 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002119 size_t target_hw_name_len;
2120 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302121
2122 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2123 if (!hif_sc) {
2124 hdd_err("HIF context is NULL");
2125 return;
2126 }
2127
2128 /*
2129 * target hw version/revision would only be retrieved after firmware
2130 * download
2131 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002132 hif_get_hw_info(hif_sc,
2133 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302134 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002135 &target_hw_name);
2136
2137 if (hdd_ctx->target_hw_name)
2138 qdf_mem_free(hdd_ctx->target_hw_name);
2139
2140 target_hw_name_len = strlen(target_hw_name) + 1;
2141 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2142 if (hdd_ctx->target_hw_name)
2143 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2144 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302145
2146 /* Get the wlan hw/fw version */
2147 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302148}
2149
2150/**
gbian62edd7e2017-03-07 13:12:13 +08002151 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2152 * @hdd_ctx: Pointer to hdd context
2153 *
2154 * Return: none
2155 */
2156static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002157hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002158{
2159 uint8_t num_entries = 0;
2160 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2161 uint8_t *tx_sched_wrr_ac;
2162 int i;
2163 cds_context_type *cds_ctx;
2164
2165 if (NULL == hdd_ctx)
2166 return;
2167
2168 if (NULL == hdd_ctx->config) {
2169 /* Do nothing if hdd_ctx is invalid */
2170 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2171 return;
2172 }
2173
2174 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2175
2176 if (!cds_ctx) {
2177 hdd_err("Invalid CDS Context");
2178 return;
2179 }
2180
2181 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2182 switch (i) {
2183 case OL_TX_WMM_AC_BE:
2184 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2185 break;
2186 case OL_TX_WMM_AC_BK:
2187 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2188 break;
2189 case OL_TX_WMM_AC_VI:
2190 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2191 break;
2192 case OL_TX_WMM_AC_VO:
2193 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2194 break;
2195 default:
2196 tx_sched_wrr_ac = NULL;
2197 break;
2198 }
2199
2200 hdd_string_to_u8_array(tx_sched_wrr_ac,
2201 tx_sched_wrr_param,
2202 &num_entries,
2203 sizeof(tx_sched_wrr_param));
2204
2205 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2206 cds_ctx->ac_specs[i].wrr_skip_weight =
2207 tx_sched_wrr_param[0];
2208 cds_ctx->ac_specs[i].credit_threshold =
2209 tx_sched_wrr_param[1];
2210 cds_ctx->ac_specs[i].send_limit =
2211 tx_sched_wrr_param[2];
2212 cds_ctx->ac_specs[i].credit_reserve =
2213 tx_sched_wrr_param[3];
2214 cds_ctx->ac_specs[i].discard_weight =
2215 tx_sched_wrr_param[4];
2216 }
2217
2218 num_entries = 0;
2219 }
2220}
2221
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002222#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002223static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2224 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2225{
Jeff Johnson9d295242017-08-29 14:39:48 -07002226 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002227 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002228
2229 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2230 if (!adapter) {
2231 hdd_err("Adapter is NULL");
2232 return PM_MAX_NUM_OF_MODE;
2233 }
2234
2235 return policy_mgr_convert_device_mode_to_qdf_type(
2236 adapter->device_mode);
2237}
2238
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002239static void hdd_register_policy_manager_callback(
2240 struct wlan_objmgr_psoc *psoc)
2241{
2242 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002243
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002244 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002245 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002246 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2247 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002248 hdd_cbacks.get_mode_for_non_connected_vdev =
2249 wlan_hdd_get_mode_for_non_connected_vdev;
2250
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002251 if (QDF_STATUS_SUCCESS !=
2252 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2253 hdd_err("HDD callback registration with policy manager failed");
2254 }
2255}
2256#else
2257static void hdd_register_policy_manager_callback(
2258 struct wlan_objmgr_psoc *psoc)
2259{
2260}
2261#endif
2262
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002263#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002264static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002265{
2266 struct nan_callbacks cb_obj = {0};
2267
2268 cb_obj.ndi_open = hdd_ndi_open;
2269 cb_obj.ndi_close = hdd_ndi_close;
2270 cb_obj.ndi_start = hdd_ndi_start;
2271 cb_obj.ndi_delete = hdd_ndi_delete;
2272 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2273 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2274
Naveen Rawat37f62c82017-03-26 22:24:43 -07002275 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2276 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002277 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002278
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002279 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2280}
2281#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002282static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002283{
2284}
2285#endif
2286
gbian62edd7e2017-03-07 13:12:13 +08002287/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302288 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2289 * @hdd_ctx: HDD context
2290 * @adapter: HDD adapter
2291 * @reinit: flag to indicate from SSR or normal path
2292 *
2293 * This function maintains the driver state machine it will be invoked from
2294 * startup, reinit and change interface. Depending on the driver state shall
2295 * perform the opening of the modules.
2296 *
2297 * Return: 0 for success; non-zero for failure
2298 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002299int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2300 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302301 bool reinit)
2302{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002303 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302304 qdf_device_t qdf_dev;
2305 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302306 bool unint = false;
2307 void *hif_ctx;
2308
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002309 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302310
2311 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2312 if (!qdf_dev) {
2313 hdd_err("QDF Device Context is Invalid return");
2314 return -EINVAL;
2315 }
2316
2317 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302318 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302319
2320 if (QDF_TIMER_STATE_RUNNING ==
2321 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2322
2323 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002324 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302325 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2326 }
2327
2328 switch (hdd_ctx->driver_status) {
2329 case DRIVER_MODULES_UNINITIALIZED:
2330 unint = true;
2331 /* Fall through dont add break here */
2332 case DRIVER_MODULES_CLOSED:
2333 if (!reinit && !unint) {
2334 ret = pld_power_on(qdf_dev->dev);
2335 if (ret) {
2336 hdd_err("Failed to Powerup the device: %d", ret);
2337 goto release_lock;
2338 }
2339 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002340
2341 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2342 hdd_ctx->config->enable_fw_log);
2343
Arun Khandavallifae92942016-08-01 13:31:08 +05302344 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2345 qdf_dev->bus_type,
2346 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2347 HIF_ENABLE_TYPE_PROBE);
2348 if (ret) {
2349 hdd_err("Failed to open hif: %d", ret);
2350 goto power_down;
2351 }
2352
2353 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302354 if (!hif_ctx) {
2355 hdd_err("hif context is null!!");
2356 goto power_down;
2357 }
2358
Arun Khandavallifae92942016-08-01 13:31:08 +05302359 status = ol_cds_init(qdf_dev, hif_ctx);
2360 if (status != QDF_STATUS_SUCCESS) {
2361 hdd_err("No Memory to Create BMI Context :%d", status);
2362 goto hif_close;
2363 }
2364
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002365 ret = hdd_update_config(hdd_ctx);
2366 if (ret) {
2367 hdd_err("Failed to update configuration :%d", ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002368 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002369 }
2370
gbian62edd7e2017-03-07 13:12:13 +08002371 hdd_update_cds_ac_specs_params(hdd_ctx);
2372
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302373 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002374 if (QDF_IS_STATUS_ERROR(status)) {
Arun Khandavallifae92942016-08-01 13:31:08 +05302375 hdd_err("Failed to Open CDS: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002376 ret = qdf_status_to_os_return(status);
2377 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302378 }
2379
Mukul Sharma9d797a02017-01-05 20:26:03 +05302380 /* initalize components configurations after psoc open */
2381 ret = hdd_update_components_config(hdd_ctx);
2382 if (ret) {
2383 hdd_err("Failed to update components configs :%d",
2384 ret);
2385 goto close;
2386 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002387 status = cds_dp_open(hdd_ctx->hdd_psoc);
2388 if (!QDF_IS_STATUS_SUCCESS(status)) {
2389 hdd_err("Failed to Open cds post open: %d", status);
2390 goto close;
2391 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302392
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002393 /*
2394 * NAN compoenet requires certian operations like, open adapter,
2395 * close adapter, etc. to be initiated by HDD, for those
2396 * register HDD callbacks with UMAC's NAN componenet.
2397 */
2398 hdd_nan_register_callbacks(hdd_ctx);
2399
Arun Khandavallifae92942016-08-01 13:31:08 +05302400 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2401
Jeff Johnson3a280122017-09-13 07:42:00 -07002402 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302403 if (!QDF_IS_STATUS_SUCCESS(status)) {
2404 hdd_err("Failed to pre-enable CDS: %d", status);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002405 ret = (status == QDF_STATUS_E_NOMEM) ? -ENOMEM : -EINVAL;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002406 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302407 }
2408
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002409 hdd_register_policy_manager_callback(
2410 hdd_ctx->hdd_psoc);
2411
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302412 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302413 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302414
Arun Khandavallifae92942016-08-01 13:31:08 +05302415 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2416 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2417 hdd_ftm_mc_process_msg);
2418 break;
2419 }
2420 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002421 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302422 break;
2423 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302424
2425 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002426 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2427 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002428 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002429 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302430 }
2431
Arun Khandavallifae92942016-08-01 13:31:08 +05302432 /* Fall through dont add break here */
2433 case DRIVER_MODULES_OPENED:
2434 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002435 hdd_alert("adapter is Null");
2436 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302437 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302438 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2439 hdd_err("in ftm mode, no need to configure cds modules");
2440 break;
2441 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302442 if (hdd_configure_cds(hdd_ctx, adapter)) {
2443 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002444 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302445 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302446 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302447 hdd_info("Driver Modules Successfully Enabled");
2448 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2449 break;
2450 case DRIVER_MODULES_ENABLED:
2451 hdd_info("Driver modules already Enabled");
2452 break;
2453 default:
2454 hdd_err("WLAN start invoked in wrong state! :%d\n",
2455 hdd_ctx->driver_status);
2456 goto release_lock;
2457 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302458 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302459 mutex_unlock(&hdd_ctx->iface_change_lock);
2460 EXIT();
2461 return 0;
2462
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002463post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002464 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002465
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002466cds_txrx_free:
2467 cds_dp_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302468close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002469 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002470 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302471
Dustin Brown28b17892017-10-10 13:29:38 -07002472deinit_config:
2473 cds_deinit_ini_config();
2474
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002475cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302476 ol_cds_free();
2477
2478hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002479 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2480 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302481power_down:
2482 if (!reinit && !unint)
2483 pld_power_off(qdf_dev->dev);
2484release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302485 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302486 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302487 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002488
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002489 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302490}
2491
Naveen Rawat910726a2017-03-06 11:42:51 -08002492#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002493static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002494{
2495 int ret = os_if_wifi_pos_register_nl();
2496
2497 if (ret)
2498 hdd_err("os_if_wifi_pos_register_nl failed");
2499
2500 return ret;
2501}
2502
2503static int hdd_deactivate_wifi_pos(void)
2504{
2505 int ret = os_if_wifi_pos_deregister_nl();
2506
2507 if (ret)
2508 hdd_err("os_if_wifi_pos_deregister_nl failed");
2509
2510 return ret;
2511}
2512
2513/**
2514 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2515 * @hdd_ctx: hdd context
2516 *
2517 * Return: status of operation
2518 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002519static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002520{
2521 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2522 struct hdd_config *cfg = hdd_ctx->config;
2523
2524 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2525 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2526 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2527 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2528 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2529 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2530 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2531 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2532}
2533#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002534static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002535{
2536 return oem_activate_service(hdd_ctx);
2537}
2538
2539static int hdd_deactivate_wifi_pos(void)
2540{
2541 return 0;
2542}
2543
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002544static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002545{
2546}
2547#endif
2548
Arun Khandavallifae92942016-08-01 13:31:08 +05302549/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002550 * __hdd_open() - HDD Open function
2551 * @dev: Pointer to net_device structure
2552 *
2553 * This is called in response to ifconfig up
2554 *
2555 * Return: 0 for success; non-zero for failure
2556 */
2557static int __hdd_open(struct net_device *dev)
2558{
Jeff Johnson9d295242017-08-29 14:39:48 -07002559 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002560 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002561 int ret;
2562
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002563 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302564 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302565 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002566
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302567 /* Nothing to be done if device is unloading */
2568 if (cds_is_driver_unloading()) {
2569 hdd_err("Driver is unloading can not open the hdd");
2570 return -EBUSY;
2571 }
2572
Dustin Brown01847752017-10-25 13:56:27 -07002573 if (cds_is_driver_recovering()) {
2574 hdd_err("WLAN is currently recovering; Please try again.");
2575 return -EBUSY;
2576 }
2577
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302578 mutex_lock(&hdd_init_deinit_lock);
2579
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302580 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2581
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302582 /*
2583 * This scenario can be hit in cases where in the wlan driver after
2584 * registering the netdevices and there is a failure in driver
2585 * initialization. So return error gracefully because the netdevices
2586 * will be de-registered as part of the load failure.
2587 */
2588
2589 if (!cds_is_driver_loaded()) {
2590 hdd_err("Failed to start the wlan driver!!");
2591 ret = -EIO;
2592 goto err_hdd_hdd_init_deinit_lock;
2593 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302594
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002595
Arun Khandavallifae92942016-08-01 13:31:08 +05302596 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2597 if (ret) {
2598 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302599 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302600 }
2601
2602
2603 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2604 ret = hdd_start_adapter(adapter);
2605 if (ret) {
2606 hdd_err("Failed to start adapter :%d",
2607 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302608 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302609 }
2610 }
2611
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002612 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2613 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002614 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002615 /* Enable TX queues only when we are connected */
2616 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302617 WLAN_START_ALL_NETIF_QUEUE,
2618 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002619 }
2620
Naveen Rawat286def52016-09-23 15:38:02 -07002621 /* Enable carrier and transmit queues for NDI */
2622 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002623 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002624 wlan_hdd_netif_queue_control(adapter,
2625 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2626 WLAN_CONTROL_PATH);
2627 }
2628
Naveen Rawat910726a2017-03-06 11:42:51 -08002629 hdd_populate_wifi_pos_cfg(hdd_ctx);
2630
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302631err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302632 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302633 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002634 return ret;
2635}
2636
Arun Khandavallifae92942016-08-01 13:31:08 +05302637
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002638/**
2639 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2640 * @dev: Pointer to net_device structure
2641 *
2642 * This is called in response to ifconfig up
2643 *
2644 * Return: 0 for success; non-zero for failure
2645 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002646static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002647{
2648 int ret;
2649
2650 cds_ssr_protect(__func__);
2651 ret = __hdd_open(dev);
2652 cds_ssr_unprotect(__func__);
2653
2654 return ret;
2655}
2656
2657/**
2658 * __hdd_stop() - HDD stop function
2659 * @dev: Pointer to net_device structure
2660 *
2661 * This is called in response to ifconfig down
2662 *
2663 * Return: 0 for success; non-zero for failure
2664 */
2665static int __hdd_stop(struct net_device *dev)
2666{
Jeff Johnson9d295242017-08-29 14:39:48 -07002667 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002668 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002669 int ret;
2670
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002671 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002672
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302673 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002674 adapter->sessionId, adapter->device_mode));
2675
2676 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302677 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002678 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002679
2680 /* Nothing to be done if the interface is not opened */
2681 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002682 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002683 return -ENODEV;
2684 }
2685
2686 /* Make sure the interface is marked as closed */
2687 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302688
2689 hdd_debug("Disabling Auto Power save timer");
2690 sme_ps_disable_auto_ps_timer(
2691 WLAN_HDD_GET_HAL_CTX(adapter),
2692 adapter->sessionId);
2693
2694 /*
2695 * Disable TX on the interface, after this hard_start_xmit() will not
2696 * be called on that interface
2697 */
2698 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302699 wlan_hdd_netif_queue_control(adapter,
2700 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2701 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002702
2703 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002704 * NAN data interface is different in some sense. The traffic on NDI is
2705 * bursty in nature and depends on the need to transfer. The service
2706 * layer may down the interface after the usage and up again when
2707 * required. In some sense, the NDI is expected to be available
2708 * (like SAP) iface until NDI delete request is issued by the service
2709 * layer. Skip BSS termination and adapter deletion for NAN Data
2710 * interface (NDI).
2711 */
2712 if (WLAN_HDD_IS_NDI(adapter))
2713 return 0;
2714
2715 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002716 * The interface is marked as down for outside world (aka kernel)
2717 * But the driver is pretty much alive inside. The driver needs to
2718 * tear down the existing connection on the netdev (session)
2719 * cleanup the data pipes and wait until the control plane is stabilized
2720 * for this interface. The call also needs to wait until the above
2721 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002722 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002723 * That is intentional to be able to scan if it is a STA/P2P interface
2724 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302725 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002726
2727 /* DeInit the adapter. This ensures datapath cleanup as well */
2728 hdd_deinit_adapter(hdd_ctx, adapter, true);
2729
Arun Khandavallifae92942016-08-01 13:31:08 +05302730
2731 /*
2732 * Find if any iface is up. If any iface is up then can't put device to
2733 * sleep/power save mode
2734 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302735 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002736 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302737 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302738 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302739 hdd_prevent_suspend_timeout(
2740 hdd_ctx->config->iface_change_wait_time,
2741 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302742 }
2743
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002744 EXIT();
2745 return 0;
2746}
2747
2748/**
2749 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2750 * @dev: pointer to net_device structure
2751 *
2752 * This is called in response to ifconfig down
2753 *
2754 * Return: 0 for success and error number for failure
2755 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002756static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002757{
2758 int ret;
2759
2760 cds_ssr_protect(__func__);
2761 ret = __hdd_stop(dev);
2762 cds_ssr_unprotect(__func__);
2763
2764 return ret;
2765}
2766
2767/**
2768 * __hdd_uninit() - HDD uninit function
2769 * @dev: Pointer to net_device structure
2770 *
2771 * This is called during the netdev unregister to uninitialize all data
2772 * associated with the device
2773 *
2774 * Return: None
2775 */
2776static void __hdd_uninit(struct net_device *dev)
2777{
Jeff Johnson9d295242017-08-29 14:39:48 -07002778 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002779 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002780
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002781 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002782
2783 do {
2784 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002785 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002786 break;
2787 }
2788
Jeff Johnson399c6272017-08-30 10:51:00 -07002789 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2790 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002791 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002792 break;
2793 }
2794
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002795 if (dev != adapter->dev)
2796 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002797
Jeff Johnson399c6272017-08-30 10:51:00 -07002798 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002799
2800 /* after uninit our adapter structure will no longer be valid */
2801 adapter->dev = NULL;
2802 adapter->magic = 0;
2803 } while (0);
2804
2805 EXIT();
2806}
2807
2808/**
2809 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2810 * @dev: pointer to net_device structure
2811 *
2812 * This is called during the netdev unregister to uninitialize all data
2813 * associated with the device
2814 *
2815 * Return: none
2816 */
2817static void hdd_uninit(struct net_device *dev)
2818{
2819 cds_ssr_protect(__func__);
2820 __hdd_uninit(dev);
2821 cds_ssr_unprotect(__func__);
2822}
2823
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002824static int hdd_open_cesium_nl_sock(void)
2825{
2826#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2827 struct netlink_kernel_cfg cfg = {
2828 .groups = WLAN_NLINK_MCAST_GRP_ID,
2829 .input = NULL
2830 };
2831#endif
2832 int ret = 0;
2833
2834#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2835 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2836#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2837 THIS_MODULE,
2838#endif
2839 &cfg);
2840#else
2841 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2842 WLAN_NLINK_MCAST_GRP_ID,
2843 NULL, NULL, THIS_MODULE);
2844#endif
2845
2846 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002847 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002848 ret = -ECONNREFUSED;
2849 }
2850
2851 return ret;
2852}
2853
2854static void hdd_close_cesium_nl_sock(void)
2855{
2856 if (NULL != cesium_nl_srv_sock) {
2857 netlink_kernel_release(cesium_nl_srv_sock);
2858 cesium_nl_srv_sock = NULL;
2859 }
2860}
2861
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002862/**
2863 * __hdd_set_mac_address() - set the user specified mac address
2864 * @dev: Pointer to the net device.
2865 * @addr: Pointer to the sockaddr.
2866 *
2867 * This function sets the user specified mac address using
2868 * the command ifconfig wlanX hw ether <mac adress>.
2869 *
2870 * Return: 0 for success, non zero for failure
2871 */
2872static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2873{
Jeff Johnson9d295242017-08-29 14:39:48 -07002874 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002875 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002876 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302877 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878 int ret;
2879
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002880 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002881
2882 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2883 ret = wlan_hdd_validate_context(hdd_ctx);
2884 if (0 != ret)
2885 return ret;
2886
2887 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2888 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2889
2890 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302891 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002892}
2893
2894/**
2895 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2896 * function from SSR
2897 * @dev: pointer to net_device structure
2898 * @addr: Pointer to the sockaddr
2899 *
2900 * This function sets the user specified mac address using
2901 * the command ifconfig wlanX hw ether <mac adress>.
2902 *
2903 * Return: 0 for success.
2904 */
2905static int hdd_set_mac_address(struct net_device *dev, void *addr)
2906{
2907 int ret;
2908
2909 cds_ssr_protect(__func__);
2910 ret = __hdd_set_mac_address(dev, addr);
2911 cds_ssr_unprotect(__func__);
2912
2913 return ret;
2914}
2915
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002916uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002917{
2918 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002919
Anurag Chouhan6d760662016-02-20 16:05:43 +05302920 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002921 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2922 break;
2923 }
2924
Anurag Chouhan6d760662016-02-20 16:05:43 +05302925 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926 return NULL;
2927
2928 hdd_ctx->config->intfAddrMask |= (1 << i);
2929 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2930}
2931
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07002932void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
2933 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002934{
2935 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002936
Anurag Chouhan6d760662016-02-20 16:05:43 +05302937 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002938 if (!memcmp(releaseAddr,
2939 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2940 6)) {
2941 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2942 break;
2943 }
2944 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002945}
2946
2947#ifdef WLAN_FEATURE_PACKET_FILTERING
2948/**
2949 * __hdd_set_multicast_list() - set the multicast address list
2950 * @dev: Pointer to the WLAN device.
2951 * @skb: Pointer to OS packet (sk_buff).
2952 *
2953 * This funciton sets the multicast address list.
2954 *
2955 * Return: None
2956 */
2957static void __hdd_set_multicast_list(struct net_device *dev)
2958{
Jeff Johnson9d295242017-08-29 14:39:48 -07002959 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002960 int i = 0, status;
2961 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002962 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302963 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2964 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2965 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002966
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002967 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302968 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302969 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302970
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002971 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302972 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302973 goto out;
2974
Dustin Brownc788acb2017-08-01 17:43:51 -07002975 status = hdd_validate_adapter(adapter);
2976 if (status)
2977 goto out;
2978
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302979 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2980 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002981 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302982 goto out;
2983 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002984
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302985 /* Delete already configured multicast address list */
2986 if (adapter->mc_addr_list.mc_cnt > 0) {
2987 hdd_info("clear previously configured MC address list");
2988 hdd_disable_and_flush_mc_addr_list(adapter,
2989 pmo_mc_list_change_notify);
2990 }
2991
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002993 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302994 hdd_disable_and_flush_mc_addr_list(adapter,
2995 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002996 } else {
2997 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302998 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002999 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303000 pmo_ucfg_max_mc_addr_supported(psoc));
3001 hdd_disable_and_flush_mc_addr_list(adapter,
3002 pmo_mc_list_change_notify);
3003 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003004 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003005 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003006 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303007 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003008 if (i == mc_count)
3009 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303010 memset(&(mc_list_request->mc_addr[i].bytes),
3011 0, ETH_ALEN);
3012 memcpy(&(mc_list_request->mc_addr[i].bytes),
3013 ha->addr, ETH_ALEN);
3014 hdd_info("mlist[%d] = %pM", i,
3015 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003016 i++;
3017 }
3018 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303019
3020 mc_list_request->psoc = psoc;
3021 mc_list_request->vdev_id = adapter->sessionId;
3022 mc_list_request->count = mc_count;
3023 status = hdd_cache_mc_addr_list(mc_list_request);
3024 if (status == 0) {
3025 hdd_enable_mc_addr_filtering(adapter,
3026 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003027 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303028 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303030out:
3031 if (mc_list_request)
3032 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303033 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003034}
3035
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303036
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003037/**
3038 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3039 * @dev: pointer to net_device
3040 *
3041 * Return: none
3042 */
3043static void hdd_set_multicast_list(struct net_device *dev)
3044{
3045 cds_ssr_protect(__func__);
3046 __hdd_set_multicast_list(dev);
3047 cds_ssr_unprotect(__func__);
3048}
3049#endif
3050
3051/**
3052 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3053 * @dev: Pointer to the WLAN device.
3054 * @skb: Pointer to OS packet (sk_buff).
3055 *
3056 * This function is registered with the Linux OS for network
3057 * core to decide which queue to use first.
3058 *
3059 * Return: ac, Queue Index/access category corresponding to UP in IP header
3060 */
3061static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3062#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3063 , void *accel_priv
3064#endif
3065#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3066 , select_queue_fallback_t fallback
3067#endif
3068)
3069{
3070 return hdd_wmm_select_queue(dev, skb);
3071}
3072
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003073static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003074 .ndo_open = hdd_open,
3075 .ndo_stop = hdd_stop,
3076 .ndo_uninit = hdd_uninit,
3077 .ndo_start_xmit = hdd_hard_start_xmit,
3078 .ndo_tx_timeout = hdd_tx_timeout,
3079 .ndo_get_stats = hdd_get_stats,
3080 .ndo_do_ioctl = hdd_ioctl,
3081 .ndo_set_mac_address = hdd_set_mac_address,
3082 .ndo_select_queue = hdd_select_queue,
3083#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003084 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003085#endif
3086};
3087
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003088/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003089static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003090 .ndo_open = hdd_mon_open,
3091 .ndo_stop = hdd_stop,
3092 .ndo_get_stats = hdd_get_stats,
3093};
3094
3095/**
3096 * hdd_set_station_ops() - update net_device ops for monitor mode
3097 * @pWlanDev: Handle to struct net_device to be updated.
3098 * Return: None
3099 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003100void hdd_set_station_ops(struct net_device *pWlanDev)
3101{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003102 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
3103 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
3104 else
3105 pWlanDev->netdev_ops = &wlan_drv_ops;
3106}
3107
3108/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003109 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3110 * @hdd_ctx: global hdd context
3111 * @macAddr: mac address to assign to the interface
3112 * @name: User-visible name of the interface
3113 *
3114 * hdd adapter pointer would point to the netdev->priv space, this function
3115 * would retrive the pointer, and setup the hdd adapter configuration.
3116 *
3117 * Return: the pointer to hdd adapter, otherwise NULL
3118 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003119static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003120 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003121 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122 const char *name)
3123{
3124 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003125 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003126 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127 /*
3128 * cfg80211 initialization and registration....
3129 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003130 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003131#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3132 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003134 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3135 hdd_mon_mode_ether_setup : ether_setup),
3136 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137
3138 if (pWlanDev != NULL) {
3139
3140 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003141 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003142
Jeff Johnson9d295242017-08-29 14:39:48 -07003143 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303144 sta_ctx = &adapter->sessionCtx.station;
3145 qdf_mem_set(sta_ctx->conn_info.staId,
3146 sizeof(sta_ctx->conn_info.staId),
3147 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003149 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303151 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152
3153 init_completion(&adapter->session_open_comp_var);
3154 init_completion(&adapter->session_close_comp_var);
3155 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303156 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003157 init_completion(&adapter->linkup_event_var);
3158 init_completion(&adapter->cancel_rem_on_chan_var);
3159 init_completion(&adapter->rem_on_chan_ready_event);
3160 init_completion(&adapter->sta_authorized_event);
3161 init_completion(&adapter->offchannel_tx_event);
3162 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003163 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164 init_completion(&adapter->change_country_code);
3165
3166
3167 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303168 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169
3170 adapter->offloads_configured = false;
3171 adapter->isLinkUpSvcNeeded = false;
3172 adapter->higherDtimTransition = true;
3173 /* Init the net_device structure */
3174 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3175
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303176 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303178 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179 sizeof(tSirMacAddr));
3180 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181
3182 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3183 pWlanDev->features |=
3184 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3185 pWlanDev->features |= NETIF_F_RXCSUM;
3186
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003187 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3188
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003189 hdd_set_station_ops(adapter->dev);
3190
Dustin Brownc81dd412017-08-15 16:26:28 -07003191 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003193 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194 adapter->wdev.wiphy = hdd_ctx->wiphy;
3195 adapter->wdev.netdev = pWlanDev;
3196 /* set pWlanDev's parent to underlying device */
3197 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3198 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303199 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303201 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202 }
3203
3204 return adapter;
3205}
3206
Jeff Johnson9d295242017-08-29 14:39:48 -07003207static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003209 struct net_device *dev = adapter->dev;
3210 int ret;
3211
3212 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003213
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003214 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003215 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3216
3217 ret = dev_alloc_name(dev, dev->name);
3218 if (ret < 0) {
3219 hdd_err(
3220 "unable to get dev name: %s, err = 0x%x",
3221 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303222 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003223 }
3224 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003225
3226 ret = register_netdevice(dev);
3227 if (ret) {
3228 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3229 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303230 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003231 }
3232 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003233 ret = register_netdev(dev);
3234 if (ret) {
3235 hdd_err("register_netdev(%s) failed, err = 0x%x",
3236 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303237 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003238 }
3239 }
3240 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3241
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003242 EXIT();
3243
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303244 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003245}
3246
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003247QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003248{
Jeff Johnson9d295242017-08-29 14:39:48 -07003249 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250
3251 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003252 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303253 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003254 }
3255
3256 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003257 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303258 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003259 }
3260
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003261 /*
3262 * For NAN Data interface, the close session results in the final
3263 * indication to the userspace
3264 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003265 if (adapter->device_mode == QDF_NDI_MODE)
3266 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003267
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3269
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270 /*
3271 * We can be blocked while waiting for scheduled work to be
3272 * flushed, and the adapter structure can potentially be freed, in
3273 * which case the magic will have been reset. So make sure the
3274 * magic is still good, and hence the adapter structure is still
3275 * valid, before signaling completion
3276 */
3277 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3278 complete(&adapter->session_close_comp_var);
3279
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303280 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003281}
3282
Jeff Johnson9d295242017-08-29 14:39:48 -07003283int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003284{
Dustin Brownd28772b2017-03-17 14:16:07 -07003285 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286
Dustin Brownd28772b2017-03-17 14:16:07 -07003287 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003288 if (QDF_IS_STATUS_ERROR(status))
3289 return qdf_status_to_os_return(status);
3290
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003291 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003292 if (QDF_IS_STATUS_ERROR(status))
3293 return qdf_status_to_os_return(status);
3294
3295 if (wma_capability_enhanced_mcast_filter())
3296 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3297 else
3298 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003299
3300 return qdf_status_to_os_return(status);
3301}
3302
Jeff Johnson9d295242017-08-29 14:39:48 -07003303int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003304{
3305 QDF_STATUS status;
3306 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003307 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003308 unsigned long rc;
3309
3310 hdd_info("destroying vdev %d", adapter->sessionId);
3311
3312 /* vdev created sanity check */
3313 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3314 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3315 return -EINVAL;
3316 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003317 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003318 /*
3319 * In SSR case, there is no need to destroy vdev in firmware since
3320 * it has already asserted. vdev can be released directly.
3321 */
3322 if (cds_is_driver_recovering())
3323 goto release_vdev;
3324
Dustin Brownd28772b2017-03-17 14:16:07 -07003325 /* close sme session (destroy vdev in firmware via legacy API) */
3326 INIT_COMPLETION(adapter->session_close_comp_var);
3327 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3328 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3329 hdd_sme_close_session_callback, adapter);
3330 if (QDF_IS_STATUS_ERROR(status)) {
3331 hdd_err("failed to close sme session: %d", status);
3332 return qdf_status_to_os_return(status);
3333 }
3334
3335 /* block on a completion variable until sme session is closed */
3336 rc = wait_for_completion_timeout(
3337 &adapter->session_close_comp_var,
3338 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3339 if (!rc) {
3340 hdd_err("timed out waiting for close sme session: %ld", rc);
3341 if (adapter->device_mode == QDF_NDI_MODE)
3342 hdd_ndp_session_end_handler(adapter);
3343 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3344 return -ETIMEDOUT;
3345 }
Yue Maf9782842017-05-08 12:49:49 -07003346release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003347 /* do vdev logical destroy via objmgr */
3348 errno = hdd_objmgr_destroy_vdev(adapter);
3349 if (errno) {
3350 hdd_err("failed to destroy objmgr vdev: %d", errno);
3351 return errno;
3352 }
3353
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003354 /* now that sme session is closed, allow physical vdev destroy */
3355 errno = hdd_objmgr_release_vdev(adapter);
3356 if (errno) {
3357 hdd_err("failed to release objmgr vdev: %d", errno);
3358 return errno;
3359 }
3360
Dustin Brownd28772b2017-03-17 14:16:07 -07003361 hdd_info("vdev destroyed successfully");
3362
3363 return 0;
3364}
3365
Jeff Johnson9d295242017-08-29 14:39:48 -07003366int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003367{
3368 QDF_STATUS status;
3369 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003370 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003371 uint32_t type;
3372 uint32_t sub_type;
3373 unsigned long rc;
3374
3375 hdd_info("creating new vdev");
3376
3377 /* determine vdev (sub)type */
3378 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303379 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003380 hdd_err("failed to get vdev type: %d", status);
3381 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003382 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003383
3384 /* do vdev create via objmgr */
3385 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003386 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003387 if (errno) {
3388 hdd_err("failed to create objmgr vdev: %d", errno);
3389 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003390 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003391
3392 /* Open a SME session (prepare vdev in firmware via legacy API) */
3393 INIT_COMPLETION(adapter->session_open_comp_var);
3394 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3395 (uint8_t *)&adapter->macAddressCurrent,
3396 adapter->sessionId, type, sub_type);
3397 if (QDF_IS_STATUS_ERROR(status)) {
3398 hdd_err("failed to open sme session: %d", status);
3399 errno = qdf_status_to_os_return(status);
3400 goto objmgr_vdev_destroy;
3401 }
3402
3403 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 rc = wait_for_completion_timeout(
3405 &adapter->session_open_comp_var,
3406 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3407 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003408 hdd_err("timed out waiting for open sme session: %ld", rc);
3409 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303410 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3411 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003412 }
3413
3414 /* firmware ready for component communication, raise vdev_ready event */
3415 errno = hdd_vdev_ready(adapter);
3416 if (errno) {
3417 hdd_err("failed to dispatch vdev ready event: %d", errno);
3418 goto hdd_vdev_destroy;
3419 }
3420
3421 hdd_info("vdev %d created successfully", adapter->sessionId);
3422
3423 return 0;
3424
3425 /*
3426 * Due to legacy constraints, we need to destroy in the same order as
3427 * create. So, split error handling into 2 cases to accommodate.
3428 */
3429
3430objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003431 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003432
3433 return errno;
3434
3435hdd_vdev_destroy:
3436 QDF_BUG(!hdd_vdev_destroy(adapter));
3437
3438 return errno;
3439}
3440
Jeff Johnson9d295242017-08-29 14:39:48 -07003441QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003442{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003443 struct hdd_station_ctx *sta_ctx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003444 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003445 QDF_STATUS status;
3446 int ret_val;
3447
3448 ret_val = hdd_vdev_create(adapter);
3449 if (ret_val) {
3450 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303451 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 }
3453
Dustin Brownd28772b2017-03-17 14:16:07 -07003454 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3455 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3456 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003457 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003458
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003459 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003460 status = hdd_register_wext(adapter->dev);
3461 if (QDF_IS_STATUS_ERROR(status)) {
3462 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463 goto error_register_wext;
3464 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003465 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003466
Jeff Johnsond377dce2017-10-04 10:32:42 -07003467 qdf_mem_set(sta_ctx->conn_info.staId,
3468 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303469
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003470 /* set fast roaming capability in sme session */
3471 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3472 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003474 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475 hdd_ctx->config->OperatingChannel;
3476
3477 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003478 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479
3480 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303481 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003482 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483 status, status);
3484 goto error_init_txrx;
3485 }
3486
3487 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3488
3489 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303490 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003491 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492 status, status);
3493 goto error_wmm_init;
3494 }
3495
3496 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3497
Naveen Rawat247a8682017-06-05 15:00:31 -07003498 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499 WMI_PDEV_PARAM_BURST_ENABLE,
3500 hdd_ctx->config->enableSifsBurst,
3501 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003502 if (ret_val)
3503 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003505 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303506 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003508error_wmm_init:
3509 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3510 hdd_deinit_tx_rx(adapter);
3511error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003512 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003513error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003514 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003515
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516 return status;
3517}
3518
Jeff Johnson9d295242017-08-29 14:39:48 -07003519void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003520{
Wu Gao02bd75b2017-10-13 18:34:02 +08003521 hdd_debug("Cleanup action frame");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003522}
3523
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303524/**
3525 * hdd_station_adapter_deinit() - De-initialize the station adapter
3526 * @hdd_ctx: global hdd context
3527 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003528 * @rtnl_held: Used to indicate whether or not the caller is holding
3529 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303530 *
3531 * This function De-initializes the STA/P2P/OCB adapter.
3532 *
3533 * Return: None.
3534 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003535static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003536 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003537 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303538{
3539 ENTER_DEV(adapter->dev);
3540
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303541 if (adapter->dev) {
3542 if (rtnl_held)
3543 adapter->dev->wireless_handlers = NULL;
3544 else {
3545 rtnl_lock();
3546 adapter->dev->wireless_handlers = NULL;
3547 rtnl_unlock();
3548 }
3549 }
3550
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303551 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3552 hdd_deinit_tx_rx(adapter);
3553 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3554 }
3555
3556 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3557 hdd_wmm_adapter_close(adapter);
3558 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3559 }
3560
3561 hdd_cleanup_actionframe(hdd_ctx, adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303562
3563 EXIT();
3564}
3565
3566/**
3567 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3568 * @hdd_ctx: global hdd context
3569 * @adapter: HDD adapter
3570 * @rtnl_held: the rtnl lock hold flag
3571 * This function De-initializes the AP/P2PGo adapter.
3572 *
3573 * Return: None.
3574 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003575static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003576 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003577 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303578{
3579 ENTER_DEV(adapter->dev);
3580
3581 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3582 hdd_wmm_adapter_close(adapter);
3583 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3584 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003585 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303586
3587 hdd_cleanup_actionframe(hdd_ctx, adapter);
3588
3589 hdd_unregister_hostapd(adapter, rtnl_held);
3590
3591 EXIT();
3592}
3593
Jeff Johnson9d295242017-08-29 14:39:48 -07003594void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003595 bool rtnl_held)
3596{
3597 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303598
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003600 case QDF_STA_MODE:
3601 case QDF_P2P_CLIENT_MODE:
3602 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303604 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605 break;
3606 }
3607
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003608 case QDF_SAP_MODE:
3609 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610 {
3611
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303612 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003613 break;
3614 }
3615
3616 default:
3617 break;
3618 }
3619
3620 EXIT();
3621}
3622
Jeff Johnson9d295242017-08-29 14:39:48 -07003623static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003624 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625{
3626 struct net_device *pWlanDev = NULL;
3627
3628 if (adapter)
3629 pWlanDev = adapter->dev;
3630 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003631 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003632 return;
3633 }
3634
Rajeev Kumardca5f812016-02-04 17:28:06 -08003635 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303636
3637 if (adapter->scan_info.default_scan_ies) {
3638 qdf_mem_free(adapter->scan_info.default_scan_ies);
3639 adapter->scan_info.default_scan_ies = NULL;
3640 }
3641
Komal Seelama89be8d2016-09-29 11:09:26 +05303642 hdd_adapter_runtime_suspend_denit(adapter);
3643
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644 /*
3645 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3646 * the driver is almost closed and cannot handle either control
3647 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003648 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3649 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003650 * is not right. Setting this flag helps hdd_stop() to recognize that
3651 * the interface is closed and restricts any operations on that
3652 */
3653 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3654
3655 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003656 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003657 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003658 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003659 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 /*
3661 * Note that the adapter is no longer valid at this point
3662 * since the memory has been reclaimed
3663 */
3664 }
3665}
3666
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003667static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003668 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003669{
3670 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003671 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303672 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003673
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303675 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003676 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303678 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303680 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003681 }
3682 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3683 adapterNode = pNext;
3684 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303685 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003686}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003687
Arun Khandavalli2358d522016-05-16 18:05:37 +05303688#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3689/**
3690 * hdd_set_fw_log_params() - Set log parameters to FW
3691 * @hdd_ctx: HDD Context
3692 * @adapter: HDD Adapter
3693 *
3694 * This function set the FW Debug log level based on the INI.
3695 *
3696 * Return: None
3697 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003698static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003699 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303700{
3701 uint8_t count = 0, numentries = 0,
3702 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3703 uint32_t value = 0;
3704 int ret;
3705
Arun Khandavallifae92942016-08-01 13:31:08 +05303706 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3707 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003708 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303709 return;
3710 }
3711
Arun Khandavallifae92942016-08-01 13:31:08 +05303712 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303713 hdd_ctx->fw_log_settings.dl_type =
3714 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003715 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303716 WMI_DBGLOG_TYPE,
3717 hdd_ctx->config->enableFwLogType,
3718 DBG_CMD);
3719 if (ret != 0)
3720 hdd_err("Failed to enable FW log type ret %d",
3721 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303722
3723 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303724 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003725 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303726 WMI_DBGLOG_LOG_LEVEL,
3727 hdd_ctx->config->enableFwLogLevel,
3728 DBG_CMD);
3729 if (ret != 0)
3730 hdd_err("Failed to enable FW log level ret %d",
3731 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303732
3733 hdd_string_to_u8_array(
3734 hdd_ctx->config->enableFwModuleLogLevel,
3735 moduleloglevel,
3736 &numentries,
3737 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3738
3739 while (count < numentries) {
3740 /*
3741 * FW module log level input string looks like
3742 * below:
3743 * gFwDebugModuleLoglevel=<FW Module ID>,
3744 * <Log Level>,...
3745 * For example:
3746 * gFwDebugModuleLoglevel=
3747 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3748 * Above input string means :
3749 * For FW module ID 1 enable log level 0
3750 * For FW module ID 2 enable log level 1
3751 * For FW module ID 3 enable log level 2
3752 * For FW module ID 4 enable log level 3
3753 * For FW module ID 5 enable log level 4
3754 * For FW module ID 6 enable log level 5
3755 * For FW module ID 7 enable log level 6
3756 */
3757
Nishank Aggarwale239d962017-03-03 12:26:02 +05303758 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3759 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3760 hdd_err("Module id %d and dbglog level %d input length is more than max",
3761 moduleloglevel[count],
3762 moduleloglevel[count + 1]);
3763 return;
3764 }
3765
3766 value = moduleloglevel[count] << 16;
3767 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003768 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303769 WMI_DBGLOG_MOD_LOG_LEVEL,
3770 value, DBG_CMD);
3771 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303772 hdd_err("Failed to enable FW module log level %d ret %d",
3773 value, ret);
3774
3775 count += 2;
3776 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303777
Arun Khandavalli2358d522016-05-16 18:05:37 +05303778}
3779#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003780static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003781 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303782{
3783}
3784
3785#endif
3786
3787/**
3788 * hdd_set_fw_params() - Set parameters to firmware
3789 * @adapter: HDD adapter
3790 *
3791 * This function Sets various parameters to fw once the
3792 * adapter is started.
3793 *
3794 * Return: 0 on success or errno on failure
3795 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003796int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303797{
3798 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003799 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303800
3801 ENTER_DEV(adapter->dev);
3802
3803 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3804 if (!hdd_ctx)
3805 return -EINVAL;
3806
Dustin Brown732ab9c2017-06-15 13:24:09 -07003807 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3808 hdd_debug("FTM Mode is active; nothing to do");
3809 return 0;
3810 }
3811
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303812 ret = sme_cli_set_command(adapter->sessionId,
3813 WMI_PDEV_PARAM_DTIM_SYNTH,
3814 hdd_ctx->config->enable_lprx, PDEV_CMD);
3815 if (ret) {
3816 hdd_err("Failed to set LPRx");
3817 goto error;
3818 }
3819
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303820 if (adapter->device_mode == QDF_STA_MODE) {
3821 sme_set_smps_cfg(adapter->sessionId,
3822 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3823 hdd_ctx->config->upper_brssi_thresh);
3824
3825 sme_set_smps_cfg(adapter->sessionId,
3826 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3827 hdd_ctx->config->lower_brssi_thresh);
3828
3829 sme_set_smps_cfg(adapter->sessionId,
3830 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3831 hdd_ctx->config->enable_dtim_1chrx);
3832 }
3833
Dustin Brown732ab9c2017-06-15 13:24:09 -07003834 if (hdd_ctx->config->enable2x2) {
3835 hdd_debug("configuring 2x2 mode fw params");
3836
Naveen Rawat247a8682017-06-05 15:00:31 -07003837 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003838 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3839 hdd_ctx->config->enable_cck_tx_fir_override,
3840 PDEV_CMD);
3841 if (ret) {
3842 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3843 ret);
3844 goto error;
3845 }
3846 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303847#define HDD_DTIM_1CHAIN_RX_ID 0x5
3848#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003849 hdd_debug("configuring 1x1 mode fw params");
3850
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003851 /*
3852 * Disable DTIM 1 chain Rx when in 1x1,
3853 * we are passing two value
3854 * as param_id << 29 | param_value.
3855 * Below param_value = 0(disable)
3856 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003857 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003858 WMI_STA_SMPS_PARAM_CMDID,
3859 HDD_DTIM_1CHAIN_RX_ID <<
3860 HDD_SMPS_PARAM_VALUE_S,
3861 VDEV_CMD);
3862 if (ret) {
3863 hdd_err("DTIM 1 chain set failed %d", ret);
3864 goto error;
3865 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303866
Naveen Rawat247a8682017-06-05 15:00:31 -07003867 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003868 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3869 hdd_ctx->config->txchainmask1x1,
3870 PDEV_CMD);
3871 if (ret) {
3872 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3873 ret);
3874 goto error;
3875 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303876
Naveen Rawat247a8682017-06-05 15:00:31 -07003877 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003878 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3879 hdd_ctx->config->rxchainmask1x1,
3880 PDEV_CMD);
3881 if (ret) {
3882 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3883 ret);
3884 goto error;
3885 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303886#undef HDD_DTIM_1CHAIN_RX_ID
3887#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003888 }
3889
Naveen Rawat247a8682017-06-05 15:00:31 -07003890 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003891 WMI_PDEV_PARAM_HYST_EN,
3892 hdd_ctx->config->enableMemDeepSleep,
3893 PDEV_CMD);
3894 if (ret) {
3895 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3896 goto error;
3897 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303898
Naveen Rawat247a8682017-06-05 15:00:31 -07003899 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003900 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3901 hdd_ctx->config->rts_profile,
3902 VDEV_CMD);
3903 if (ret) {
3904 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3905 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303906 }
3907
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003908 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3909
3910 ret = wma_cli_set_command(adapter->sessionId,
3911 GEN_VDEV_PARAM_AMSDU,
3912 hdd_ctx->config->max_amsdu_num,
3913 GEN_CMD);
3914 if (ret != 0) {
3915 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3916 goto error;
3917 }
3918
Arun Khandavalli2358d522016-05-16 18:05:37 +05303919 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303920 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003921
Arun Khandavalli2358d522016-05-16 18:05:37 +05303922 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303923
Arun Khandavalli2358d522016-05-16 18:05:37 +05303924error:
3925 return -EINVAL;
3926}
3927
Ryan Hsu07495ea2016-01-21 15:25:39 -08003928/**
3929 * hdd_open_adapter() - open and setup the hdd adatper
3930 * @hdd_ctx: global hdd context
3931 * @session_type: type of the interface to be created
3932 * @iface_name: User-visible name of the interface
3933 * @macAddr: MAC address to assign to the interface
3934 * @name_assign_type: the name of assign type of the netdev
3935 * @rtnl_held: the rtnl lock hold flag
3936 *
3937 * This function open and setup the hdd adpater according to the device
3938 * type request, assign the name, the mac address assigned, and then prepared
3939 * the hdd related parameters, queue, lock and ready to start.
3940 *
3941 * Return: the pointer of hdd adapter, otherwise NULL.
3942 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003943struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003944 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003945 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003946 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947{
Jeff Johnson9d295242017-08-29 14:39:48 -07003948 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303950 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003951
3952 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3953 /*
3954 * Max limit reached on the number of vdevs configured by the
3955 * host. Return error
3956 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303957 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3958 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003959 return NULL;
3960 }
3961
3962 if (macAddr == NULL) {
3963 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303964 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003965 return NULL;
3966 }
3967 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303968 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303969 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3970 " already exists",
3971 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 return NULL;
3973 }
3974
3975 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003976 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003977 /* Reset locally administered bit if the device mode is STA */
3978 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303979 hdd_info("locally administered bit reset in sta mode: "
3980 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003982 case QDF_P2P_CLIENT_MODE:
3983 case QDF_P2P_DEVICE_MODE:
3984 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003985 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303986 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003987 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3988 name_assign_type,
3989 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990
3991 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303992 hdd_err("failed to allocate adapter for session %d",
3993 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994 return NULL;
3995 }
3996
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003997 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003999 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304001 else if (QDF_MONITOR_MODE == session_type)
4002 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004003 else
4004 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4005
4006 adapter->device_mode = session_type;
4007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004009 /*
4010 * Workqueue which gets scheduled in IPv4 notification
4011 * callback
4012 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4014 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015
4016#ifdef WLAN_NS_OFFLOAD
4017 /*
4018 * Workqueue which gets scheduled in IPv6
4019 * notification callback.
4020 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4022 hdd_ipv6_notifier_work_queue);
4023#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304025 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004026 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304027 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004028 }
4029
4030 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004031 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304033 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4034 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304035
Ravi Joshi1a292562017-05-18 16:28:54 -07004036 /* Initialize NAN Data Interface */
4037 if (QDF_NDI_MODE == session_type) {
4038 status = hdd_init_nan_data_mode(adapter);
4039 if (QDF_STATUS_SUCCESS != status)
4040 goto err_free_netdev;
4041 }
4042
4043 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004045 case QDF_P2P_GO_MODE:
4046 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004047 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4048 name_assign_type,
4049 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004051 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304052 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004053 return NULL;
4054 }
4055
4056 adapter->wdev.iftype =
4057 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004058 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004059 NL80211_IFTYPE_P2P_GO;
4060 adapter->device_mode = session_type;
4061
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004062 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304063 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004064 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4065 goto err_free_netdev;
4066 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004067 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304069 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4070 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304071
4072 /*
4073 * Workqueue which gets scheduled in IPv4 notification
4074 * callback
4075 */
4076 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4077 hdd_ipv4_notifier_work_queue);
4078
4079#ifdef WLAN_NS_OFFLOAD
4080 /*
4081 * Workqueue which gets scheduled in IPv6
4082 * notification callback.
4083 */
4084 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4085 hdd_ipv6_notifier_work_queue);
4086#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004087 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304088 case QDF_FTM_MODE:
4089 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4090 name_assign_type,
4091 "wlan0");
4092 if (NULL == adapter) {
4093 hdd_err("Failed to allocate adapter for FTM mode");
4094 return NULL;
4095 }
4096 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4097 adapter->device_mode = session_type;
4098 status = hdd_register_interface(adapter, rtnl_held);
4099 if (QDF_STATUS_SUCCESS != status) {
4100 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4101 goto err_free_netdev;
4102 }
4103 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004104 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304105 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304106 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4107 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304108 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004110 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304111 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 return NULL;
4113 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114
hqueaa33ee2017-05-04 17:56:35 +08004115 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4116
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304117 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004118 /* Add it to the hdd's session list. */
4119 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304120 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004121 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304122 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004124 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004125 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4126 }
4127 }
4128
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304129 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130 if (NULL != adapter) {
4131 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4132 adapter = NULL;
4133 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004134 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304135 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004136
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004137 return NULL;
4138 }
4139
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304140 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004141 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4142 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004143
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144 /* Adapter successfully added. Increment the vdev count */
4145 hdd_ctx->current_intf_count++;
4146
Jeff Johnson5880d792016-08-15 13:32:30 -07004147 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004148 hdd_ctx->current_intf_count);
4149
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004150 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004151 }
4152
Rajeev Kumardca5f812016-02-04 17:28:06 -08004153 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004154 hdd_err("Interface %s wow debug_fs init failed",
4155 netdev_name(adapter->dev));
4156
4157 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4158 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004159
4160 return adapter;
4161
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004162err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304164 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004165
4166 return NULL;
4167}
4168
Jeff Johnson9d295242017-08-29 14:39:48 -07004169QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004170 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004171{
4172 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304173 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004174
4175 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304176 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004177 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004178 status);
4179 return status;
4180 }
4181
Jeff Johnson57eb2732017-10-02 11:40:20 -07004182 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004183 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304184 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004185 break;
4186
4187 pCurrent = pNext;
4188 }
4189 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304190 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004191 /*
4192 * Here we are stopping global bus_bw timer & work per adapter.
4193 *
4194 * The reason is to fix one race condition between
4195 * bus bandwidth work and cleaning up an adapter.
4196 * Under some conditions, it is possible for the bus bandwidth
4197 * work to access a particularly destroyed adapter, leading to
4198 * use-after-free.
4199 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004200 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004201 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004202 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004203
4204 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004205 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4206 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004207 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004208 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304209 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210 adapterNode = NULL;
4211
Dustin Brown5ec6b552017-03-31 12:11:40 -07004212 /* conditionally restart the bw timer */
4213 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4214
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004215 /* Adapter removed. Decrement vdev count */
4216 if (hdd_ctx->current_intf_count != 0)
4217 hdd_ctx->current_intf_count--;
4218
4219 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304220 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304222
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304223 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004224}
4225
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004226/**
4227 * hdd_close_all_adapters - Close all open adapters
4228 * @hdd_ctx: Hdd context
4229 * rtnl_held: True if RTNL lock held
4230 *
4231 * Close all open adapters.
4232 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304233 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004234 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004235QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004236{
4237 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304238 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239
4240 ENTER();
4241
4242 do {
4243 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304244 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304245 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004246 pHddAdapterNode->adapter->macAddressCurrent.bytes);
4247 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004248 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304249 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304250 /* Adapter removed. Decrement vdev count */
4251 if (hdd_ctx->current_intf_count != 0)
4252 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004253 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304254 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004255
4256 EXIT();
4257
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304258 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259}
4260
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004261void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004262{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304263 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004265
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004266 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004267 case QDF_STA_MODE:
4268 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004270 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004271 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004272 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004273 break;
4274 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004275 case QDF_SAP_MODE:
4276 case QDF_P2P_GO_MODE:
4277 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004278 {
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004279 bssid = &adapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280 break;
4281 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004282 case QDF_FTM_MODE:
4283 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004284 default:
4285 /*
4286 * wlan_hdd_reset_prob_rspies should not have been called
4287 * for these kind of devices
4288 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004289 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004290 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291 return;
4292 }
4293
Anurag Chouhanc5548422016-02-24 18:33:27 +05304294 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004295 updateIE.smeSessionId = adapter->sessionId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004296 updateIE.ieBufferlength = 0;
4297 updateIE.pAdditionIEBuffer = NULL;
4298 updateIE.append = true;
4299 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004300 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004301 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304302 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004303 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 }
4305}
4306
Jeff Johnson9d295242017-08-29 14:39:48 -07004307QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308 const bool bCloseSession)
4309{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304310 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004311 struct hdd_wext_state *pWextState =
4312 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004313 union iwreq_data wrqu;
4314 tSirUpdateIE updateIE;
4315 unsigned long rc;
4316
4317 ENTER();
4318
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004319 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304320 wlan_hdd_netif_queue_control(adapter,
4321 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4322 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004323 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004324 case QDF_STA_MODE:
4325 case QDF_P2P_CLIENT_MODE:
4326 case QDF_IBSS_MODE:
4327 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004328 case QDF_NDI_MODE:
4329 if ((QDF_NDI_MODE == adapter->device_mode) ||
4330 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004331 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4332 hdd_is_connecting(
4333 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004334 INIT_COMPLETION(adapter->disconnect_comp_var);
4335 /*
4336 * For NDI do not use pWextState from sta_ctx, if needed
4337 * extract from ndi_ctx.
4338 */
4339 if (QDF_NDI_MODE == adapter->device_mode)
4340 qdf_ret_status = sme_roam_disconnect(
4341 hdd_ctx->hHal,
4342 adapter->sessionId,
4343 eCSR_DISCONNECT_REASON_NDI_DELETE);
4344 else if (pWextState->roamProfile.BSSType ==
4345 eCSR_BSS_TYPE_START_IBSS)
4346 qdf_ret_status = sme_roam_disconnect(
4347 hdd_ctx->hHal,
4348 adapter->sessionId,
4349 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004350 else if (QDF_STA_MODE == adapter->device_mode)
4351 qdf_ret_status =
4352 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004354 qdf_ret_status = sme_roam_disconnect(
4355 hdd_ctx->hHal,
4356 adapter->sessionId,
4357 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004358 /* success implies disconnect command got
4359 * queued up successfully
4360 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004361 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4362 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004363 rc = wait_for_completion_timeout(
4364 &adapter->disconnect_comp_var,
4365 msecs_to_jiffies
4366 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004367 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004368 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004370 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4371 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004372 memset(&wrqu, '\0', sizeof(wrqu));
4373 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4374 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4375 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4376 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304377 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004378 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004379
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304380 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304381 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004382
4383#ifdef WLAN_OPEN_SOURCE
4384 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4385#endif
4386
4387 hdd_deregister_tx_flow_control(adapter);
4388
4389#ifdef WLAN_NS_OFFLOAD
4390#ifdef WLAN_OPEN_SOURCE
4391 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4392#endif
4393#endif
4394
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304395 if (adapter->device_mode == QDF_STA_MODE)
4396 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4397 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 /*
4399 * It is possible that the caller of this function does not
4400 * wish to close the session
4401 */
Krunal Soni985b8132017-02-10 18:49:08 -08004402 if (true == bCloseSession) {
4403 if (0 != wlan_hdd_try_disconnect(adapter)) {
4404 hdd_err("Error: Can't disconnect adapter");
4405 return QDF_STATUS_E_FAILURE;
4406 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004407 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004408 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004409 break;
4410
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004411 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304412 /* Flush IPA exception path packets */
4413 hdd_ipa_flush(hdd_ctx);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004414
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004415 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004416 if (QDF_SAP_MODE == adapter->device_mode) {
4417 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4418 cds_flush_delayed_work(
4419 &adapter->acs_pending_work);
4420 clear_bit(ACS_PENDING, &adapter->event_flags);
4421 }
4422 }
Krunal Soni22208392017-09-29 18:10:34 -07004423 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004424
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004425 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004426 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004427 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004428 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4429
4430 hdd_deregister_tx_flow_control(adapter);
4431
Kapil Guptac1224bf2017-06-22 21:22:40 +05304432 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004433 mutex_lock(&hdd_ctx->sap_lock);
4434 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304435 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304436 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004437
4438 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004439 status = wlansap_stop_bss(
4440 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304442 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004443 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004444 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304445 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304446 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304447 qdf_status =
4448 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004449 qdf_stop_bss_event,
4450 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004451
Anurag Chouhance0dc992016-02-16 18:18:03 +05304452 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004453 hdd_err("failure waiting for wlansap_stop_bss %d",
4454 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004455 }
4456 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004457 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458 }
4459 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004460 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4461 adapter->device_mode,
4462 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004463
Anurag Chouhanc5548422016-02-24 18:33:27 +05304464 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004465 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466 updateIE.smeSessionId = adapter->sessionId;
4467 updateIE.ieBufferlength = 0;
4468 updateIE.pAdditionIEBuffer = NULL;
4469 updateIE.append = false;
4470 updateIE.notify = false;
4471 /* Probe bcn reset */
4472 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4473 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304474 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004475 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004476 }
4477 /* Assoc resp reset */
4478 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4479 &updateIE,
4480 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304481 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004482 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004483 }
4484 /* Reset WNI_CFG_PROBE_RSP Flags */
4485 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004487 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4488 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304489 /*
4490 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4491 */
4492 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4493 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4494
Peng Xu66162de2016-02-11 17:01:20 -08004495 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004496 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004497 mutex_unlock(&hdd_ctx->sap_lock);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304498
4499#ifdef WLAN_OPEN_SOURCE
4500 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4501#endif
4502
4503#ifdef WLAN_NS_OFFLOAD
4504#ifdef WLAN_OPEN_SOURCE
4505 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4506#endif
4507#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004508 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004509 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004510 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004511 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004512 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004513 break;
4514 default:
4515 break;
4516 }
4517
4518 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304519 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004520}
4521
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304522/**
4523 * hdd_deinit_all_adapters - deinit all adapters
4524 * @hdd_ctx: HDD context
4525 * @rtnl_held: True if RTNL lock held
4526 *
4527 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004528void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304529{
4530 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4531 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004532 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304533
4534 ENTER();
4535
4536 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4537
4538 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004539 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304540 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4541 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4542 adapter_node = next;
4543 }
4544
4545 EXIT();
4546}
4547
Dustin Brown27cd9942017-09-27 16:11:44 -07004548QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4549 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004550{
4551 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304552 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004553 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004554
4555 ENTER();
4556
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304557 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4558
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004559 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4560
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304561 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004562 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004563 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004564 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4565 adapterNode = pNext;
4566 }
4567
4568 EXIT();
4569
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304570 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571}
4572
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004573QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574{
4575 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304576 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004577 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004578 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004579 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004580
4581 ENTER();
4582
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304583 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4584
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004585 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4586
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304587 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004588 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004589 hdd_notice("Disabling queues for adapter type: %d",
4590 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304591
4592 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004593 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304594 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004595 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304596
Arun Khandavallicc544b32017-01-30 19:52:16 +05304597 if (hdd_ctx->config->sap_internal_restart &&
4598 adapter->device_mode == QDF_SAP_MODE) {
4599 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304600 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304601 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004602 if (test_bit(SOFTAP_BSS_STARTED,
4603 &adapter->event_flags)) {
4604 hdd_sap_indicate_disconnect_for_sta(adapter);
4605 hdd_cleanup_actionframe(hdd_ctx, adapter);
4606 hdd_sap_destroy_events(adapter);
4607 }
4608 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4609 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304610 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304611 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004612 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004613 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004614
Jeff Johnson690fe952017-10-25 11:48:39 -07004615 adapter->sessionCtx.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004616
4617 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004618 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4619 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004620 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4621 hdd_wmm_adapter_close(adapter);
4622 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4623 }
4624
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304625 if (adapter->device_mode == QDF_STA_MODE)
4626 hdd_clear_fils_connection_info(adapter);
4627
Wu Gao3545e642017-07-14 19:24:41 +08004628 if (adapter->device_mode == QDF_SAP_MODE) {
4629 /*
4630 * If adapter is SAP, set session ID to invalid
4631 * since SAP session will be cleanup during SSR.
4632 */
Wu Gao36717432016-11-21 15:09:48 +08004633 wlansap_set_invalid_session(
4634 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4635
Wu Gao3545e642017-07-14 19:24:41 +08004636 wlansap_cleanup_cac_timer(
4637 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4638 }
4639
Yue Mad5b4b9f2017-05-26 16:23:40 -07004640 /* Delete peers if any for STA and P2P client modes */
4641 if (adapter->device_mode == QDF_STA_MODE ||
4642 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004643 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004644 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004645 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004646
4647 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4648 peerMacAddr.bytes);
4649 }
4650
Yue Maf9782842017-05-08 12:49:49 -07004651 /* Destroy vdev which will be recreated during reinit. */
4652 hdd_vdev_destroy(adapter);
4653
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004654 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4655 adapterNode = pNext;
4656 }
4657
4658 EXIT();
4659
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304660 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004661}
4662
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004663bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304664{
4665 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4666 QDF_STATUS status;
4667 bool close_modules = true;
4668
Arun Khandavalliba479c42017-07-26 21:29:40 +05304669 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4670 hdd_info("FTM mode, don't close the module");
4671 return false;
4672 }
4673
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304674 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4675 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4676 if (test_bit(DEVICE_IFACE_OPENED,
Yeshwanth Sriram Guntuka4ce0a1b2017-10-17 17:55:45 +05304677 &adapter_node->adapter->event_flags) ||
4678 test_bit(SME_SESSION_OPENED,
4679 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004680 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304681 close_modules = false;
4682 break;
4683 }
4684 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4685 adapter_node = next;
4686 }
4687
4688 return close_modules;
4689}
4690
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304691bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304692{
4693 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4694 return true;
4695 else
4696 return false;
4697}
4698
Anurag Chouhanc4092922016-09-08 15:56:11 +05304699#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004700 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304701struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4702 struct ieee80211_channel *channel,
4703 const u8 *bssid, const u8 *ssid,
4704 size_t ssid_len)
4705{
4706 return cfg80211_get_bss(wiphy, channel, bssid,
4707 ssid, ssid_len,
4708 WLAN_CAPABILITY_ESS,
4709 WLAN_CAPABILITY_ESS);
4710}
4711#else
4712struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4713 struct ieee80211_channel *channel,
4714 const u8 *bssid, const u8 *ssid,
4715 size_t ssid_len)
4716{
4717 return cfg80211_get_bss(wiphy, channel, bssid,
4718 ssid, ssid_len,
4719 IEEE80211_BSS_TYPE_ESS,
4720 IEEE80211_PRIVACY_ANY);
4721}
4722#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304723
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304724#if defined CFG80211_CONNECT_BSS || \
4725 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304726#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304727 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304728/**
4729 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4730 * @timeout_reason: reason for connect timeout
4731 *
4732 * This function is used to convert host timeout
4733 * reason enum to kernel specific enum.
4734 *
4735 * Return: nl timeout enum
4736 */
4737static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4738 tSirResultCodes timeout_reason)
4739{
4740 switch (timeout_reason) {
4741 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4742 return NL80211_TIMEOUT_SCAN;
4743 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4744 return NL80211_TIMEOUT_AUTH;
4745 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4746 return NL80211_TIMEOUT_ASSOC;
4747 default:
4748 return NL80211_TIMEOUT_UNSPECIFIED;
4749 }
4750}
4751
4752/**
4753 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4754 * @dev: network device
4755 * @bssid: bssid to which we want to associate
4756 * @timeout_reason: reason for connect timeout
4757 *
4758 * This API is used to send connection timeout reason to supplicant
4759 *
4760 * Return: void
4761 */
4762static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4763 const u8 *bssid,
4764 tSirResultCodes timeout_reason)
4765{
4766 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004767
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304768 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4769
4770 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4771 nl_timeout_reason);
4772}
4773
4774/**
4775 * __hdd_connect_bss() - API to send connection status to supplicant
4776 * @dev: network device
4777 * @bssid: bssid to which we want to associate
4778 * @req_ie: Request Information Element
4779 * @req_ie_len: len of the req IE
4780 * @resp_ie: Response IE
4781 * @resp_ie_len: len of ht response IE
4782 * @status: status
4783 * @gfp: Kernel Flag
4784 * @timeout_reason: reason for connect timeout
4785 *
4786 * Return: void
4787 */
4788static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4789 struct cfg80211_bss *bss, const u8 *req_ie,
4790 size_t req_ie_len, const u8 *resp_ie,
4791 size_t resp_ie_len, int status, gfp_t gfp,
4792 tSirResultCodes timeout_reason)
4793{
4794 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004795
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304796 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4797
4798 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4799 resp_ie, resp_ie_len, status, gfp,
4800 nl_timeout_reason);
4801}
4802#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304803#if defined CFG80211_CONNECT_TIMEOUT || \
4804 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304805static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4806 const u8 *bssid,
4807 tSirResultCodes timeout_reason)
4808{
4809 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4810}
4811#endif
4812
4813static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4814 struct cfg80211_bss *bss, const u8 *req_ie,
4815 size_t req_ie_len, const u8 *resp_ie,
4816 size_t resp_ie_len, int status, gfp_t gfp,
4817 tSirResultCodes timeout_reason)
4818{
4819 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4820 resp_ie, resp_ie_len, status, gfp);
4821}
4822#endif
4823
Abhishek Singha84d3952016-09-13 13:45:05 +05304824/**
4825 * hdd_connect_bss() - API to send connection status to supplicant
4826 * @dev: network device
4827 * @bssid: bssid to which we want to associate
4828 * @req_ie: Request Information Element
4829 * @req_ie_len: len of the req IE
4830 * @resp_ie: Response IE
4831 * @resp_ie_len: len of ht response IE
4832 * @status: status
4833 * @gfp: Kernel Flag
4834 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304835 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304836 *
4837 * The API is a wrapper to send connection status to supplicant
4838 *
4839 * Return: Void
4840 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304841#if defined CFG80211_CONNECT_TIMEOUT || \
4842 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05304843static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4844 struct cfg80211_bss *bss, const u8 *req_ie,
4845 size_t req_ie_len, const u8 *resp_ie,
4846 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304847 bool connect_timeout,
4848 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304849{
4850 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304851 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304852 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304853 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4854 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304855}
4856#else
4857static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4858 struct cfg80211_bss *bss, const u8 *req_ie,
4859 size_t req_ie_len, const u8 *resp_ie,
4860 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304861 bool connect_timeout,
4862 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304863{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304864 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4865 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304866}
4867#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304868
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304869#if defined(WLAN_FEATURE_FILS_SK)
4870#if defined(CFG80211_CONNECT_DONE) || \
4871 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
4872#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
4873 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304874/**
4875 * hdd_populate_fils_params() - Populate FILS keys to connect response
4876 * @fils_params: connect response to supplicant
4877 * @fils_kek: FILS kek
4878 * @fils_kek_len: FILS kek length
4879 * @pmk: FILS PMK
4880 * @pmk_len: FILS PMK length
4881 * @pmkid: PMKID
4882 * @fils_seq_num: FILS Seq number
4883 *
4884 * Return: None
4885 */
4886static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4887 *fils_params, const uint8_t *fils_kek,
4888 size_t fils_kek_len, const uint8_t *pmk,
4889 size_t pmk_len, const uint8_t *pmkid,
4890 uint16_t fils_seq_num)
4891{
4892 /* Increament seq number to be used for next FILS */
4893 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4894 fils_params->update_erp_next_seq_num = true;
4895 fils_params->fils_kek = fils_kek;
4896 fils_params->fils_kek_len = fils_kek_len;
4897 fils_params->pmk = pmk;
4898 fils_params->pmk_len = pmk_len;
4899 fils_params->pmkid = pmkid;
4900}
4901#else
4902static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4903 *fils_params, const uint8_t
4904 *fils_kek, size_t fils_kek_len,
4905 const uint8_t *pmk, size_t pmk_len,
4906 const uint8_t *pmkid,
4907 uint16_t fils_seq_num)
4908{ }
4909#endif
4910
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304911void hdd_update_hlp_info(struct net_device *dev, tCsrRoamInfo *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304912{
4913 struct sk_buff *skb;
4914 uint16_t skb_len;
4915 struct llc_snap_hdr_t *llc_hdr;
4916 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304917 uint8_t *hlp_data;
4918 uint16_t hlp_data_len;
4919 struct fils_join_rsp_params *roam_fils_params
4920 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304921 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
4922
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304923 if (!roam_fils_params) {
4924 hdd_err("FILS Roam Param NULL");
4925 return;
4926 }
4927
4928 if (!roam_fils_params->hlp_data_len || !roam_fils_params->hlp_data) {
4929 hdd_err("FILS HLP Data NULL, len %d",
4930 roam_fils_params->hlp_data_len);
4931 return;
4932 }
4933
4934 hlp_data = roam_fils_params->hlp_data;
4935 hlp_data_len = roam_fils_params->hlp_data_len;
4936
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304937 /* Calculate skb length */
4938 skb_len = (2 * ETH_ALEN) + hlp_data_len;
4939 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
4940 if (skb == NULL) {
4941 hdd_err("HLP packet nbuf alloc fails");
4942 return;
4943 }
4944
4945 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
4946 QDF_MAC_ADDR_SIZE);
4947 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
4948 QDF_MAC_ADDR_SIZE);
4949
4950 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
4951 if (IS_SNAP(llc_hdr)) {
4952 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4953 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4954 }
4955
4956 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
4957
4958 /*
4959 * This HLP packet is formed from HLP info encapsulated
4960 * in assoc response frame which is AEAD encrypted.
4961 * Hence, this checksum validation can be set unnecessary.
4962 * i.e. network layer need not worry about checksum.
4963 */
4964 skb->ip_summed = CHECKSUM_UNNECESSARY;
4965
4966 status = hdd_rx_packet_cbk(padapter, skb);
4967 if (QDF_IS_STATUS_ERROR(status)) {
4968 hdd_err("Sending HLP packet fails");
4969 return;
4970 }
4971 hdd_debug("send HLP packet to netif successfully");
4972}
4973
4974/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304975 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4976 * @dev: network device
4977 * @bssid: bssid to which we want to associate
4978 * @bss: cfg80211 bss info
4979 * @roam_info: information about connected bss
4980 * @req_ie: Request Information Element
4981 * @req_ie_len: len of the req IE
4982 * @resp_ie: Response IE
4983 * @resp_ie_len: len of ht response IE
4984 * @status: status
4985 * @gfp: allocation flags
4986 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4987 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304988 *
4989 * This API is used as wrapper to send FILS key/sequence number
4990 * params etc. to supplicant in case of FILS connection
4991 *
4992 * Return: None
4993 */
4994static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4995 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4996 const u8 *req_ie, size_t req_ie_len,
4997 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004998 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304999 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305000{
5001 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305002 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5003 struct fils_join_rsp_params *roam_fils_params =
5004 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005005
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305006 qdf_mem_zero(&fils_params, sizeof(fils_params));
5007
5008 if (!roam_fils_params) {
5009 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5010 } else {
5011 fils_params.status = status;
5012 fils_params.bssid = bssid;
5013 fils_params.timeout_reason = timeout_reason;
5014 fils_params.req_ie = req_ie;
5015 fils_params.req_ie_len = req_ie_len;
5016 fils_params.resp_ie = resp_ie;
5017 fils_params.resp_ie_len = resp_ie_len;
5018 fils_params.bss = bss;
5019 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5020 roam_fils_params->kek_len,
5021 roam_fils_params->fils_pmk,
5022 roam_fils_params->fils_pmk_len,
5023 roam_fils_params->fils_pmkid,
5024 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305025 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305026 }
5027 hdd_debug("FILS indicate connect status %d seq no %d",
5028 fils_params.status,
5029 fils_params.fils_erp_next_seq_num);
5030
5031 cfg80211_connect_done(dev, &fils_params, gfp);
5032
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305033 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305034 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305035
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305036 /* Clear all the FILS key info */
5037 if (roam_fils_params && roam_fils_params->fils_pmk)
5038 qdf_mem_free(roam_fils_params->fils_pmk);
5039 if (roam_fils_params)
5040 qdf_mem_free(roam_fils_params);
5041 roam_info->fils_join_rsp = NULL;
5042}
5043#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005044static inline void
5045hdd_connect_done(struct net_device *dev, const u8 *bssid,
5046 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
5047 const u8 *req_ie, size_t req_ie_len,
5048 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5049 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305050 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305051{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305052#endif
5053#endif
5054
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305055#if defined(WLAN_FEATURE_FILS_SK) && \
5056 (defined(CFG80211_CONNECT_DONE) || \
5057 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305058/**
5059 * hdd_fils_update_connect_results() - API to send fils connection status to
5060 * supplicant.
5061 * @dev: network device
5062 * @bssid: bssid to which we want to associate
5063 * @bss: cfg80211 bss info
5064 * @roam_info: information about connected bss
5065 * @req_ie: Request Information Element
5066 * @req_ie_len: len of the req IE
5067 * @resp_ie: Response IE
5068 * @resp_ie_len: len of ht response IE
5069 * @status: status
5070 * @gfp: allocation flags
5071 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5072 * @timeout_reason: reason for connect timeout
5073 *
5074 * The API is a wrapper to send connection status to supplicant
5075 *
5076 * Return: 0 if success else failure
5077 */
5078static int hdd_fils_update_connect_results(struct net_device *dev,
5079 const u8 *bssid,
5080 struct cfg80211_bss *bss,
5081 tCsrRoamInfo *roam_info, const u8 *req_ie,
5082 size_t req_ie_len, const u8 *resp_ie,
5083 size_t resp_ie_len, u16 status, gfp_t gfp,
5084 bool connect_timeout,
5085 tSirResultCodes timeout_reason)
5086{
5087 ENTER();
5088 if (!roam_info || !roam_info->is_fils_connection)
5089 return -EINVAL;
5090
5091 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5092 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305093 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305094 return 0;
5095}
5096#else
5097static inline int hdd_fils_update_connect_results(struct net_device *dev,
5098 const u8 *bssid,
5099 struct cfg80211_bss *bss,
5100 tCsrRoamInfo *roam_info, const u8 *req_ie,
5101 size_t req_ie_len, const u8 *resp_ie,
5102 size_t resp_ie_len, u16 status, gfp_t gfp,
5103 bool connect_timeout,
5104 tSirResultCodes timeout_reason)
5105{
5106 return -EINVAL;
5107}
5108#endif
5109
Anurag Chouhanc4092922016-09-08 15:56:11 +05305110/**
5111 * hdd_connect_result() - API to send connection status to supplicant
5112 * @dev: network device
5113 * @bssid: bssid to which we want to associate
5114 * @roam_info: information about connected bss
5115 * @req_ie: Request Information Element
5116 * @req_ie_len: len of the req IE
5117 * @resp_ie: Response IE
5118 * @resp_ie_len: len of ht response IE
5119 * @status: status
5120 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305121 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305122 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305123 *
5124 * The API is a wrapper to send connection status to supplicant
5125 * and allow runtime suspend
5126 *
5127 * Return: Void
5128 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305129void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5130 tCsrRoamInfo *roam_info, const u8 *req_ie,
5131 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305132 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305133 bool connect_timeout,
5134 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305135{
Jeff Johnson9d295242017-08-29 14:39:48 -07005136 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305137 struct cfg80211_bss *bss = NULL;
5138
5139 if (WLAN_STATUS_SUCCESS == status) {
5140 struct ieee80211_channel *chan;
5141 int freq;
5142 int chan_no = roam_info->pBssDesc->channelId;
5143
5144 if (chan_no <= 14)
5145 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005146 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305147 else
5148 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005149 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305150
5151 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5152 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5153 roam_info->u.pConnectedProfile->SSID.ssId,
5154 roam_info->u.pConnectedProfile->SSID.length);
5155 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305156
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305157 if (hdd_fils_update_connect_results(dev, bssid, bss,
5158 roam_info, req_ie, req_ie_len, resp_ie,
5159 resp_ie_len, status, gfp, connect_timeout,
5160 timeout_reason) != 0) {
5161 hdd_connect_bss(dev, bssid, bss, req_ie,
5162 req_ie_len, resp_ie, resp_ie_len,
5163 status, gfp, connect_timeout, timeout_reason);
5164 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305165
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005166 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005167 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305168}
5169#else
5170void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5171 tCsrRoamInfo *roam_info, const u8 *req_ie,
5172 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305173 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305174 bool connect_timeout,
5175 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305176{
Jeff Johnson9d295242017-08-29 14:39:48 -07005177 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305178
Anurag Chouhanc4092922016-09-08 15:56:11 +05305179 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5180 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005181
5182 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005183 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305184}
5185#endif
5186
5187
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005188QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005189{
5190 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305191 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005192 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005193#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305194 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005195#endif
5196 eConnectionState connState;
5197
5198 ENTER();
5199
5200 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305201 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005202 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203
Arun Khandavallifae92942016-08-01 13:31:08 +05305204 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305205 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005207 hdd_wmm_init(adapter);
5208
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005209 adapter->scan_info.mScanPending = false;
5210
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005211 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005212 case QDF_STA_MODE:
5213 case QDF_P2P_CLIENT_MODE:
5214 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005215
5216 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5217 ->conn_info.connState;
5218
5219 hdd_init_station_mode(adapter);
5220 /* Open the gates for HDD to receive Wext commands */
5221 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005222
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005223 /* Indicate disconnect event to supplicant
5224 * if associated previously
5225 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005226 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005227 eConnectionState_IbssConnected == connState ||
5228 eConnectionState_NotConnected == connState ||
5229 eConnectionState_IbssDisconnected == connState ||
5230 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233 memset(&wrqu, '\0', sizeof(wrqu));
5234 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5235 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5236 wireless_send_event(adapter->dev, SIOCGIWAP,
5237 &wrqu, NULL);
5238 adapter->sessionCtx.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005239 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240
5241 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305242 wlan_hdd_cfg80211_indicate_disconnect(
5243 adapter->dev, false,
5244 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005245 } else if (eConnectionState_Connecting == connState) {
5246 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005247 * Indicate connect failure to supplicant if we
5248 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305250 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305251 NULL, 0, NULL, 0,
5252 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005253 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254 }
5255
5256 hdd_register_tx_flow_control(adapter,
5257 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005258 hdd_tx_resume_cb,
5259 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005260
5261 break;
5262
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005263 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005264 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305265 hdd_init_ap_mode(adapter, true);
5266
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005267 break;
5268
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005269 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005270#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005271 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005272 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5273#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005274 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005275 /* event supplicant to restart */
5276 cfg80211_del_sta(adapter->dev,
5277 (const u8 *)&bcastMac.bytes[0],
5278 GFP_KERNEL);
5279#endif
5280 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305281 case QDF_MONITOR_MODE:
5282 hdd_init_station_mode(adapter);
5283 hdd_set_mon_rx_cb(adapter->dev);
5284 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5285 adapter->mon_bandwidth);
5286 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 default:
5288 break;
5289 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005290 /*
5291 * Action frame registered in one adapter which will
5292 * applicable to all interfaces
5293 */
5294 wlan_hdd_cfg80211_register_frames(adapter);
5295
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305296get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005297 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5298 adapterNode = pNext;
5299 }
5300
5301 EXIT();
5302
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305303 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005304}
5305
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005306QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005307 hdd_adapter_list_node_t **padapterNode)
5308{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305309 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005310
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005311 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305312 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5313 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005314 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005315 return status;
5316}
5317
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005318QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319 hdd_adapter_list_node_t *adapterNode,
5320 hdd_adapter_list_node_t **pNextAdapterNode)
5321{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305322 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005323
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005324 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305325 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5326 (qdf_list_node_t *) adapterNode,
5327 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005328
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005329 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005330 return status;
5331}
5332
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005333QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005334 hdd_adapter_list_node_t *adapterNode)
5335{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305336 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005337
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005338 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305339 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005340 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005341 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005342 return status;
5343}
5344
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005345QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005346 hdd_adapter_list_node_t **padapterNode)
5347{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305348 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005349
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005350 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305351 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5352 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005353 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005354 return status;
5355}
5356
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005357QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005358 hdd_adapter_list_node_t *adapterNode)
5359{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305360 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005361
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005362 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305363 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5364 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005365 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005366 return status;
5367}
5368
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005369QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005370 hdd_adapter_list_node_t *adapterNode)
5371{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305372 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005373
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005374 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305375 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5376 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005377 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005378 return status;
5379}
5380
Jeff Johnson9d295242017-08-29 14:39:48 -07005381struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005382 tSirMacAddr macAddr)
5383{
5384 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005385 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305386 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005387
5388 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5389
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305390 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005391 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392
5393 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305394 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005395 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005396 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005397
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005398 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5399 adapterNode = pNext;
5400 }
5401
5402 return NULL;
5403
5404}
5405
Jeff Johnson9d295242017-08-29 14:39:48 -07005406struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005407 uint32_t vdev_id)
5408{
5409 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005410 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305411 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305413 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005414
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305415 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005416 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005417
5418 if (adapter->sessionId == vdev_id)
5419 return adapter;
5420
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305421 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005422 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5423 adapterNode = pNext;
5424 }
5425
Jeff Johnson5880d792016-08-15 13:32:30 -07005426 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005427
5428 return NULL;
5429}
5430
Abhishek Singh7996eb72015-12-30 17:24:02 +05305431/**
5432 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5433 * the sessionid
5434 * @hdd_ctx: hdd context.
5435 * @sme_session_id: sme session is for the adapter to get.
5436 *
5437 * This function is used to get the adapter with provided session id
5438 *
5439 * Return: adapter pointer if found
5440 *
5441 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005442struct hdd_adapter *
5443hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5444 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305445{
5446 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005447 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305448 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305449
5450
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305451 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305452
5453 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305454 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005455 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305456
5457 if (adapter &&
5458 adapter->sessionId == sme_session_id)
5459 return adapter;
5460
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305461 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305462 hdd_get_next_adapter(hdd_ctx,
5463 adapter_node, &next);
5464 adapter_node = next;
5465 }
5466 return NULL;
5467}
5468
Jeff Johnson9d295242017-08-29 14:39:48 -07005469struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005470 const char *iface_name)
5471{
5472 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005473 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005474 QDF_STATUS qdf_status;
5475
5476 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5477
5478 while ((NULL != adapter_node) &&
5479 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005480 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005481
5482 if (adapter &&
5483 !qdf_str_cmp(adapter->dev->name, iface_name))
5484 return adapter;
5485
5486 qdf_status =
5487 hdd_get_next_adapter(hdd_ctx,
5488 adapter_node, &next);
5489 adapter_node = next;
5490 }
5491 return NULL;
5492}
5493
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005494/**
5495 * hdd_get_adapter() - to get adapter matching the mode
5496 * @hdd_ctx: hdd context
5497 * @mode: adapter mode
5498 *
5499 * This routine will return the pointer to adapter matching
5500 * with the passed mode.
5501 *
5502 * Return: pointer to adapter or null
5503 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005504struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005505 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005506{
5507 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005508 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305509 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005510
5511 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5512
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305513 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005514 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005515
5516 if (adapter && (mode == adapter->device_mode))
5517 return adapter;
5518
5519 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5520 adapterNode = pNext;
5521 }
5522
5523 return NULL;
5524
5525}
5526
5527/**
5528 * hdd_get_operating_channel() - return operating channel of the device mode
5529 * @hdd_ctx: Pointer to the HDD context.
5530 * @mode: Device mode for which operating channel is required.
5531 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005532 * QDF_STA_MODE,
5533 * QDF_P2P_CLIENT_MODE,
5534 * QDF_SAP_MODE,
5535 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005536 *
5537 * This API returns the operating channel of the requested device mode
5538 *
5539 * Return: channel number. "0" id the requested device is not found OR it is
5540 * not connected.
5541 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005542uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005543 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005544{
5545 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305546 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005547 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005548 uint8_t operatingChannel = 0;
5549
5550 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5551
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305552 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005553 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005554
5555 if (mode == adapter->device_mode) {
5556 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005557 case QDF_STA_MODE:
5558 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005559 if (hdd_conn_is_connected
5560 (WLAN_HDD_GET_STATION_CTX_PTR
5561 (adapter))) {
5562 operatingChannel =
5563 (WLAN_HDD_GET_STATION_CTX_PTR
5564 (adapter))->conn_info.
5565 operationChannel;
5566 }
5567 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005568 case QDF_SAP_MODE:
5569 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005570 /* softap connection info */
5571 if (test_bit
5572 (SOFTAP_BSS_STARTED,
5573 &adapter->event_flags))
5574 operatingChannel =
5575 (WLAN_HDD_GET_AP_CTX_PTR
5576 (adapter))->operatingChannel;
5577 break;
5578 default:
5579 break;
5580 }
5581
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005582 /* Found the device of interest. break the loop */
5583 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005584 }
5585
5586 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5587 adapterNode = pNext;
5588 }
5589 return operatingChannel;
5590}
5591
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005592static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005593 hdd_ctx)
5594{
5595 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305596 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005597 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598
5599 ENTER();
5600
5601 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5602
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305603 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005604 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005605 if ((adapter->device_mode == QDF_STA_MODE) ||
5606 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5607 (adapter->device_mode == QDF_IBSS_MODE) ||
5608 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5609 (adapter->device_mode == QDF_SAP_MODE) ||
5610 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005611 wlan_hdd_cfg80211_deregister_frames(adapter);
5612 hdd_unregister_wext(adapter->dev);
5613 }
5614 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5615 adapterNode = pNext;
5616 }
5617
5618 EXIT();
5619
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305620 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005621}
5622
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005623QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005624{
5625 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305626 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005627 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005628
5629 ENTER();
5630
5631 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5632
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305633 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005634 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005635 if ((adapter->device_mode == QDF_STA_MODE) ||
5636 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5637 (adapter->device_mode == QDF_IBSS_MODE) ||
5638 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5639 (adapter->device_mode == QDF_SAP_MODE) ||
5640 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005641 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5642 adapter->sessionId, INVALID_SCAN_ID,
5643 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005644 }
5645 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5646 adapterNode = pNext;
5647 }
5648
5649 EXIT();
5650
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305651 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005652}
5653
Dustin Brownf27bce82016-11-03 12:52:27 -07005654/**
5655 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5656 * adapters
5657 * @hdd_ctx: The HDD context containing the adapters to operate on
5658 *
5659 * return: QDF_STATUS_SUCCESS
5660 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005661static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005662{
5663 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5664 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005665 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005666 int err;
5667
5668 ENTER();
5669
5670 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5671
5672 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005673 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005674 if ((adapter->device_mode == QDF_STA_MODE) ||
5675 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5676 (adapter->device_mode == QDF_IBSS_MODE) ||
5677 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5678 (adapter->device_mode == QDF_SAP_MODE) ||
5679 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5680 err = wlan_hdd_sched_scan_stop(adapter->dev);
5681 if (err)
5682 hdd_err("Unable to stop scheduled scan");
5683 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005684 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5685 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005686 adapter_node = next_node;
5687 }
5688
5689 EXIT();
5690
5691 return QDF_STATUS_SUCCESS;
5692}
5693
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005694#ifdef WLAN_NS_OFFLOAD
5695/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005696 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697 * @hdd_ctx: Pointer to hdd context
5698 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005699 * Unregister for IPv6 address change notifications.
5700 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005701 * Return: None
5702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005703static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005704{
5705 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005706}
5707
5708/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005709 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005710 * @hdd_ctx: Pointer to hdd context
5711 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005712 * Register for IPv6 address change notifications.
5713 *
5714 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005716static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005717{
5718 int ret;
5719
5720 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5721 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005722 if (ret) {
5723 hdd_err("Failed to register IPv6 notifier: %d", ret);
5724 goto out;
5725 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005726
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005727 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005728out:
5729 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005730}
5731#else
5732/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005733 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005734 * @hdd_ctx: Pointer to hdd context
5735 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005736 * Unregister for IPv6 address change notifications.
5737 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005738 * Return: None
5739 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005740static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005741{
5742}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005743
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005744/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005745 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005746 * @hdd_ctx: Pointer to hdd context
5747 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005748 * Register for IPv6 address change notifications.
5749 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005750 * Return: None
5751 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005752static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005753{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005754 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005755}
5756#endif
5757
5758/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005759 * hdd_register_notifiers - Register netdev notifiers.
5760 * @hdd_ctx: HDD context
5761 *
5762 * Register netdev notifiers like IPv4 and IPv6.
5763 *
5764 * Return: 0 on success and errno on failure
5765 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005766static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005767{
5768 int ret;
5769
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005770 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5771 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305772 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005773
5774 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5775 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5776 if (ret) {
5777 hdd_err("Failed to register IPv4 notifier: %d", ret);
5778 goto unregister_ip6_notifier;
5779 }
5780
5781 return 0;
5782
5783unregister_ip6_notifier:
5784 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005785out:
5786 return ret;
5787
5788}
5789
5790/**
5791 * hdd_unregister_notifiers - Unregister netdev notifiers.
5792 * @hdd_ctx: HDD context
5793 *
5794 * Unregister netdev notifiers like IPv4 and IPv6.
5795 *
5796 * Return: None.
5797 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005798void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005799{
5800 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5801
5802 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005803}
5804
5805/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005806 * hdd_exit_netlink_services - Exit netlink services
5807 * @hdd_ctx: HDD context
5808 *
5809 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5810 * nl service.
5811 *
5812 * Return: None.
5813 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005814static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005815{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005816 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005817 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005818 ptt_sock_deactivate_svc();
5819
5820 nl_srv_exit();
5821}
5822
5823/**
5824 * hdd_init_netlink_services- Init netlink services
5825 * @hdd_ctx: HDD context
5826 *
5827 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5828 * nl service.
5829 *
5830 * Return: 0 on success and errno on failure.
5831 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005832static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005833{
5834 int ret;
5835
Ryan Hsuceddceb2016-04-28 10:20:14 -07005836 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005837 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005838 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005839 goto out;
5840 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005841 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005842
Naveen Rawat910726a2017-03-06 11:42:51 -08005843 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005844 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005845 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005846 goto err_nl_srv;
5847 }
5848
5849 ret = ptt_sock_activate_svc();
5850 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005851 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005852 goto err_nl_srv;
5853 }
5854
5855 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005856 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005857 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005858
5859 ret = cnss_diag_activate_service();
5860 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005861 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005862 goto err_close_cesium;
5863 }
5864
5865 return 0;
5866
5867err_close_cesium:
5868 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005869 ptt_sock_deactivate_svc();
5870err_nl_srv:
5871 nl_srv_exit();
5872out:
5873 return ret;
5874}
5875
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005876/**
5877 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5878 * @hdd_ctx: HDD context.
5879 *
5880 * Destroy RX wakelock.
5881 *
5882 * Return: None.
5883 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005884static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005885{
5886 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5887}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005888
5889/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005890 * hdd_rx_wake_lock_create() - Create RX wakelock
5891 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005892 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005893 * Create RX wakelock.
5894 *
5895 * Return: None.
5896 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005897static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005898{
5899 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5900}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005901
5902/**
Houston Hoffman160db392016-10-10 17:37:51 -07005903 * hdd_context_deinit() - Deinitialize HDD context
5904 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005905 *
Houston Hoffman160db392016-10-10 17:37:51 -07005906 * Deinitialize HDD context along with all the feature specific contexts but
5907 * do not free hdd context itself. Caller of this API is supposed to free
5908 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005909 *
Houston Hoffman160db392016-10-10 17:37:51 -07005910 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005911 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005912static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005913{
Houston Hoffman160db392016-10-10 17:37:51 -07005914 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005915
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005916 hdd_sap_context_destroy(hdd_ctx);
5917
5918 hdd_rx_wake_lock_destroy(hdd_ctx);
5919
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005920 hdd_scan_context_destroy(hdd_ctx);
5921
5922 qdf_list_destroy(&hdd_ctx->hddAdapters);
5923
Houston Hoffman160db392016-10-10 17:37:51 -07005924 return 0;
5925}
5926
5927/**
5928 * hdd_context_destroy() - Destroy HDD context
5929 * @hdd_ctx: HDD context to be destroyed.
5930 *
5931 * Free config and HDD context as well as destroy all the resources.
5932 *
5933 * Return: None
5934 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005935static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005936{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005937 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305938
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305939 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5940
Houston Hoffman160db392016-10-10 17:37:51 -07005941 hdd_context_deinit(hdd_ctx);
5942
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305943 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005944 hdd_ctx->config = NULL;
5945
5946 wiphy_free(hdd_ctx->wiphy);
5947}
5948
5949/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305950 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5951 *
5952 * This function is used to destroy bug report lock
5953 *
5954 * Return: None
5955 */
5956static void wlan_destroy_bug_report_lock(void)
5957{
5958 p_cds_contextType p_cds_context;
5959
5960 p_cds_context = cds_get_global_context();
5961 if (!p_cds_context) {
5962 hdd_err("cds context is NULL");
5963 return;
5964 }
5965
5966 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5967}
5968
5969/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005970 * hdd_wlan_exit() - HDD WLAN exit function
5971 * @hdd_ctx: Pointer to the HDD Context
5972 *
5973 * This is the driver exit point (invoked during rmmod)
5974 *
5975 * Return: None
5976 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005977static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005978{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305979 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305981 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005982
5983 ENTER();
5984
Arun Khandavallifae92942016-08-01 13:31:08 +05305985 if (QDF_TIMER_STATE_RUNNING ==
5986 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005987 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305988 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005989 }
5990
Arun Khandavallifae92942016-08-01 13:31:08 +05305991 if (!QDF_IS_STATUS_SUCCESS
5992 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5993 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005994
Arun Khandavallifae92942016-08-01 13:31:08 +05305995
5996 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005997
Prashanth Bhattaab004382016-10-11 16:08:11 -07005998 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005999
6000#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306001 if (QDF_TIMER_STATE_RUNNING ==
6002 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6003 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006004 }
6005
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306006 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306007 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006008 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006009 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006010 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6011 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6012 hdd_ctx->last_acs_channel_list = NULL;
6013 hdd_ctx->num_of_channels = 0;
6014 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006016
Arun Khandavallifae92942016-08-01 13:31:08 +05306017 mutex_lock(&hdd_ctx->iface_change_lock);
6018 driver_status = hdd_ctx->driver_status;
6019 mutex_unlock(&hdd_ctx->iface_change_lock);
6020
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006021 /*
6022 * Powersave Offload Case
6023 * Disable Idle Power Save Mode
6024 */
6025 hdd_set_idle_ps_config(hdd_ctx, false);
6026
Arun Khandavallifae92942016-08-01 13:31:08 +05306027 if (driver_status != DRIVER_MODULES_CLOSED) {
6028 hdd_unregister_wext_all_adapters(hdd_ctx);
6029 /*
6030 * Cancel any outstanding scan requests. We are about to close
6031 * all of our adapters, but an adapter structure is what SME
6032 * passes back to our callback function. Hence if there
6033 * are any outstanding scan requests then there is a
6034 * race condition between when the adapter is closed and
6035 * when the callback is invoked. We try to resolve that
6036 * race condition here by canceling any outstanding scans
6037 * before we close the adapters.
6038 * Note that the scans may be cancelled in an asynchronous
6039 * manner, so ideally there needs to be some kind of
6040 * synchronization. Rather than introduce a new
6041 * synchronization here, we will utilize the fact that we are
6042 * about to Request Full Power, and since that is synchronized,
6043 * the expectation is that by the time Request Full Power has
6044 * completed, all scans will be cancelled
6045 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07006046 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05306047 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006048 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006049 hdd_stop_all_adapters(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006050 }
6051
6052 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306053 * Close the scheduler before calling cds_close to make sure
6054 * no thread is scheduled after the each module close is
6055 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006056 */
Jeff Johnson7d562272017-09-13 15:12:54 -07006057 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306058 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05306059 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306060 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006061 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006062
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306063 unregister_netdevice_notifier(&hdd_netdev_notifier);
6064
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006065 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306066
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306067 qdf_nbuf_deinit_replenish_timer();
6068
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306069 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6070 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6071 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6072
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006073 /*
6074 * Close CDS
6075 * This frees pMac(HAL) context. There should not be any call
6076 * that requires pMac access after this.
6077 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006078
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006079 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006080 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006081
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006082 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006083
6084 hdd_ipa_cleanup(hdd_ctx);
6085
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306086 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306087 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306088 /*
6089 * If there is re_init failure wiphy would have already de-registered
6090 * check the wiphy status before un-registering again
6091 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306092 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306093 wiphy_unregister(wiphy);
6094 wlan_hdd_cfg80211_deinit(wiphy);
6095 hdd_lpass_notify_stop(hdd_ctx);
6096 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006097
Arun Khandavallifae92942016-08-01 13:31:08 +05306098 hdd_exit_netlink_services(hdd_ctx);
6099 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306100#ifdef FEATURE_WLAN_CH_AVOID
6101 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6102#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306103
6104 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6105 if (driver_status)
6106 hdd_err("Pdev delete failed");
6107
6108 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6109 if (driver_status)
6110 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006111
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006112 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006113}
6114
6115void __hdd_wlan_exit(void)
6116{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006117 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006118
6119 ENTER();
6120
Anurag Chouhan6d760662016-02-20 16:05:43 +05306121 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006122 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006123 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006124 EXIT();
6125 return;
6126 }
6127
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006128 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306129 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006130
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006131 /* Do all the cleanup before deregistering the driver */
6132 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006134 EXIT();
6135}
6136
6137#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006138/**
6139 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006140 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006141 *
6142 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6143 * Then new ACS request will do a fresh scan without reusing the cached
6144 * scan information.
6145 *
6146 * Return: void
6147 */
Tang Yingying523322d2017-01-17 23:28:43 +08006148static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006149{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006150 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006151
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006152 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006153 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006154 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6155 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6156 hdd_ctx->last_acs_channel_list = NULL;
6157 hdd_ctx->num_of_channels = 0;
6158 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006159
6160 if (!hdd_ctx->hHal)
6161 return;
6162 sme_scan_flush_result(hdd_ctx->hHal);
6163}
6164#endif
6165
6166#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006167int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6168 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006169{
6170 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306171 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006172 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173
6174 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6175
6176 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306177 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006178 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306179
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006180 if (!hdd_ctx->hHal)
6181 return -EINVAL;
6182
Jeff Johnsone7672e72017-10-21 15:10:04 -07006183 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006184 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306185 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006186 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006187 return -EINVAL;
6188 }
6189
6190 return 0;
6191}
6192#endif
6193
6194/**
6195 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6196 * @state: state
6197 *
6198 * This function notifies FW with modem power status
6199 *
6200 * Return: 0 if successful, error number otherwise
6201 */
6202int hdd_wlan_notify_modem_power_state(int state)
6203{
6204 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306205 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006206 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006207
Anurag Chouhan6d760662016-02-20 16:05:43 +05306208 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306210 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306212
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006213 if (!hdd_ctx->hHal)
6214 return -EINVAL;
6215
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306216 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6217 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006218 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006219 state);
6220 return -EINVAL;
6221 }
6222 return 0;
6223}
6224
6225/**
6226 *
6227 * hdd_post_cds_enable_config() - HDD post cds start config helper
6228 * @adapter - Pointer to the HDD
6229 *
6230 * Return: None
6231 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006232QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006233{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306234 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006235
6236 /*
6237 * Send ready indication to the HDD. This will kick off the MAC
6238 * into a 'running' state and should kick off an initial scan.
6239 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306240 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6241 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006242 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6243 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306244 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006245 }
6246
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306247 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006248}
6249
6250/* wake lock APIs for HDD */
6251void hdd_prevent_suspend(uint32_t reason)
6252{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306253 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254}
6255
6256void hdd_allow_suspend(uint32_t reason)
6257{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306258 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006259}
6260
6261void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6262{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306263 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6264 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006265}
6266
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006267/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006268QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006269{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006270
Amar Singhal6f8592b2017-04-26 14:31:58 -07006271 return sme_init_chan_list(hdd_ctx->hHal,
6272 hdd_ctx->reg.alpha2,
6273 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006274}
6275
6276/**
6277 * hdd_is_5g_supported() - check if hardware supports 5GHz
6278 * @hdd_ctx: Pointer to the hdd context
6279 *
6280 * HDD function to know if hardware supports 5GHz
6281 *
6282 * Return: true if hardware supports 5GHz
6283 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006284bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006285{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006286 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006287 return true;
6288
Amar Singhal58b45ef2017-08-01 13:43:54 -07006289 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006290 return true;
6291 else
6292 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006293}
6294
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006295static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006296{
6297 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006298 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006299
6300 wiphy = hdd_ctx->wiphy;
6301
6302 /*
6303 * The channel information in
6304 * wiphy needs to be initialized before wiphy registration
6305 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006306 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6307 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006308 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006309 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006310 }
6311
6312#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6313 wiphy->wowlan = &wowlan_support_reg_init;
6314#else
6315 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6316 WIPHY_WOWLAN_MAGIC_PKT |
6317 WIPHY_WOWLAN_DISCONNECT |
6318 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6319 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6320 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6321 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6322 WIPHY_WOWLAN_RFKILL_RELEASE;
6323
6324 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6325 WOW_MAX_FILTERS_PER_LIST);
6326 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6327 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6328#endif
6329
6330 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006331 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306332 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006333 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306334 return ret_val;
6335 }
6336
Amar Singhal5cccafe2017-02-15 12:42:58 -08006337 if (!hdd_ctx->reg_offload)
6338 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006339
Amar Singhale4f28ee2015-10-21 14:36:56 -07006340 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006341}
6342
Ravi Joshie2331e82015-07-01 18:18:54 -07006343/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006344 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006345 * @hdd_ctx - handle to hdd context
6346 * @tx_packets - transmit packet count
6347 * @rx_packets - receive packet count
6348 *
6349 * The function controls the bus bandwidth and dynamic control of
6350 * tcp delayed ack configuration
6351 *
6352 * Returns: None
6353 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006354#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006355static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006356 const uint64_t tx_packets,
6357 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006358{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006359 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006360 uint64_t temp_rx = 0;
6361 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006362 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006363 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006364 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006365 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006366 uint16_t index = 0;
6367 bool vote_level_change = false;
6368 bool rx_level_change = false;
6369 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006370
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006371 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006372 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006373 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006374 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006375 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006376 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006377 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006378 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006379
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006380 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006381 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6382 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006383 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006384 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006385 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306386 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306387 if (hdd_ctx->hbw_requested) {
6388 pld_remove_pm_qos(hdd_ctx->parent_dev);
6389 hdd_ctx->hbw_requested = false;
6390 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306391 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006392 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006393 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306394 if (!hdd_ctx->hbw_requested) {
6395 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6396 hdd_ctx->hbw_requested = true;
6397 }
6398
Nirav Shah3bbfa512016-05-12 16:43:49 +05306399 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006400 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006401 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006402 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006403 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006404
Mohit Khannaf8f96822017-05-17 17:11:59 -07006405 qdf_dp_trace_throttle_live_mode(
6406 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6407
Mohit Khannae71e2262015-11-10 09:37:24 -08006408 /* fine-tuning parameters for RX Flows */
6409 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006411 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006412
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306413 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6414 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6415 else
6416 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6417
Ravi Joshifed83572016-10-07 16:20:37 -07006418 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6419 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6420 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6421 next_rx_level = WLAN_SVC_TP_HIGH;
6422 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006423 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006424 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006425 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006426 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006427
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006428 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006429 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006430 next_rx_level, temp_rx);
6431 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006432 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006433 /* Send throughput indication only if it is enabled.
6434 * Disabling tcp_del_ack will revert the tcp stack behavior
6435 * to default delayed ack. Note that this will disable the
6436 * dynamic delayed ack mechanism across the system
6437 */
6438 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306439 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6440 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006441 &next_rx_level,
6442 sizeof(next_rx_level));
6443 }
6444
Mohit Khannae71e2262015-11-10 09:37:24 -08006445 /* fine-tuning parameters for TX Flows */
6446 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6447 hdd_ctx->prev_tx = tx_packets;
6448 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6449 next_tx_level = WLAN_SVC_TP_HIGH;
6450 else
6451 next_tx_level = WLAN_SVC_TP_LOW;
6452
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006453 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006454 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6455 next_tx_level, temp_tx);
6456 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006457 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306458 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6459 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006460 &next_tx_level,
6461 sizeof(next_tx_level));
6462 }
6463
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006464 index = hdd_ctx->hdd_txrx_hist_idx;
6465
6466 if (vote_level_change || tx_level_change || rx_level_change) {
6467 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6468 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6469 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6470 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6471 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6472 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6473 hdd_ctx->hdd_txrx_hist_idx++;
6474 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6475 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006476}
6477
6478#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306479static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006480{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006481 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306482 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006483 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306484 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306485 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6486 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006487 uint64_t total_tx = 0, total_rx = 0;
6488 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306489 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306490 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006491 bool connected = false;
6492 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6493
Prashanth Bhattaab004382016-10-11 16:08:11 -07006494 if (wlan_hdd_validate_context(hdd_ctx))
6495 return;
6496
Jingxiang Gec64e1932017-08-22 14:38:59 +08006497 if (hdd_ctx->isWiphySuspended)
6498 goto restart_timer;
6499
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006500 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306501 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006502 status =
6503 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6504
Jeff Johnson57eb2732017-10-02 11:40:20 -07006505 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006507 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306508 /*
6509 * Validate magic so we don't end up accessing
6510 * an invalid adapter.
6511 */
6512 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6513 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006514
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006515 if ((adapter->device_mode == QDF_STA_MODE ||
6516 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006517 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6518 != eConnectionState_Associated) {
6519
6520 continue;
6521 }
6522
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006523 if ((adapter->device_mode == QDF_SAP_MODE ||
6524 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006525 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6526
6527 continue;
6528 }
6529
6530 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6531 adapter->prev_tx_packets);
6532 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6533 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306534
6535 if (adapter->device_mode == QDF_SAP_MODE ||
6536 adapter->device_mode == QDF_P2P_GO_MODE ||
6537 adapter->device_mode == QDF_IBSS_MODE) {
6538
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006539 ret = cdp_get_intra_bss_fwd_pkts_count(
6540 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306541 adapter->sessionId,
6542 &fwd_tx_packets, &fwd_rx_packets);
6543 if (ret == A_OK) {
6544 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6545 fwd_tx_packets,
6546 adapter->prev_fwd_tx_packets);
6547 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6548 fwd_tx_packets,
6549 adapter->prev_fwd_rx_packets);
6550 }
6551 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006552
6553 total_rx += adapter->stats.rx_packets;
6554 total_tx += adapter->stats.tx_packets;
6555
6556 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6557 adapter->prev_tx_packets = adapter->stats.tx_packets;
6558 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306559 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6560 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006561 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6562 connected = true;
6563 }
6564
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306565 /* add intra bss forwarded tx and rx packets */
6566 tx_packets += fwd_tx_packets_diff;
6567 rx_packets += fwd_rx_packets_diff;
6568
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006569 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6570 tx_packets += (uint64_t)ipa_tx_packets;
6571 rx_packets += (uint64_t)ipa_rx_packets;
6572
Yun Park2aa880c2017-08-22 10:58:10 -07006573 if (adapter) {
6574 adapter->stats.tx_packets += ipa_tx_packets;
6575 adapter->stats.rx_packets += ipa_rx_packets;
6576 }
6577
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006578 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006579 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006580 return;
6581 }
6582
Yuanyuan Liu13738502016-04-06 17:41:37 -07006583 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006584
6585 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6586 hdd_ipa_uc_stat_request(adapter, 2);
6587
Jingxiang Gec64e1932017-08-22 14:38:59 +08006588restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006589 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006590 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006591 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306592 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006593 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006594 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006595}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006596
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306597/**
6598 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6599 * @arg: Argument of timer function
6600 *
6601 * Schedule a workqueue in this function where all the processing is done.
6602 *
6603 * Return: None.
6604 */
6605static void __hdd_bus_bw_cbk(void *arg)
6606{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006607 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306608
6609 if (wlan_hdd_validate_context(hdd_ctx))
6610 return;
6611
6612 schedule_work(&hdd_ctx->bus_bw_work);
6613}
6614
6615/**
6616 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6617 * @arg: Argument of timer function
6618 *
6619 * Return: None.
6620 */
6621static void hdd_bus_bw_cbk(void *arg)
6622{
6623 cds_ssr_protect(__func__);
6624 __hdd_bus_bw_cbk(arg);
6625 cds_ssr_unprotect(__func__);
6626}
6627
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006628int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006629{
6630 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306631 INIT_WORK(&hdd_ctx->bus_bw_work,
6632 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006633 hdd_ctx->bus_bw_timer_running = false;
6634 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306635 qdf_timer_init(NULL,
6636 &hdd_ctx->bus_bw_timer,
6637 hdd_bus_bw_cbk, (void *)hdd_ctx,
6638 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006639
6640 return 0;
6641}
6642
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006643void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006644{
Dustin Brownfce08d12017-01-17 16:29:38 -08006645 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006646 hdd_reset_tcp_delack(hdd_ctx);
6647
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006648 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306649 cancel_work_sync(&hdd_ctx->bus_bw_work);
6650 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006651 hdd_ctx->bus_bw_timer_running = false;
6652 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006653}
Lin Baic5c06882017-09-21 13:58:43 +08006654
6655void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6656{
6657 if (hdd_ctx)
6658 cancel_work_sync(&hdd_ctx->bus_bw_work);
6659}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006660#endif
6661
6662/**
Nirav Shahed34b212016-04-25 10:59:16 +05306663 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6664 * @hdd_ctx: hdd context
6665 *
6666 * Return: 0 for success or error code
6667 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006668static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306669{
6670 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6671 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6672 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006673 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306674 return -ENOMEM;
6675 }
6676 return 0;
6677}
6678
6679/**
6680 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6681 * @hdd_ctx: hdd context
6682 *
6683 * Return: none
6684 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006685void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306686{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306687 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6688 return;
6689
6690 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6691 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306692}
6693
Nirav Shahda008342016-05-17 18:50:40 +05306694static uint8_t *convert_level_to_string(uint32_t level)
6695{
6696 switch (level) {
6697 /* initialize the wlan sub system */
6698 case WLAN_SVC_TP_NONE:
6699 return "NONE";
6700 case WLAN_SVC_TP_LOW:
6701 return "LOW";
6702 case WLAN_SVC_TP_MEDIUM:
6703 return "MED";
6704 case WLAN_SVC_TP_HIGH:
6705 return "HIGH";
6706 default:
6707 return "INVAL";
6708 }
6709}
6710
Nirav Shahed34b212016-04-25 10:59:16 +05306711
6712/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006713 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6714 * @hdd_ctx: hdd context
6715 *
6716 * Return: none
6717 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006718void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006719{
6720 int i;
6721
6722#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006723 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306724 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006725 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006726 hdd_ctx->config->busBandwidthHighThreshold,
6727 hdd_ctx->config->busBandwidthMediumThreshold,
6728 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006729 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306730 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006731 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006732 hdd_ctx->config->tcpDelackThresholdHigh,
6733 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006734 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306735 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006736#endif
6737
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006738 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306739 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6740
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006741 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006742
6743 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006744 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006745 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006746 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006747 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6748 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006749 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006750 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6751 convert_level_to_string(
6752 hdd_ctx->hdd_txrx_hist[i].
6753 next_vote_level),
6754 convert_level_to_string(
6755 hdd_ctx->hdd_txrx_hist[i].
6756 next_rx_level),
6757 convert_level_to_string(
6758 hdd_ctx->hdd_txrx_hist[i].
6759 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006760 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006761}
6762
6763/**
6764 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6765 * @hdd_ctx: hdd context
6766 *
6767 * Return: none
6768 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006769void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006770{
6771 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306772 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6773 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006774}
6775
6776/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006777 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006778 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779 *
6780 * Return: none
6781 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006782void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006783{
6784
Jeff Johnson9d295242017-08-29 14:39:48 -07006785 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006786 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306787 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006788 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306789 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006790
6791 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306792 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006793 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006794
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006795 hdd_debug("Netif queue operation statistics:");
6796 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306797 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006798 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306799 curr_time = qdf_system_ticks();
6800 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306801 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306802 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306803 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306804 unpause = adapter->total_unpause_time;
6805 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306806 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306807 pause = adapter->total_pause_time;
6808 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006809 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306810 qdf_system_ticks_to_msecs(total),
6811 qdf_system_ticks_to_msecs(pause),
6812 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006813 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006814
Nirav Shahda008342016-05-17 18:50:40 +05306815 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6816 qdf_time_t pause_delta = 0;
6817
6818 if (adapter->pause_map & (1 << i))
6819 pause_delta = delta;
6820
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006821 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006822 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006823 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006824 hdd_reason_type_to_string(i),
6825 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306826 adapter->queue_oper_stats[i].unpause_count,
6827 qdf_system_ticks_to_msecs(
6828 adapter->queue_oper_stats[i].total_pause_time +
6829 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006830 }
6831
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006832 hdd_debug("Netif queue operation history:");
6833 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306834 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6835
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006836 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006837
6838 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006839 /* using hdd_log to avoid printing function name */
6840 if (adapter->queue_oper_history[i].time == 0)
6841 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006842 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006843 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306844 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006845 adapter->queue_oper_history[i].time),
6846 hdd_action_type_to_string(
6847 adapter->queue_oper_history[i].netif_action),
6848 hdd_reason_type_to_string(
6849 adapter->queue_oper_history[i].netif_reason),
6850 adapter->queue_oper_history[i].pause_map);
6851 }
6852
6853 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6854 adapter_node = next;
6855 }
6856
6857
6858}
6859
6860/**
6861 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6862 * @hdd_ctx: hdd context
6863 *
6864 * Return: none
6865 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006866void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006867{
Jeff Johnson9d295242017-08-29 14:39:48 -07006868 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006869 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306870 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006871
6872 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306873 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006874 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006875
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306876 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006877 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306878 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006879 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306880 adapter->history_index = 0;
6881 adapter->start_time = adapter->last_time = qdf_system_ticks();
6882 adapter->total_pause_time = 0;
6883 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006884 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6885 adapter_node = next;
6886 }
6887}
6888
6889/**
6890 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6891 * @halHandle: Hal handle
6892 * @pContext: Pointer to the context
6893 * @sessionId: Session ID
6894 * @scanId: Scan ID
6895 * @status: Status
6896 *
6897 * This is the callback to be executed when 11d scan is completed to flush out
6898 * the scan results
6899 *
6900 * 11d scan is done during driver load and is a passive scan on all
6901 * channels supported by the device, 11d scans may find some APs on
6902 * frequencies which are forbidden to be used in the regulatory domain
6903 * the device is operating in. If these APs are notified to the supplicant
6904 * it may try to connect to these APs, thus flush out all the scan results
6905 * which are present in SME after 11d scan is done.
6906 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306907 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006908 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306909static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006910 uint8_t sessionId, uint32_t scanId,
6911 eCsrScanStatus status)
6912{
6913 ENTER();
6914
6915 sme_scan_flush_result(halHandle);
6916
6917 EXIT();
6918
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306919 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006920}
6921
6922#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6923/**
6924 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6925 * @hdd_ctx: hdd global context
6926 *
6927 * Return: none
6928 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006929static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006930{
6931 uint8_t i;
6932
6933 mutex_init(&hdd_ctx->op_ctx.op_lock);
6934 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6935 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6936 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6937 }
6938}
6939#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006940static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006941{
6942}
6943#endif
6944
Yingying Tang95409972016-10-20 15:16:15 +08006945#ifdef WLAN_FEATURE_WOW_PULSE
6946/**
6947 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006948 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006949 * @enable: enable or disable this behaviour
6950 *
6951 * Return: int
6952 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006953static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006954{
6955 struct hdd_config *pcfg_ini = phddctx->config;
6956 struct wow_pulse_mode wow_pulse_set_info;
6957 QDF_STATUS status;
6958
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006959 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006960
6961 if (false == phddctx->config->wow_pulse_support)
6962 return 0;
6963
6964 /* prepare the request to send to SME */
6965 if (enable == true) {
6966 wow_pulse_set_info.wow_pulse_enable = true;
6967 wow_pulse_set_info.wow_pulse_pin =
6968 pcfg_ini->wow_pulse_pin;
6969 wow_pulse_set_info.wow_pulse_interval_low =
6970 pcfg_ini->wow_pulse_interval_low;
6971 wow_pulse_set_info.wow_pulse_interval_high =
6972 pcfg_ini->wow_pulse_interval_high;
6973 } else {
6974 wow_pulse_set_info.wow_pulse_enable = false;
6975 wow_pulse_set_info.wow_pulse_pin = 0;
6976 wow_pulse_set_info.wow_pulse_interval_low = 0;
6977 wow_pulse_set_info.wow_pulse_interval_high = 0;
6978 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006979 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006980 wow_pulse_set_info.wow_pulse_enable,
6981 wow_pulse_set_info.wow_pulse_pin,
6982 wow_pulse_set_info.wow_pulse_interval_low,
6983 wow_pulse_set_info.wow_pulse_interval_high);
6984
6985 status = sme_set_wow_pulse(&wow_pulse_set_info);
6986 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006987 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006988 return -EIO;
6989 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006990 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006991 return 0;
6992}
6993#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006994static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006995{
6996 return 0;
6997}
6998#endif
6999
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007000#ifdef WLAN_FEATURE_FASTPATH
7001/**
7002 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7003 * @hdd_cfg: hdd config
7004 * @context: lower layer context
7005 *
7006 * Return: none
7007 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307008void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007009 void *context)
7010{
7011 if (hdd_cfg->fastpath_enable)
7012 hif_enable_fastpath(context);
7013}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007014#endif
7015
Yuanyuan Liu13738502016-04-06 17:41:37 -07007016#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007017/**
7018 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007019 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007020 * @level: thermal level
7021 *
7022 * Change IPA data path to SW path when the thermal throttle level greater
7023 * than 0, and restore the original data path when throttle level is 0
7024 *
7025 * Return: none
7026 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007027static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007028{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007029 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007030
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007031 /* Change IPA to SW path when throttle level greater than 0 */
7032 if (level > THROTTLE_LEVEL_0)
7033 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7034 else
7035 /* restore original concurrency mode */
7036 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7037}
7038
7039/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307040 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7041 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307042 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007043 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307044 * Get a safe channel to restart SAP. PCL already takes into account the
7045 * unsafe channels. So, the PCL is validated with the ACS range to provide
7046 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007047 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307048 * Return: Channel number to restart SAP in case of success. In case of any
7049 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007050 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307051static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007052 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007053{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307054 struct sir_pcl_list pcl;
7055 QDF_STATUS status;
7056 uint32_t i, j;
7057 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007058 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307059 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007060
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307061 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7062 if (!hdd_ctx) {
7063 hdd_err("invalid HDD context");
7064 return INVALID_CHANNEL_ID;
7065 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007066
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307067 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7068 if (!hal_handle) {
7069 hdd_err("invalid HAL handle");
7070 return INVALID_CHANNEL_ID;
7071 }
7072
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007073 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7074 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007075 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7076 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307077 if (QDF_IS_STATUS_ERROR(status)) {
7078 hdd_err("Get PCL failed");
7079 return INVALID_CHANNEL_ID;
7080 }
7081
Frank Liudc2cefb2017-06-21 15:38:18 +08007082 /*
7083 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7084 * channel is unsafe channel, the pcl may be empty, instead of return,
7085 * try to choose a safe channel from acs range.
7086 */
7087 if (!pcl.pcl_len)
7088 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307089
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007090 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307091 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7092 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7093
7094 /* PCL already takes unsafe channel into account */
7095 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007096 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307097 if ((pcl.pcl_list[i] >=
7098 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7099 (pcl.pcl_list[i] <=
7100 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007101 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307102 return pcl.pcl_list[i];
7103 }
7104 }
7105
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007106 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307107
7108 /* Try for safe channel from all valid channel */
7109 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007110 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307111 &pcl.pcl_len);
7112 if (QDF_IS_STATUS_ERROR(status)) {
7113 hdd_err("error in getting valid channel list");
7114 return INVALID_CHANNEL_ID;
7115 }
7116
7117 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007118 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307119 found = false;
7120 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007121 if (pcl.pcl_list[i] ==
7122 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007123 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307124 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007125 break;
7126 }
7127 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307128
7129 if (found)
7130 continue;
7131
7132 if ((pcl.pcl_list[i] >=
7133 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7134 (pcl.pcl_list[i] <=
7135 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007136 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307137 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007138 }
7139 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307140
7141 return INVALID_CHANNEL_ID;
7142}
7143
7144/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007145 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307146 * @adapter: AP adapter
7147 * @channel: Channel
7148 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007149 * Moves the SAP interface by invoking the function which
7150 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307151 *
7152 * Return: None
7153 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007154void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307155{
Jeff Johnson87251032017-08-29 13:31:11 -07007156 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307157 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007158 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307159
7160 if (!adapter) {
7161 hdd_err("invalid adapter");
7162 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007163 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307164
7165 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7166
7167 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7168 if (!hal_handle) {
7169 hdd_err("invalid HAL handle");
7170 return;
7171 }
7172
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007173 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7174
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307175 hdd_ap_ctx->sapConfig.channel = channel;
7176 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7177 hdd_ap_ctx->sapConfig.ch_width_orig;
7178
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007179 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307180 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7181
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007182 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7183 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307184 hdd_ap_ctx->sapConfig.sec_ch,
7185 &hdd_ap_ctx->sapConfig.ch_params);
7186
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007187 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7188 adapter->sessionId, channel,
7189 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007190}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307191
Jeff Johnson9d295242017-08-29 14:39:48 -07007192int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307193{
7194 struct hdd_external_acs_timer_context *timer_context;
7195
7196 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7197
7198 if (QDF_TIMER_STATE_RUNNING ==
7199 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7200 ap.vendor_acs_timer)) {
7201 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7202 }
7203 timer_context = (struct hdd_external_acs_timer_context *)
7204 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7205 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307206 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307207 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307208 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7209 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307210 hdd_notice("Updated ACS config to nl with reason %d", reason);
7211
7212 return 0;
7213}
7214
Agrawal Ashish467dde42016-09-08 18:44:22 +05307215/**
7216 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7217 * @hdd_ctx: hdd context pointer
7218 *
7219 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7220 * and if ACS is enabled, driver will ask userspace to restart the
7221 * sap. User space on LTE coex indication restart driver.
7222 *
7223 * Return - none
7224 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007225void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307226{
7227 QDF_STATUS status;
7228 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007229 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307230 uint32_t i;
7231 bool found = false;
7232 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007233
Agrawal Ashish467dde42016-09-08 18:44:22 +05307234 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7235 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007236 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307237
7238 if (!adapter_temp) {
7239 hdd_err("adapter is NULL, moving to next one");
7240 goto next_adapater;
7241 }
7242
7243 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7244 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007245 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307246 adapter_temp->device_mode,
7247 adapter_temp->sessionCtx.ap.sapConfig.
7248 acs_cfg.acs_mode);
7249 goto next_adapater;
7250 }
7251
7252 found = false;
7253 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007254 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307255 hdd_ctxt->unsafe_channel_list[i]) {
7256 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007257 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307258 adapter_temp->sessionCtx.ap.operatingChannel);
7259 break;
7260 }
7261 }
7262
7263 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007264 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307265 adapter_temp->sessionCtx.ap.operatingChannel);
7266 goto next_adapater;
7267 }
7268
Kapil Gupta8878ad92017-02-13 11:56:04 +05307269 if (hdd_ctxt->config->vendor_acs_support &&
7270 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7271 hdd_update_acs_timer_reason(adapter_temp,
7272 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7273 goto next_adapater;
7274 } else
7275 restart_chan =
7276 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307277 adapter_temp);
7278 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007279 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307280 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007281 /*
7282 * SAP restart due to unsafe channel. While
7283 * restarting the SAP, make sure to clear
7284 * acs_channel, channel to reset to
7285 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307286 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007287 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307288 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7289 adapter_temp->sessionCtx.ap.sapConfig.channel =
7290 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007291 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307292 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7293 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007294 hdd_debug("driver to start sap: %d",
7295 hdd_ctxt->config->sap_internal_restart);
7296 if (hdd_ctxt->config->sap_internal_restart)
7297 hdd_switch_sap_channel(adapter_temp, restart_chan);
7298 else
7299 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307300 }
7301
7302next_adapater:
7303 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7304 adapter_node = next;
7305 }
7306}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307307
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007308/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007309 * hdd_init_channel_avoidance() - Initialize channel avoidance
7310 * @hdd_ctx: HDD global context
7311 *
7312 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007313 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007314 * down to the lower layers. Then subscribe to subsequent channel
7315 * avoidance events.
7316 *
7317 * Return: None
7318 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007319static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007320{
7321 uint16_t unsafe_channel_count;
7322 int index;
7323
Yuanyuan Liu13738502016-04-06 17:41:37 -07007324 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7325 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007326 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007327 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007328
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007329 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007330 hdd_ctx->unsafe_channel_count);
7331
Anurag Chouhan6d760662016-02-20 16:05:43 +05307332 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007333 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007334
7335 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007336 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007337 hdd_ctx->unsafe_channel_list[index]);
7338
7339 }
7340
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007341}
Dustin Brown676a2322017-08-15 13:16:13 -07007342
Jeff Johnson9d295242017-08-29 14:39:48 -07007343static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007344 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007345{
7346 uint8_t restart_chan;
7347
7348 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7349 if (!restart_chan) {
7350 hdd_alert("fail to restart SAP");
7351 return;
7352 }
7353
7354 /* SAP restart due to unsafe channel. While restarting
7355 * the SAP, make sure to clear acs_channel, channel to
7356 * reset to 0. Otherwise these settings will override
7357 * the ACS while restart.
7358 */
7359 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7360 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7361
7362 hdd_debug("sending coex indication");
7363
7364 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7365 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7366 hdd_switch_sap_channel(adapter, restart_chan);
7367}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007368
7369int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7370 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7371{
7372 uint32_t size;
7373 uint16_t *unsafe_list;
7374 uint16_t chan_count;
7375
7376 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7377 return -EINVAL;
7378
7379 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7380 NUM_CHANNELS);
7381 if (chan_count) {
7382 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7383 unsafe_list = qdf_mem_malloc(size);
7384 if (!unsafe_list) {
7385 hdd_err("No memory for unsafe chan list size%d",
7386 size);
7387 return -ENOMEM;
7388 }
7389 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7390 } else {
7391 unsafe_list = NULL;
7392 }
7393
7394 *local_unsafe_list = unsafe_list;
7395 *local_unsafe_list_count = chan_count;
7396
7397 return 0;
7398}
7399
7400bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7401 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7402{
7403 int i, j;
7404
7405 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7406 return true;
7407 if (local_unsafe_list_count == 0)
7408 return false;
7409 for (i = 0; i < local_unsafe_list_count; i++) {
7410 for (j = 0; j < local_unsafe_list_count; j++)
7411 if (local_unsafe_list[i] ==
7412 hdd_ctx->unsafe_channel_list[j])
7413 break;
7414 if (j >= local_unsafe_list_count)
7415 break;
7416 }
7417 if (i >= local_unsafe_list_count) {
7418 hdd_info("unsafe chan list same");
7419 return false;
7420 }
7421
7422 return true;
7423}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007424#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007425static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007426{
7427}
Dustin Brown676a2322017-08-15 13:16:13 -07007428
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007429static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007430{
7431}
Dustin Brown676a2322017-08-15 13:16:13 -07007432
Jeff Johnson9d295242017-08-29 14:39:48 -07007433static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007434 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007435{
7436 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7437}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007438#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007439
7440/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007441 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7442 * user space
7443 * @frame_ind: Management frame data to be informed.
7444 *
7445 * This function is used to indicate management frame to
7446 * user space
7447 *
7448 * Return: None
7449 *
7450 */
7451void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7452{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007453 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007454 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007455 int i;
7456
Rajeev Kumard004abc2016-02-17 12:09:56 -08007457 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007458 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007459
7460 if (0 != wlan_hdd_validate_context(hdd_ctx))
7461 return;
7462
7463 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7464 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7465 adapter =
7466 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7467 if (adapter)
7468 break;
7469 }
7470 } else {
7471 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7472 frame_ind->sessionId);
7473 }
7474
7475 if ((NULL != adapter) &&
7476 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7477 __hdd_indicate_mgmt_frame(adapter,
7478 frame_ind->frame_len,
7479 frame_ind->frameBuf,
7480 frame_ind->frameType,
7481 frame_ind->rxChan,
7482 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007483}
7484
Kapil Gupta8878ad92017-02-13 11:56:04 +05307485void hdd_acs_response_timeout_handler(void *context)
7486{
7487 struct hdd_external_acs_timer_context *timer_context =
7488 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007489 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007490 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307491 uint8_t reason;
7492
7493 ENTER();
7494 if (!timer_context) {
7495 hdd_err("invlaid timer context");
7496 return;
7497 }
7498 adapter = timer_context->adapter;
7499 reason = timer_context->reason;
7500
7501
7502 if ((!adapter) ||
7503 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7504 hdd_err("invalid adapter or adapter has invalid magic");
7505 return;
7506 }
7507 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7508 if (wlan_hdd_validate_context(hdd_ctx))
7509 return;
7510
7511 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7512 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7513 else
7514 return;
7515
7516 hdd_err("ACS timeout happened for %s reason %d",
7517 adapter->dev->name, reason);
7518 switch (reason) {
7519 /* SAP init case */
7520 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7521 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7522 false);
7523 wlan_hdd_cfg80211_start_acs(adapter);
7524 break;
7525 /* DFS detected on current channel */
7526 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7527 wlan_sap_update_next_channel(
7528 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7529 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7530 adapter->sessionId);
7531 break;
7532 /* LTE coex event on current channel */
7533 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7534 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7535 break;
7536 default:
7537 hdd_info("invalid reason for timer invoke");
7538
7539 }
7540}
7541
Rajeev Kumard004abc2016-02-17 12:09:56 -08007542/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007543 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7544 * @hdd_ctx: HDD context
7545 *
7546 * Disables all the dual mac features like DBS, Agile DFS etc.
7547 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307548 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007549 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007550static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007551{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007552 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307553 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007554
7555 if (!hdd_ctx) {
7556 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307557 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007558 }
7559
7560 cfg.scan_config = 0;
7561 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007562 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007563
7564 hdd_debug("Disabling all dual mac features...");
7565
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007566 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307567 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007568 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7569 return status;
7570 }
7571
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307572 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007573}
7574
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007575static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007576wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007577{
7578 struct policy_mgr_dual_mac_config cfg = {0};
7579 QDF_STATUS status;
7580
7581 if (!hdd_ctx) {
7582 hdd_err("HDD context is NULL");
7583 return QDF_STATUS_E_FAILURE;
7584 }
7585
7586 cfg.scan_config = 0;
7587 cfg.fw_mode_config = 0;
7588 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7589 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7590 hdd_ctx->hdd_psoc, &cfg.scan_config,
7591 &cfg.fw_mode_config,
7592 hdd_ctx->config->dual_mac_feature_disable);
7593
7594 if (status != QDF_STATUS_SUCCESS) {
7595 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7596 status);
7597 return status;
7598 }
7599
7600 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7601 cfg.scan_config, cfg.fw_mode_config);
7602
7603 status = sme_soc_set_dual_mac_config(cfg);
7604 if (status != QDF_STATUS_SUCCESS) {
7605 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7606 return status;
7607 }
7608
7609 return QDF_STATUS_SUCCESS;
7610}
7611
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007612/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007613 * hdd_override_ini_config - Override INI config
7614 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007615 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007616 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007617 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007618 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007619 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007620static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007621{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007622
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007623 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7624 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007625 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007626 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007628 if (0 == enable_11d || 1 == enable_11d) {
7629 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007630 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007631 }
Leo Chang11545d62016-10-17 14:53:50 -07007632
7633 if (!hdd_ipa_is_present(hdd_ctx))
7634 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007635}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007636
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007637/**
7638 * hdd_set_trace_level_for_each - Set trace level for each INI config
7639 * @hdd_ctx - HDD context
7640 *
7641 * Set trace level for each module based on INI config.
7642 *
7643 * Return: None
7644 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007645static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007646{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307647 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7648 hdd_ctx->config->qdf_trace_enable_wdi);
7649 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7650 hdd_ctx->config->qdf_trace_enable_hdd);
7651 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7652 hdd_ctx->config->qdf_trace_enable_sme);
7653 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7654 hdd_ctx->config->qdf_trace_enable_pe);
7655 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7656 hdd_ctx->config->qdf_trace_enable_wma);
7657 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7658 hdd_ctx->config->qdf_trace_enable_sys);
7659 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7660 hdd_ctx->config->qdf_trace_enable_qdf);
7661 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7662 hdd_ctx->config->qdf_trace_enable_sap);
7663 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7664 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7665 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7666 hdd_ctx->config->qdf_trace_enable_bmi);
7667 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7668 hdd_ctx->config->qdf_trace_enable_cfg);
7669 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7670 hdd_ctx->config->qdf_trace_enable_epping);
7671 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7672 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7673 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007674 hdd_ctx->config->qdf_trace_enable_txrx);
7675 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7676 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307677 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7678 hdd_ctx->config->qdf_trace_enable_htc);
7679 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7680 hdd_ctx->config->qdf_trace_enable_hif);
7681 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7682 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7683 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7684 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007685 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7686 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007687 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7688 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007689 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7690 hdd_ctx->config->qdf_trace_enable_regulatory);
7691
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007692 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007693}
7694
7695/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007696 * hdd_context_init() - Initialize HDD context
7697 * @hdd_ctx: HDD context.
7698 *
7699 * Initialize HDD context along with all the feature specific contexts.
7700 *
7701 * return: 0 on success and errno on failure.
7702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007703static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007704{
7705 int ret;
7706
7707 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7708 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7709
7710 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307711 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007712
7713 init_completion(&hdd_ctx->mc_sus_event_var);
7714 init_completion(&hdd_ctx->ready_to_suspend);
7715
7716 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307717 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007718 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307719
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007720 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7721
7722 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7723
7724 ret = hdd_scan_context_init(hdd_ctx);
7725 if (ret)
7726 goto list_destroy;
7727
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007728 hdd_rx_wake_lock_create(hdd_ctx);
7729
7730 ret = hdd_sap_context_init(hdd_ctx);
7731 if (ret)
7732 goto scan_destroy;
7733
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007734 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7735
7736 hdd_init_offloaded_packets_ctx(hdd_ctx);
7737
7738 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7739 hdd_ctx->config);
7740 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08007741 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007742
7743 return 0;
7744
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007745sap_destroy:
7746 hdd_sap_context_destroy(hdd_ctx);
7747
7748scan_destroy:
7749 hdd_scan_context_destroy(hdd_ctx);
7750 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007751list_destroy:
7752 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007753
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007754 return ret;
7755}
7756
7757/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307758 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7759 * @hdd_ctx: pointer to hdd context
7760 *
7761 * Return: status of initialization
7762 * 0 - success
7763 * negative value - failure
7764 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007765static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307766{
7767 int ret;
7768
7769 if (!hdd_ctx->config->probe_req_ie_whitelist)
7770 return 0;
7771
7772 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7773 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7774 hdd_ctx->config->probe_req_ie_whitelist = false;
7775 return -EINVAL;
7776 }
7777
7778 /* parse ini string probe req oui */
7779 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7780 if (ret) {
7781 hdd_err("parsing error: disable ie whitelisting");
7782 hdd_ctx->config->probe_req_ie_whitelist = false;
7783 }
7784
7785 return ret;
7786}
7787
7788/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007789 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307790 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007791 *
7792 * Allocate and initialize HDD context. HDD context is allocated as part of
7793 * wiphy allocation and then context is initialized.
7794 *
7795 * Return: HDD context on success and ERR_PTR on failure
7796 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007797static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007798{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307799 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007800 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007801 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007802
7803 ENTER();
7804
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007805 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007806 if (hdd_ctx == NULL) {
7807 ret = -ENOMEM;
7808 goto err_out;
7809 }
7810
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007811 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307812 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007813
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307814 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007815 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007816 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007817 ret = -ENOMEM;
7818 goto err_free_hdd_context;
7819 }
7820
7821 /* Read and parse the qcom_cfg.ini file */
7822 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307823 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307824 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007825 WLAN_INI_FILE);
7826 ret = -EINVAL;
7827 goto err_free_config;
7828 }
7829
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307830 ie_whitelist_attrs_init(hdd_ctx);
7831
Dustin Brown7f939932017-05-18 15:02:17 -07007832 hdd_debug("setting timer multiplier: %u",
7833 hdd_ctx->config->timer_multiplier);
7834 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7835
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007836
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307837 if (hdd_ctx->config->fhostNSOffload)
7838 hdd_ctx->ns_offload_enable = true;
7839
Abhishek Singh5ea86532016-04-27 14:10:53 +05307840 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7841
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007842 hdd_override_ini_config(hdd_ctx);
7843
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007844 ret = hdd_context_init(hdd_ctx);
7845
7846 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007847 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007848
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007849 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307850 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007851
Anurag Chouhan6d760662016-02-20 16:05:43 +05307852 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007853 goto skip_multicast_logging;
7854
7855 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7856
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007857 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7858 if (ret)
7859 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307860
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007861 ret = hdd_init_netlink_services(hdd_ctx);
7862 if (ret)
7863 goto err_deinit_txrx_histogram;
7864
Dustin Brown7b3dea22017-07-10 13:02:47 -07007865 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7866 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307867
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007868skip_multicast_logging:
7869 hdd_set_trace_level_for_each(hdd_ctx);
7870
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007871 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7872
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007873 EXIT();
7874
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007875 return hdd_ctx;
7876
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007877err_deinit_txrx_histogram:
7878 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7879
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007880err_deinit_hdd_context:
7881 hdd_context_deinit(hdd_ctx);
7882
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007883err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307884 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007885
7886err_free_hdd_context:
7887 wiphy_free(hdd_ctx->wiphy);
7888
7889err_out:
7890 return ERR_PTR(ret);
7891}
7892
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007893#ifdef WLAN_OPEN_P2P_INTERFACE
7894/**
7895 * hdd_open_p2p_interface - Open P2P interface
7896 * @hdd_ctx: HDD context
7897 * @rtnl_held: True if RTNL lock held
7898 *
7899 * Open P2P interface during probe. This function called to open the P2P
7900 * interface at probe along with STA interface.
7901 *
7902 * Return: 0 on success and errno on failure
7903 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007904static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007905{
Jeff Johnson9d295242017-08-29 14:39:48 -07007906 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007907 uint8_t *p2p_dev_addr;
7908
7909 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7910 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307911 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007912 hdd_ctx->config->intfMacAddr[0].bytes,
7913 sizeof(tSirMacAddr));
7914
7915 /*
7916 * Generate the P2P Device Address. This consists of
7917 * the device's primary MAC address with the locally
7918 * administered bit set.
7919 */
7920 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7921 } else {
7922 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7923 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007924 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007925 return -ENOSPC;
7926 }
7927
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307928 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307929 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007930 }
7931
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007932 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007933 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007934 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007935
7936 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007937 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007938 return -ENOSPC;
7939 }
7940
7941 return 0;
7942}
7943#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007944static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007945 bool rtnl_held)
7946{
7947 return 0;
7948}
7949#endif
7950
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007951static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007952{
Jeff Johnson9d295242017-08-29 14:39:48 -07007953 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007954 int ret = 0;
7955
7956 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7957 wlan_hdd_get_intf_addr(hdd_ctx),
7958 NET_NAME_UNKNOWN, rtnl_held);
7959 if (adapter == NULL) {
7960 hdd_err("Failed to open 802.11p interface");
7961 ret = -ENOSPC;
7962 }
7963
7964 return ret;
7965}
7966
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007967/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307968 * hdd_start_station_adapter()- Start the Station Adapter
7969 * @adapter: HDD adapter
7970 *
7971 * This function initializes the adapter for the station mode.
7972 *
7973 * Return: 0 on success or errno on failure.
7974 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007975int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307976{
7977 QDF_STATUS status;
7978
7979 ENTER_DEV(adapter->dev);
7980
7981 status = hdd_init_station_mode(adapter);
7982
7983 if (QDF_STATUS_SUCCESS != status) {
7984 hdd_err("Error Initializing station mode: %d", status);
7985 return qdf_status_to_os_return(status);
7986 }
7987
Arun Khandavallifae92942016-08-01 13:31:08 +05307988 hdd_register_tx_flow_control(adapter,
7989 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007990 hdd_tx_resume_cb,
7991 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307992
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307993 EXIT();
7994 return 0;
7995}
7996
7997/**
7998 * hdd_start_ap_adapter()- Start AP Adapter
7999 * @adapter: HDD adapter
8000 *
8001 * This function initializes the adapter for the AP mode.
8002 *
8003 * Return: 0 on success errno on failure.
8004 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008005int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308006{
8007 QDF_STATUS status;
8008
8009 ENTER();
8010
Arun Khandavallicc544b32017-01-30 19:52:16 +05308011 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308012
8013 if (QDF_STATUS_SUCCESS != status) {
8014 hdd_err("Error Initializing the AP mode: %d", status);
8015 return qdf_status_to_os_return(status);
8016 }
8017
Arun Khandavallifae92942016-08-01 13:31:08 +05308018 hdd_register_tx_flow_control(adapter,
8019 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008020 hdd_softap_tx_resume_cb,
8021 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308022
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308023 EXIT();
8024 return 0;
8025}
8026
8027/**
8028 * hdd_start_ftm_adapter()- Start FTM adapter
8029 * @adapter: HDD adapter
8030 *
8031 * This function initializes the adapter for the FTM mode.
8032 *
8033 * Return: 0 on success or errno on failure.
8034 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008035int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308036{
8037 QDF_STATUS qdf_status;
8038
8039 ENTER_DEV(adapter->dev);
8040
8041 qdf_status = hdd_init_tx_rx(adapter);
8042
8043 if (QDF_STATUS_SUCCESS != qdf_status) {
8044 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8045 return qdf_status_to_os_return(qdf_status);
8046 }
8047
8048 return 0;
8049 EXIT();
8050}
8051
8052/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008053 * hdd_open_interfaces - Open all required interfaces
8054 * hdd_ctx: HDD context
8055 * rtnl_held: True if RTNL lock is held
8056 *
8057 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8058 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008059 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008060 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008061static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008062{
Jeff Johnson9d295242017-08-29 14:39:48 -07008063 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008064 int ret;
8065
Ravi Joshia307f632017-07-17 23:41:41 -07008066 /* open monitor mode adapter if con_mode is monitor mode */
8067 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8068 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8069 wlan_hdd_get_intf_addr(hdd_ctx),
8070 NET_NAME_UNKNOWN, rtnl_held);
8071 if (!adapter) {
8072 hdd_err("open adapter failed");
8073 return -ENOSPC;
8074 }
8075 return 0;
8076 }
8077
Jeff Johnson957bc272017-02-02 08:54:48 -08008078 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308079 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008080 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008081
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008082 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008083 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008084 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008085
8086 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008087 return -ENOSPC;
8088
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008089 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8090 adapter->fast_roaming_allowed = true;
8091
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008092 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8093 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008094 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008095
8096 /* Open 802.11p Interface */
8097 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008098 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8099 if (ret)
8100 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008101 }
8102
Jeff Johnson957bc272017-02-02 08:54:48 -08008103 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008104
Jeff Johnson957bc272017-02-02 08:54:48 -08008105err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008106 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008107 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008108}
8109
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008110/**
8111 * hdd_update_country_code - Update country code
8112 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008113 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008114 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008115 *
8116 * Return: 0 on success and errno on failure
8117 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008118static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008119{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008120 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008121 return 0;
8122
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008123 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008124}
8125
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308126#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8127/**
8128 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8129 * @cds_cfg: CDS Configuration
8130 * @hdd_ctx: Pointer to hdd context
8131 *
8132 * Return: none
8133 */
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 cds_cfg->tx_flow_stop_queue_th =
8139 hdd_ctx->config->TxFlowStopQueueThreshold;
8140 cds_cfg->tx_flow_start_queue_offset =
8141 hdd_ctx->config->TxFlowStartQueueOffset;
8142}
8143#else
8144static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8145 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008146 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308147{
8148}
8149#endif
8150
8151#ifdef FEATURE_WLAN_RA_FILTERING
8152/**
8153 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8154 * @cds_cfg: CDS Configuration
8155 * @hdd_ctx: Pointer to hdd context
8156 *
8157 * Return: none
8158 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308159static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008160 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308161{
8162 cds_cfg->ra_ratelimit_interval =
8163 hdd_ctx->config->RArateLimitInterval;
8164 cds_cfg->is_ra_ratelimit_enabled =
8165 hdd_ctx->config->IsRArateLimitEnabled;
8166}
8167#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308168static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008169 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308170{
8171}
8172#endif
8173
8174/**
8175 * hdd_update_cds_config() - API to update cds configuration parameters
8176 * @hdd_ctx: HDD Context
8177 *
8178 * Return: 0 for Success, errno on failure
8179 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008180static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308181{
8182 struct cds_config_info *cds_cfg;
8183
8184 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8185 if (!cds_cfg) {
8186 hdd_err("failed to allocate cds config");
8187 return -ENOMEM;
8188 }
8189
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008190 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008191 if (!hdd_ctx->config->nMaxPsPoll ||
8192 !hdd_ctx->config->enablePowersaveOffload) {
8193 cds_cfg->powersave_offload_enabled =
8194 hdd_ctx->config->enablePowersaveOffload;
8195 } else {
8196 if ((hdd_ctx->config->enablePowersaveOffload ==
8197 PS_QPOWER_NODEEPSLEEP) ||
8198 (hdd_ctx->config->enablePowersaveOffload ==
8199 PS_LEGACY_NODEEPSLEEP))
8200 cds_cfg->powersave_offload_enabled =
8201 PS_LEGACY_NODEEPSLEEP;
8202 else
8203 cds_cfg->powersave_offload_enabled =
8204 PS_LEGACY_DEEPSLEEP;
8205 hdd_info("Qpower disabled in cds config, %d",
8206 cds_cfg->powersave_offload_enabled);
8207 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308208 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8209 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8210 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8211 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8212 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8213
8214 /* Here ol_ini_info is used to store ini status of arp offload
8215 * ns offload and others. Currently 1st bit is used for arp
8216 * off load and 2nd bit for ns offload currently, rest bits are unused
8217 */
8218 if (hdd_ctx->config->fhostArpOffload)
8219 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8220 if (hdd_ctx->config->fhostNSOffload)
8221 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8222
8223 /*
8224 * Copy the DFS Phyerr Filtering Offload status.
8225 * This parameter reflects the value of the
8226 * dfs_phyerr_filter_offload flag as set in the ini.
8227 */
8228 cds_cfg->dfs_phyerr_filter_offload =
8229 hdd_ctx->config->fDfsPhyerrFilterOffload;
8230 if (hdd_ctx->config->ssdp)
8231 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8232
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308233 cds_cfg->force_target_assert_enabled =
8234 hdd_ctx->config->crash_inject_enabled;
8235
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308236 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8237 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8238
8239 cds_cfg->ap_maxoffload_reorderbuffs =
8240 hdd_ctx->config->apMaxOffloadReorderBuffs;
8241
8242 cds_cfg->ap_disable_intrabss_fwd =
8243 hdd_ctx->config->apDisableIntraBssFwd;
8244
8245 cds_cfg->dfs_pri_multiplier =
8246 hdd_ctx->config->dfsRadarPriMultiplier;
8247 cds_cfg->reorder_offload =
8248 hdd_ctx->config->reorderOffloadSupport;
8249
8250 /* IPA micro controller data path offload resource config item */
8251 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008252 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8253 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008254 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008255 hdd_ctx->config->IpaUcTxBufCount);
8256 hdd_ctx->config->IpaUcTxBufCount =
8257 rounddown_pow_of_two(
8258 hdd_ctx->config->IpaUcTxBufCount);
8259 if (!hdd_ctx->config->IpaUcTxBufCount) {
8260 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308261 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008262 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008263 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008264 hdd_ctx->config->IpaUcTxBufCount);
8265 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308266 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8267 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008268 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8269 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008270 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008271 hdd_ctx->config->IpaUcRxIndRingCount);
8272 hdd_ctx->config->IpaUcRxIndRingCount =
8273 rounddown_pow_of_two(
8274 hdd_ctx->config->IpaUcRxIndRingCount);
8275 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8276 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308277 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008278 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008279 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008280 hdd_ctx->config->IpaUcRxIndRingCount);
8281 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308282 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008283 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308284 cds_cfg->uc_tx_partition_base =
8285 hdd_ctx->config->IpaUcTxPartitionBase;
8286 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8287
8288 cds_cfg->ip_tcp_udp_checksum_offload =
8289 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308290 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308291 cds_cfg->ce_classify_enabled =
8292 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008293 cds_cfg->bpf_packet_filter_enable =
8294 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308295 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8296 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8297 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008298 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008299 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008300 cds_cfg->max_msdus_per_rxinorderind =
8301 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008302 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008303 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308304 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8305 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308306 cds_cfg->auto_power_save_fail_mode =
8307 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308308
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308309 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008310 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308311
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308312 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8313 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8314 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008315 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308316 cds_init_ini_config(cds_cfg);
8317 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308318
8319exit:
8320 qdf_mem_free(cds_cfg);
8321 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308322}
8323
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008324/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008325 * hdd_update_user_config() - API to update user configuration
8326 * parameters to obj mgr which are used by multiple components
8327 * @hdd_ctx: HDD Context
8328 *
8329 * Return: 0 for Success, errno on failure
8330 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008331static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008332{
8333 struct wlan_objmgr_psoc_user_config *user_config;
8334
8335 user_config = qdf_mem_malloc(sizeof(*user_config));
8336 if (user_config == NULL) {
8337 hdd_alert("Failed to alloc memory for user_config!");
8338 return -ENOMEM;
8339 }
8340
8341 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8342 user_config->dual_mac_feature_disable =
8343 hdd_ctx->config->dual_mac_feature_disable;
8344 user_config->indoor_channel_support =
8345 hdd_ctx->config->indoor_channel_support;
8346 user_config->is_11d_support_enabled =
8347 hdd_ctx->config->Is11dSupportEnabled;
8348 user_config->is_11h_support_enabled =
8349 hdd_ctx->config->Is11hSupportEnabled;
8350 user_config->optimize_chan_avoid_event =
8351 hdd_ctx->config->goptimize_chan_avoid_event;
8352 user_config->skip_dfs_chnl_in_p2p_search =
8353 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008354 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008355 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8356
8357 qdf_mem_free(user_config);
8358 return 0;
8359}
8360
8361/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008362 * hdd_init_thermal_info - Initialize thermal level
8363 * @hdd_ctx: HDD context
8364 *
8365 * Initialize thermal level at SME layer and set the thermal level callback
8366 * which would be called when a configured thermal threshold is hit.
8367 *
8368 * Return: 0 on success and errno on failure
8369 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008370static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008371{
8372 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308373 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008374
8375 thermal_param.smeThermalMgmtEnabled =
8376 hdd_ctx->config->thermalMitigationEnable;
8377 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8378
Poddar, Siddarth83905022016-04-16 17:56:08 -07008379 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8380 hdd_ctx->config->throttle_dutycycle_level0;
8381 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8382 hdd_ctx->config->throttle_dutycycle_level1;
8383 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8384 hdd_ctx->config->throttle_dutycycle_level2;
8385 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8386 hdd_ctx->config->throttle_dutycycle_level3;
8387
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008388 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8389 hdd_ctx->config->thermalTempMinLevel0;
8390 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8391 hdd_ctx->config->thermalTempMaxLevel0;
8392 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8393 hdd_ctx->config->thermalTempMinLevel1;
8394 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8395 hdd_ctx->config->thermalTempMaxLevel1;
8396 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8397 hdd_ctx->config->thermalTempMinLevel2;
8398 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8399 hdd_ctx->config->thermalTempMaxLevel2;
8400 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8401 hdd_ctx->config->thermalTempMinLevel3;
8402 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8403 hdd_ctx->config->thermalTempMaxLevel3;
8404
8405 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8406
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308407 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308408 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008409
8410 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8411 hdd_set_thermal_level_cb);
8412
8413 return 0;
8414
8415}
8416
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008417#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8418/**
8419 * hdd_hold_rtnl_lock - Hold RTNL lock
8420 *
8421 * Hold RTNL lock
8422 *
8423 * Return: True if held and false otherwise
8424 */
8425static inline bool hdd_hold_rtnl_lock(void)
8426{
8427 rtnl_lock();
8428 return true;
8429}
8430
8431/**
8432 * hdd_release_rtnl_lock - Release RTNL lock
8433 *
8434 * Release RTNL lock
8435 *
8436 * Return: None
8437 */
8438static inline void hdd_release_rtnl_lock(void)
8439{
8440 rtnl_unlock();
8441}
8442#else
8443static inline bool hdd_hold_rtnl_lock(void) { return false; }
8444static inline void hdd_release_rtnl_lock(void) { }
8445#endif
8446
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008447#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008448
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308449/* MAX iwpriv command support */
8450#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308451#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308452#define MAX_PKTLOG_SIZE 16
8453
8454/**
8455 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8456 * @hdd_ctx: hdd context
8457 * @set_value2: pktlog buffer size value
8458 *
8459 *
8460 * Return: 0 for success or error.
8461 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008462static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308463{
8464 struct sir_wifi_start_log start_log = { 0 };
8465 QDF_STATUS status;
8466
8467 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8468 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8469 start_log.ini_triggered = cds_is_packet_log_enabled();
8470 start_log.user_triggered = 1;
8471 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308472 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308473
8474 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8475 if (!QDF_IS_STATUS_SUCCESS(status)) {
8476 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8477 EXIT();
8478 return -EINVAL;
8479 }
8480
8481 return 0;
8482}
8483
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008484/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308485 * hdd_pktlog_clear_buff() - clear pktlog buffer
8486 * @hdd_ctx: hdd context
8487 *
8488 * Return: 0 for success or error.
8489 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008490static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308491{
8492 struct sir_wifi_start_log start_log;
8493 QDF_STATUS status;
8494
8495 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8496 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8497 start_log.ini_triggered = cds_is_packet_log_enabled();
8498 start_log.user_triggered = 1;
8499 start_log.size = 0;
8500 start_log.is_pktlog_buff_clear = true;
8501
8502 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8503 if (!QDF_IS_STATUS_SUCCESS(status)) {
8504 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8505 EXIT();
8506 return -EINVAL;
8507 }
8508
8509 return 0;
8510}
8511
8512
8513/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008514 * hdd_process_pktlog_command() - process pktlog command
8515 * @hdd_ctx: hdd context
8516 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308517 * @set_value2: pktlog buffer size value
8518 *
8519 * This function process pktlog command.
8520 * set_value2 only matters when set_value is 3 (set buff size)
8521 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008522 *
8523 * Return: 0 for success or error.
8524 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008525int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308526 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008527{
8528 int ret;
8529 bool enable;
8530 uint8_t user_triggered = 0;
8531
8532 ret = wlan_hdd_validate_context(hdd_ctx);
8533 if (0 != ret)
8534 return ret;
8535
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008536 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008537
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308538 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008539 hdd_err("invalid pktlog value %d", set_value);
8540 return -EINVAL;
8541 }
8542
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308543 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8544 if (set_value2 <= 0) {
8545 hdd_err("invalid pktlog size %d", set_value2);
8546 return -EINVAL;
8547 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8548 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8549 return -EINVAL;
8550 }
8551 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308552 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8553 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308554 }
8555
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008556 /*
8557 * set_value = 0 then disable packetlog
8558 * set_value = 1 enable packetlog forcefully
8559 * set_vlaue = 2 then disable packetlog if disabled through ini or
8560 * enable packetlog with AUTO type.
8561 */
8562 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8563 true : false;
8564
8565 if (1 == set_value) {
8566 enable = true;
8567 user_triggered = 1;
8568 }
8569
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308570 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008571}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008572
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008573/**
8574 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8575 * @hdd_ctx: HDD context
8576 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308577 * @user_triggered: triggered through iwpriv
8578 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008579 *
8580 * Return: 0 on success; error number otherwise
8581 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008582int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308583 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008584{
8585 struct sir_wifi_start_log start_log;
8586 QDF_STATUS status;
8587
8588 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8589 start_log.verbose_level =
8590 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008591 start_log.ini_triggered = cds_is_packet_log_enabled();
8592 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308593 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308594 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308595 /*
8596 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8597 * commands. Host uses this flag to decide whether to send pktlog
8598 * disable command to fw without sending pktlog enable command
8599 * previously. For eg, If vendor sends pktlog disable command without
8600 * sending pktlog enable command, then host discards the packet
8601 * but for iwpriv command, host will send it to fw.
8602 */
8603 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008604 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8605 if (!QDF_IS_STATUS_SUCCESS(status)) {
8606 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8607 EXIT();
8608 return -EINVAL;
8609 }
8610
8611 return 0;
8612}
8613#endif /* REMOVE_PKT_LOG */
8614
Komal Seelam92fff912016-03-24 11:51:41 +05308615/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008616 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8617 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308618 * @dev: Device Pointer
8619 * @num: Number of Valid Mac address
8620 *
8621 * Return: Pointer to MAC address buffer
8622 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008623static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8624 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308625{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008626 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308627}
Komal Seelam92fff912016-03-24 11:51:41 +05308628
8629/**
8630 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8631 * @hdd_ctx: HDD Context
8632 * @num: Number of random mac addresses needed
8633 *
8634 * Generate random addresses using bit manipulation on the base mac address
8635 *
8636 * Return: None
8637 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008638void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308639{
8640 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8641 uint32_t iter;
8642 struct hdd_config *ini = hdd_ctx->config;
8643 uint8_t *buf = NULL;
8644 uint8_t macaddr_b3, tmp_br3;
8645 uint8_t *src = ini->intfMacAddr[0].bytes;
8646
8647 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8648 buf = ini->intfMacAddr[iter].bytes;
8649 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8650 macaddr_b3 = buf[3];
8651 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8652 INTF_MACADDR_MASK;
8653 macaddr_b3 += tmp_br3;
8654 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8655 buf[0] |= 0x02;
8656 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008657 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308658 }
8659}
8660
8661/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008662 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308663 * @hdd_ctx: HDD Context
8664 *
8665 * API to get mac addresses from platform driver and update the driver
8666 * structures and configure FW with the base mac address.
8667 * Return: int
8668 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008669static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308670{
8671 uint32_t no_of_mac_addr, iter;
8672 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8673 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8674 uint8_t *addr, *buf;
8675 struct device *dev = hdd_ctx->parent_dev;
8676 struct hdd_config *ini = hdd_ctx->config;
8677 tSirMacAddr mac_addr;
8678 QDF_STATUS status;
8679
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008680 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308681
8682 if (no_of_mac_addr == 0 || !addr) {
8683 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8684 return -EINVAL;
8685 }
8686
8687 if (no_of_mac_addr > max_mac_addr)
8688 no_of_mac_addr = max_mac_addr;
8689
8690 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8691
8692 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8693 buf = ini->intfMacAddr[iter].bytes;
8694 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008695 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308696 }
8697
8698 status = sme_set_custom_mac_addr(mac_addr);
8699
8700 if (!QDF_IS_STATUS_SUCCESS(status))
8701 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008702
Komal Seelam92fff912016-03-24 11:51:41 +05308703 if (no_of_mac_addr < max_mac_addr)
8704 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8705 no_of_mac_addr);
8706 return 0;
8707}
8708
8709/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008710 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8711 * @hdd_ctx: HDD Context
8712 *
8713 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8714 * will generate its own MAC and update it to FW.
8715 *
8716 * Return: 0 for success
8717 * Non-zero error code for failure
8718 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008719static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008720{
8721 tSirMacAddr customMacAddr;
8722 QDF_STATUS status;
8723
8724 qdf_mem_copy(&customMacAddr,
8725 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8726 sizeof(tSirMacAddr));
8727 status = sme_set_custom_mac_addr(customMacAddr);
8728 if (!QDF_IS_STATUS_SUCCESS(status))
8729 return -EAGAIN;
8730 return 0;
8731}
8732
8733/**
Komal Seelam92fff912016-03-24 11:51:41 +05308734 * hdd_initialize_mac_address() - API to get wlan mac addresses
8735 * @hdd_ctx: HDD Context
8736 *
8737 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8738 * is provisioned with mac addresses, driver uses it, else it will use
8739 * wlan_mac.bin to update HW MAC addresses.
8740 *
8741 * Return: None
8742 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008743static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308744{
8745 QDF_STATUS status;
8746 int ret;
8747
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008748 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308749 if (ret == 0)
8750 return;
8751
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008752 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8753 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308754
8755 status = hdd_update_mac_config(hdd_ctx);
8756
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008757 if (QDF_IS_STATUS_SUCCESS(status))
8758 return;
8759
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008760 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8761 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008762
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008763 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008764 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008765 if (ret != 0) {
8766 hdd_err("MAC address out-of-sync, ret:%d", ret);
8767 QDF_ASSERT(ret);
8768 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008769 }
Komal Seelam92fff912016-03-24 11:51:41 +05308770}
8771
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008772static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008773{
8774 int vdev_id = 0;
8775 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8776 int value = hdd_ctx->config->smart_chainmask_enabled;
8777 int vpdev = PDEV_CMD;
8778 int ret;
8779
Naveen Rawat247a8682017-06-05 15:00:31 -07008780 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008781 if (ret)
8782 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8783
8784 return ret;
8785}
8786
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008787static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008788{
8789 int vdev_id = 0;
8790 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8791 int value = hdd_ctx->config->alternative_chainmask_enabled;
8792 int vpdev = PDEV_CMD;
8793 int ret;
8794
Naveen Rawat247a8682017-06-05 15:00:31 -07008795 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008796 if (ret)
8797 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8798 ret);
8799
8800 return ret;
8801}
8802
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008803static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008804{
8805 int vdev_id = 0;
8806 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8807 int value = hdd_ctx->config->ani_enabled;
8808 int vpdev = PDEV_CMD;
8809 int ret;
8810
Naveen Rawat247a8682017-06-05 15:00:31 -07008811 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008812 if (ret)
8813 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8814
8815 return ret;
8816}
8817
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008818/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008819 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8820 * @hdd_ctx: HDD context
8821 *
8822 * Pre configurations to be done at lower layer before calling cds enable.
8823 *
8824 * Return: 0 on success and errno on failure.
8825 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008826static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008827{
8828 int ret;
8829 QDF_STATUS status;
8830 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008831 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008832
Leo Changfdb45c32016-10-28 11:09:23 -07008833 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008834 /*
8835 * Set 802.11p config
8836 * TODO-OCB: This has been temporarily added here to ensure this
8837 * parameter is set in CSR when we init the channel list. This should
8838 * be removed once the 5.9 GHz channels are added to the regulatory
8839 * domain.
8840 */
8841 hdd_set_dot11p_config(hdd_ctx);
8842
8843 /*
8844 * Note that the cds_pre_enable() sequence triggers the cfg download.
8845 * The cfg download must occur before we update the SME config
8846 * since the SME config operation must access the cfg database
8847 */
8848 status = hdd_set_sme_config(hdd_ctx);
8849
8850 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008851 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008852 ret = qdf_status_to_os_return(status);
8853 goto out;
8854 }
8855
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008856 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8857 if (QDF_STATUS_SUCCESS != status) {
8858 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8859 ret = qdf_status_to_os_return(status);
8860 goto out;
8861 }
8862
Naveen Rawat247a8682017-06-05 15:00:31 -07008863 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008864 hdd_ctx->config->tx_chain_mask_1ss,
8865 PDEV_CMD);
8866 if (0 != ret) {
8867 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8868 goto out;
8869 }
8870
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008871 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8872 if (ret)
8873 goto out;
8874
8875 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8876 if (ret)
8877 goto out;
8878
Jeff Johnson12a744b2017-04-04 08:19:37 -07008879 ret = hdd_set_ani_enabled(hdd_ctx);
8880 if (ret)
8881 goto out;
8882
Naveen Rawat247a8682017-06-05 15:00:31 -07008883 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008884 hdd_ctx->config->arp_ac_category,
8885 PDEV_CMD);
8886 if (0 != ret) {
8887 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8888 hdd_ctx->config->arp_ac_category, ret);
8889 goto out;
8890 }
8891
8892
Prashanth Bhatta07998752016-04-28 12:35:33 -07008893 status = hdd_set_sme_chan_list(hdd_ctx);
8894 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008895 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008896 ret = qdf_status_to_os_return(status);
8897 goto out;
8898 }
8899
8900 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008901 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008902 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008903 ret = -EINVAL;
8904 goto out;
8905 }
8906
Prashanth Bhatta07998752016-04-28 12:35:33 -07008907 /*
8908 * Set the MAC Address Currently this is used by HAL to add self sta.
8909 * Remove this once self sta is added as part of session open.
8910 */
8911 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8912 hdd_ctx->config->intfMacAddr[0].bytes,
8913 sizeof(hdd_ctx->config->intfMacAddr[0]));
8914
8915 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8916 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8917 hal_status, hal_status);
8918 ret = -EINVAL;
8919 goto out;
8920 }
8921
8922 hdd_init_channel_avoidance(hdd_ctx);
8923
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308924 /* update enable sap mandatory chan list */
8925 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8926 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008927out:
8928 return ret;
8929}
8930
8931/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008932 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8933 * @context_ptr - hdd context pointer
8934 * @event_ptr - event structure pointer
8935 *
8936 * This is the p2p listen offload stop event handler, it sends vendor
8937 * event back to supplicant to notify the stop reason.
8938 *
8939 * Return: None
8940 */
8941static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8942 void *event_ptr)
8943{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008944 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008945 struct sir_p2p_lo_event *evt = event_ptr;
8946 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008947 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008948
8949 ENTER();
8950
8951 if (hdd_ctx == NULL) {
8952 hdd_err("Invalid HDD context pointer");
8953 return;
8954 }
8955
Peng Xu5c682812017-08-06 07:39:13 -07008956 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8957 if (!adapter) {
8958 hdd_err("Cannot find adapter by vdev_id = %d",
8959 evt->vdev_id);
8960 return;
8961 }
8962
Peng Xu8fdaa492016-06-22 10:20:47 -07008963 vendor_event =
8964 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008965 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008966 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8967 GFP_KERNEL);
8968
8969 if (!vendor_event) {
8970 hdd_err("cfg80211_vendor_event_alloc failed");
8971 return;
8972 }
8973
8974 if (nla_put_u32(vendor_event,
8975 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8976 evt->reason_code)) {
8977 hdd_err("nla put failed");
8978 kfree_skb(vendor_event);
8979 return;
8980 }
8981
8982 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008983 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8984 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008985}
8986
8987/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308988 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8989 * @hdd_ctx: HDD context
8990 *
8991 * This function sends the adaptive dwell time config configuration to the
8992 * firmware via WMA
8993 *
8994 * Return: 0 - success, < 0 - failure
8995 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008996static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308997{
8998 QDF_STATUS status;
8999 struct adaptive_dwelltime_params dwelltime_params;
9000
9001 dwelltime_params.is_enabled =
9002 hdd_ctx->config->adaptive_dwell_mode_enabled;
9003 dwelltime_params.dwelltime_mode =
9004 hdd_ctx->config->global_adapt_dwelltime_mode;
9005 dwelltime_params.lpf_weight =
9006 hdd_ctx->config->adapt_dwell_lpf_weight;
9007 dwelltime_params.passive_mon_intval =
9008 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9009 dwelltime_params.wifi_act_threshold =
9010 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9011
9012 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9013 &dwelltime_params);
9014
9015 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9016 if (!QDF_IS_STATUS_SUCCESS(status)) {
9017 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9018 return -EAGAIN;
9019 }
9020 return 0;
9021}
9022
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009023int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309024{
9025 QDF_STATUS status;
9026 struct wmi_dbs_scan_sel_params dbs_scan_params;
9027 uint32_t i = 0;
9028 uint8_t count = 0, numentries = 0;
9029 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9030 * CDS_DBS_SCAN_CLIENTS_MAX];
9031
9032 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009033 if (hdd_ctx->config->dual_mac_feature_disable ==
9034 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309035 return -EINVAL;
9036
9037 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9038 dbs_scan_config, &numentries,
9039 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9040 * CDS_DBS_SCAN_CLIENTS_MAX));
9041
9042 hdd_info("numentries %hu", numentries);
9043 if (!numentries) {
9044 hdd_info("Donot send scan_selection_config");
9045 return 0;
9046 }
9047
9048 /* hdd_set_fw_log_params */
9049 dbs_scan_params.num_clients = 0;
9050 while (count < (numentries - 2)) {
9051 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9052 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9053 dbs_scan_params.num_non_dbs_scans[i] =
9054 dbs_scan_config[count + 2];
9055 dbs_scan_params.num_clients++;
9056 hdd_debug("module:%d NDS:%d NNDS:%d",
9057 dbs_scan_params.module_id[i],
9058 dbs_scan_params.num_dbs_scans[i],
9059 dbs_scan_params.num_non_dbs_scans[i]);
9060 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9061 i++;
9062 }
9063
9064 dbs_scan_params.pdev_id = 0;
9065
9066 hdd_debug("clients:%d pdev:%d",
9067 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9068
9069 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9070 &dbs_scan_params);
9071 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9072 if (!QDF_IS_STATUS_SUCCESS(status)) {
9073 hdd_err("Failed to send DBS Scan selection configuration!");
9074 return -EAGAIN;
9075 }
9076 return 0;
9077}
9078
Arun Khandavallid4349a92016-07-25 11:10:43 +05309079#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9080/**
9081 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9082 * @hdd_ctx: HDD context
9083 *
9084 * Set auto shutdown callback to get indications from firmware to indicate
9085 * userspace to shutdown WLAN after a configured amount of inactivity.
9086 *
9087 * Return: 0 on success and errno on failure.
9088 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009089static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309090{
9091 QDF_STATUS status;
9092
9093 if (!hdd_ctx->config->WlanAutoShutdown)
9094 return 0;
9095
9096 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9097 wlan_hdd_auto_shutdown_cb);
9098 if (status != QDF_STATUS_SUCCESS)
9099 hdd_err("Auto shutdown feature could not be enabled: %d",
9100 status);
9101
9102 return qdf_status_to_os_return(status);
9103}
9104#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009105static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309106{
9107 return 0;
9108}
9109#endif
9110
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009111static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009112{
9113 QDF_STATUS status = QDF_STATUS_SUCCESS;
9114
9115 switch (hdd_ctx->config->dual_mac_feature_disable) {
9116 case DISABLE_DBS_CXN_AND_SCAN:
9117 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9118 if (status != QDF_STATUS_SUCCESS)
9119 hdd_err("Failed to disable dual mac features");
9120 break;
9121 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9122 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9123 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9124 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9125 if (status != QDF_STATUS_SUCCESS)
9126 hdd_err("Failed to set dbs scan and fw mode config");
9127 break;
9128 default:
9129 break;
9130 }
9131
9132 return status;
9133}
9134
Arun Khandavallid4349a92016-07-25 11:10:43 +05309135/**
9136 * hdd_features_init() - Init features
9137 * @hdd_ctx: HDD context
9138 * @adapter: Primary adapter context
9139 *
9140 * Initialize features and their feature context after WLAN firmware is up.
9141 *
9142 * Return: 0 on success and errno on failure.
9143 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009144static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309145{
9146 tSirTxPowerLimit hddtxlimit;
9147 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309148 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309149 int ret;
9150
9151 ENTER();
9152
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009153 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309154 if (ret) {
9155 hdd_err("Failed to update country code: %d", ret);
9156 goto out;
9157 }
9158
9159 /* FW capabilities received, Set the Dot11 mode */
9160 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009161 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9162 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309163
Arun Khandavallid4349a92016-07-25 11:10:43 +05309164
9165 if (hdd_ctx->config->fIsImpsEnabled)
9166 hdd_set_idle_ps_config(hdd_ctx, true);
9167 else
9168 hdd_set_idle_ps_config(hdd_ctx, false);
9169
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309170 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009171 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309172
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309173 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9174 hdd_warn("Error in setting Voltage Corner mode config to FW");
9175
Arun Khandavallid4349a92016-07-25 11:10:43 +05309176 if (hdd_lro_init(hdd_ctx))
9177 hdd_err("Unable to initialize LRO in fw");
9178
9179 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9180 hdd_err("Unable to send adaptive dwelltime setting to FW");
9181
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309182 if (hdd_dbs_scan_selection_init(hdd_ctx))
9183 hdd_err("Unable to send DBS scan selection setting to FW");
9184
Arun Khandavallid4349a92016-07-25 11:10:43 +05309185 ret = hdd_init_thermal_info(hdd_ctx);
9186 if (ret) {
9187 hdd_err("Error while initializing thermal information");
9188 goto deregister_frames;
9189 }
9190
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309191 if (cds_is_packet_log_enabled())
9192 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9193
Arun Khandavallid4349a92016-07-25 11:10:43 +05309194 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9195 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9196 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9197 if (!QDF_IS_STATUS_SUCCESS(status))
9198 hdd_err("Error setting txlimit in sme: %d", status);
9199
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009200 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309201
Arun Khandavallid4349a92016-07-25 11:10:43 +05309202 ret = hdd_register_cb(hdd_ctx);
9203 if (ret) {
9204 hdd_err("Failed to register HDD callbacks!");
9205 goto deregister_frames;
9206 }
9207
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009208 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9209 if (!QDF_IS_STATUS_SUCCESS(status)) {
9210 hdd_err("Failed to set dbs scan and fw mode cfg");
9211 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309212 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009213
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309214 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9215 status = sme_enable_disable_chanavoidind_event(
9216 hdd_ctx->hHal, 0);
9217 if (!QDF_IS_STATUS_SUCCESS(status)) {
9218 hdd_err("Failed to disable Chan Avoidance Indication");
9219 goto deregister_cb;
9220 }
9221 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309222
Manjeet Singha9cae432017-02-28 11:58:22 +05309223 if (hdd_ctx->config->enable_5g_band_pref) {
9224 band_pref_params.rssi_boost_threshold_5g =
9225 hdd_ctx->config->rssi_boost_threshold_5g;
9226 band_pref_params.rssi_boost_factor_5g =
9227 hdd_ctx->config->rssi_boost_factor_5g;
9228 band_pref_params.max_rssi_boost_5g =
9229 hdd_ctx->config->max_rssi_boost_5g;
9230 band_pref_params.rssi_penalize_threshold_5g =
9231 hdd_ctx->config->rssi_penalize_threshold_5g;
9232 band_pref_params.rssi_penalize_factor_5g =
9233 hdd_ctx->config->rssi_penalize_factor_5g;
9234 band_pref_params.max_rssi_penalize_5g =
9235 hdd_ctx->config->max_rssi_penalize_5g;
9236 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9237 }
9238
Arun Khandavallid4349a92016-07-25 11:10:43 +05309239 /* register P2P Listen Offload event callback */
9240 if (wma_is_p2p_lo_capable())
9241 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9242 wlan_hdd_p2p_lo_event_callback);
9243
9244 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9245
9246 if (ret)
9247 goto deregister_cb;
9248
9249 EXIT();
9250 return 0;
9251
9252deregister_cb:
9253 hdd_deregister_cb(hdd_ctx);
9254deregister_frames:
9255 wlan_hdd_cfg80211_deregister_frames(adapter);
9256out:
9257 return -EINVAL;
9258
9259}
9260
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009261/**
9262 * hdd_features_deinit() - Deinit features
9263 * @hdd_ctx: HDD context
9264 *
9265 * De-Initialize features and their feature context.
9266 *
9267 * Return: none.
9268 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009269static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009270{
9271 wlan_hdd_tsf_deinit(hdd_ctx);
9272}
9273
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309274/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009275 * hdd_register_bcn_cb() - register scan beacon callback
9276 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309277 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009278 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009280static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309281{
9282 QDF_STATUS status;
9283
9284 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9285 wlan_cfg80211_inform_bss_frame,
9286 SCAN_CB_TYPE_INFORM_BCN);
9287 if (!QDF_IS_STATUS_SUCCESS(status)) {
9288 hdd_err("failed with status code %08d [x%08x]",
9289 status, status);
9290 return status;
9291 }
9292
9293 return QDF_STATUS_SUCCESS;
9294}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309295
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309296/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309297 * hdd_configure_cds() - Configure cds modules
9298 * @hdd_ctx: HDD context
9299 * @adapter: Primary adapter context
9300 *
9301 * Enable Cds modules after WLAN firmware is up.
9302 *
9303 * Return: 0 on success and errno on failure.
9304 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009305int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309306{
9307 int ret;
9308 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309309 int set_value;
9310 uint32_t num_abg_tx_chains = 0;
9311 uint32_t num_11b_tx_chains = 0;
9312 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009313 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309314
9315 if (hdd_ctx->config->sifs_burst_duration) {
9316 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9317 hdd_ctx->config->sifs_burst_duration;
9318
9319 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9320 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9321 set_value, PDEV_CMD);
9322 }
9323
9324 if (hdd_ctx->config->is_force_1x1)
9325 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9326 1, PDEV_CMD);
9327 /* set chip power save failure detected callback */
9328 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9329 hdd_chip_pwr_save_fail_detected_cb);
9330
9331 if (hdd_ctx->config->max_mpdus_inampdu) {
9332 set_value = hdd_ctx->config->max_mpdus_inampdu;
9333 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9334 set_value, PDEV_CMD);
9335 }
9336
9337 if (hdd_ctx->config->enable_rts_sifsbursting) {
9338 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9339 sme_cli_set_command(0,
9340 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9341 set_value, PDEV_CMD);
9342 }
9343
9344 if (hdd_ctx->config->sap_get_peer_info) {
9345 set_value = hdd_ctx->config->sap_get_peer_info;
9346 sme_cli_set_command(0,
9347 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9348 set_value, PDEV_CMD);
9349 }
9350
9351 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9352 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9353 if (!hdd_ctx->config->enable2x2) {
9354 if (num_11b_tx_chains > 1)
9355 num_11b_tx_chains = 1;
9356 if (num_11ag_tx_chains > 1)
9357 num_11ag_tx_chains = 1;
9358 }
9359 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9360 num_11b_tx_chains);
9361 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9362 num_11ag_tx_chains);
9363 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9364 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309365
9366 ret = hdd_pre_enable_configure(hdd_ctx);
9367 if (ret) {
9368 hdd_err("Failed to pre-configure cds");
9369 goto out;
9370 }
9371
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009372 /* Always get latest IPA resources allocated from cds_open and configure
9373 * IPA module before configuring them to FW. Sequence required as crash
9374 * observed otherwise.
9375 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009376 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9377 hdd_err("Failed to setup pipes");
9378 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009379 }
9380
Arun Khandavallifae92942016-08-01 13:31:08 +05309381 /*
9382 * Start CDS which starts up the SME/MAC/HAL modules and everything
9383 * else
9384 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009385 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309386
9387 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009388 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309389 goto out;
9390 }
9391
9392 status = hdd_post_cds_enable_config(hdd_ctx);
9393 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009394 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009395 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309396 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309397 status = hdd_register_bcn_cb(hdd_ctx);
9398 if (!QDF_IS_STATUS_SUCCESS(status)) {
9399 hdd_alert("hdd_post_cds_enable_config failed");
9400 goto cds_disable;
9401 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309402
9403 ret = hdd_features_init(hdd_ctx, adapter);
9404 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009405 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309406
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009407 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009408 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009409 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9410 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009411 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009412 goto cds_disable;
9413 }
9414
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309415 if (hdd_enable_egap(hdd_ctx))
9416 hdd_debug("enhance green ap is not enabled");
9417
Nachiket Kukadedd302662017-07-13 17:31:44 +05309418 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9419 hdd_debug("Failed to set wow pulse");
9420
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309421 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9422 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9423
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309424
9425 if (hdd_ctx->config->enable_phy_reg_retention)
9426 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9427 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9428
Arun Khandavallifae92942016-08-01 13:31:08 +05309429 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009430
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009431cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009432 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009433
Arun Khandavallifae92942016-08-01 13:31:08 +05309434out:
9435 return -EINVAL;
9436}
9437
9438/**
9439 * hdd_deconfigure_cds() -De-Configure cds
9440 * @hdd_ctx: HDD context
9441 *
9442 * Deconfigure Cds modules before WLAN firmware is down.
9443 *
9444 * Return: 0 on success and errno on failure.
9445 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009446static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309447{
9448 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009449 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309450
9451 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009452
9453 /* De-init features */
9454 hdd_features_deinit(hdd_ctx);
9455
Arun Khandavallifae92942016-08-01 13:31:08 +05309456 /* De-register the SME callbacks */
9457 hdd_deregister_cb(hdd_ctx);
9458
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009459 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309460 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9461 hdd_err("Failed to Disable the CDS Modules! :%d",
9462 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009463 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309464 }
9465
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309466 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9467 hdd_err("Failed to disconnect pipes");
9468 ret = -EINVAL;
9469 }
9470
Arun Khandavallifae92942016-08-01 13:31:08 +05309471 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009472 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309473}
9474
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009475#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9476static void hdd_deregister_policy_manager_callback(
9477 struct wlan_objmgr_psoc *psoc)
9478{
9479 if (QDF_STATUS_SUCCESS !=
9480 policy_mgr_deregister_hdd_cb(psoc)) {
9481 hdd_err("HDD callback deregister with policy manager failed");
9482 }
9483}
9484#else
9485static void hdd_deregister_policy_manager_callback(
9486 struct wlan_objmgr_psoc *psoc)
9487{
9488}
9489#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309490
9491/**
9492 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9493 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009494 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309495 *
9496 * This function maintains the driver state machine it will be invoked from
9497 * exit, shutdown and con_mode change handler. Depending on the driver state
9498 * shall perform the stopping/closing of the modules.
9499 *
9500 * Return: 0 for success; non-zero for failure
9501 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009502int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309503{
9504 void *hif_ctx;
9505 qdf_device_t qdf_ctx;
9506 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309507 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009508 bool is_idle_stop = !cds_is_driver_unloading() &&
9509 !cds_is_driver_recovering();
9510 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309511
9512 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009513 hdd_alert("stop WLAN module: entering driver status=%d",
9514 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309515
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009516 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9517
Arun Khandavallifae92942016-08-01 13:31:08 +05309518 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9519 if (!qdf_ctx) {
9520 hdd_err("QDF device context NULL");
9521 return -EINVAL;
9522 }
9523
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309524 mutex_lock(&hdd_ctx->iface_change_lock);
9525 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009526 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +05309527
Dustin Brown70111822017-03-30 15:31:40 -07009528 active_threads = cds_return_external_threads_count();
9529 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009530 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009531 active_threads, hdd_ctx->isWiphySuspended);
9532
9533 cds_print_external_threads();
9534
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009535 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009536 mutex_unlock(&hdd_ctx->iface_change_lock);
9537 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009538 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309539 hdd_prevent_suspend_timeout(
9540 hdd_ctx->config->iface_change_wait_time,
9541 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009542 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009543 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -07009544 return 0;
9545 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009546 }
9547
Arun Khandavallifae92942016-08-01 13:31:08 +05309548 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9549
9550 switch (hdd_ctx->driver_status) {
9551 case DRIVER_MODULES_UNINITIALIZED:
9552 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309553 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309554 case DRIVER_MODULES_CLOSED:
9555 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309556 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309557 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309558 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309559 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009560 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309561 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309562 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309563 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009564 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309565 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9566 break;
9567 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009568 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309569 break;
9570 default:
9571 hdd_err("Trying to stop wlan in a wrong state: %d",
9572 hdd_ctx->driver_status);
9573 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309574 ret = -EINVAL;
9575 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309576 }
9577
Rajeev Kumarbe021242017-02-16 16:12:23 -08009578 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309579 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9580 hdd_err("Failed to process post CDS disable Modules! :%d",
9581 qdf_status);
9582 ret = -EINVAL;
9583 QDF_ASSERT(0);
9584 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07009585
9586 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
9587 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9588 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
9589 ret = -EINVAL;
9590 QDF_ASSERT(0);
9591 }
9592
Jeff Johnsone4b14592017-09-13 14:23:33 -07009593 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309594 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009595 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309596 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309597 QDF_ASSERT(0);
9598 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009599
Arun Khandavallifae92942016-08-01 13:31:08 +05309600 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9601 if (!hif_ctx) {
9602 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309603 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309604 }
9605
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309606 hdd_runtime_suspend_context_deinit(hdd_ctx);
9607
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309608 if (hdd_ctx->target_hw_name) {
9609 qdf_mem_free(hdd_ctx->target_hw_name);
9610 hdd_ctx->target_hw_name = NULL;
9611 }
9612
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309613 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309614
9615 ol_cds_free();
9616
Dustin Brown70111822017-03-30 15:31:40 -07009617 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309618 ret = pld_power_off(qdf_ctx->dev);
9619 if (ret)
9620 hdd_err("CNSS power down failed put device into Low power mode:%d",
9621 ret);
9622 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309623
9624 /* Once the firmware sequence is completed reset this flag */
9625 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309626 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009627 /*
9628 * Reset total mac phy during module stop such that during
9629 * next module start same psoc is used to populate new service
9630 * ready data
9631 */
9632 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309633
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309634done:
9635 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009636 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309637 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07009638 hdd_alert("stop WLAN module: exit driver status=%d",
9639 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309640 EXIT();
9641
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309642 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309643
9644}
9645
9646/**
9647 * hdd_iface_change_callback() - Function invoked when stop modules expires
9648 * @priv: pointer to hdd context
9649 *
9650 * This function is invoked when the timer waiting for the interface change
9651 * expires, it shall cut-down the power to wlan and stop all the modules.
9652 *
9653 * Return: void
9654 */
9655static void hdd_iface_change_callback(void *priv)
9656{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009657 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309658 int ret;
9659 int status = wlan_hdd_validate_context(hdd_ctx);
9660
9661 if (status)
9662 return;
9663
9664 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009665 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009666 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309667 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009668 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309669 EXIT();
9670}
9671
9672/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309673 * hdd_state_info_dump() - prints state information of hdd layer
9674 * @buf: buffer pointer
9675 * @size: size of buffer to be filled
9676 *
9677 * This function is used to dump state information of hdd layer
9678 *
9679 * Return: None
9680 */
9681static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9682{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009683 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309684 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9685 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009686 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009687 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309688 uint16_t len = 0;
9689 char *buf = *buf_ptr;
9690
9691 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9692 if (!hdd_ctx) {
9693 hdd_err("Failed to get hdd context ");
9694 return;
9695 }
9696
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009697 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309698
9699 len += scnprintf(buf + len, *size - len,
9700 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9701 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009702 "\n is_scheduler_suspended %d",
9703 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309704
9705 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9706
9707 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009708 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309709 if (adapter->dev)
9710 len += scnprintf(buf + len, *size - len,
9711 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009712 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309713 "\n device_mode: %d", adapter->device_mode);
9714 switch (adapter->device_mode) {
9715 case QDF_STA_MODE:
9716 case QDF_P2P_CLIENT_MODE:
9717 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9718 len += scnprintf(buf + len, *size - len,
9719 "\n connState: %d",
9720 hdd_sta_ctx->conn_info.connState);
9721 break;
9722
9723 default:
9724 break;
9725 }
9726 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9727 adapter_node = next;
9728 }
9729
9730 *size -= len;
9731 *buf_ptr += len;
9732}
9733
9734/**
9735 * hdd_register_debug_callback() - registration function for hdd layer
9736 * to print hdd state information
9737 *
9738 * Return: None
9739 */
9740static void hdd_register_debug_callback(void)
9741{
9742 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9743}
9744
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309745/*
9746 * wlan_init_bug_report_lock() - Initialize bug report lock
9747 *
9748 * This function is used to create bug report lock
9749 *
9750 * Return: None
9751 */
9752static void wlan_init_bug_report_lock(void)
9753{
9754 p_cds_contextType p_cds_context;
9755
9756 p_cds_context = cds_get_global_context();
9757 if (!p_cds_context) {
9758 hdd_err("cds context is NULL");
9759 return;
9760 }
9761
9762 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9763}
9764
Mohit Khannaf8f96822017-05-17 17:11:59 -07009765void hdd_dp_trace_init(struct hdd_config *config)
9766{
9767
9768 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9769 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9770 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9771 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9772 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9773 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9774 uint8_t num_entries = 0;
9775
9776 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9777 &num_entries, sizeof(config_params));
9778
9779 /* calculating, num bw timer intervals in a second (1000ms) */
9780 if (config->busBandwidthComputeInterval)
9781 thresh_time_limit =
9782 (1000 / config->busBandwidthComputeInterval);
9783 else
9784 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9785
9786 switch (num_entries) {
9787 case 4:
9788 proto_bitmap = config_params[3];
9789 case 3:
9790 verbosity = config_params[2];
9791 case 2:
9792 thresh = config_params[1];
9793 case 1:
9794 live_mode = config_params[0];
9795 default:
9796 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9797 live_mode, thresh, thresh_time_limit,
9798 verbosity, proto_bitmap);
9799 };
9800
9801 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9802 verbosity, proto_bitmap);
9803
9804}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309805/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009806 * hdd_wlan_startup() - HDD init function
9807 * @dev: Pointer to the underlying device
9808 *
9809 * This is the driver startup code executed once a WLAN device has been detected
9810 *
9811 * Return: 0 for success, < 0 for failure
9812 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309813int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009814{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309815 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009816 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009817 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009818 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009819
9820 ENTER();
9821
Arun Khandavallifae92942016-08-01 13:31:08 +05309822 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009823
9824 if (IS_ERR(hdd_ctx))
9825 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009826
Abhishek Singhe9068f12017-03-31 14:14:52 +05309827 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9828 DEFAULT_PSOC_ID);
9829 if (ret) {
9830 hdd_err("Psoc creation fails!");
9831 QDF_BUG(0);
9832 goto err_hdd_free_context;
9833 }
9834
Arun Khandavallifae92942016-08-01 13:31:08 +05309835 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9836 hdd_iface_change_callback, (void *)hdd_ctx);
9837
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309838 qdf_nbuf_init_replenish_timer();
9839
Arun Khandavallifae92942016-08-01 13:31:08 +05309840 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309841#ifdef FEATURE_WLAN_CH_AVOID
9842 mutex_init(&hdd_ctx->avoid_freq_lock);
9843#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309844
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009845 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009846 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309847
Jeff Johnson957bc272017-02-02 08:54:48 -08009848 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309849 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009850 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009851 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009852 }
9853
Yingying Tang80e15f32016-09-27 18:23:01 +08009854 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009855
Anurag Chouhan6d760662016-02-20 16:05:43 +05309856 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009857
9858 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009859 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309860 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009861 }
9862
Prashanth Bhatta07998752016-04-28 12:35:33 -07009863 ret = hdd_wiphy_init(hdd_ctx);
9864 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009865 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309866 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009867 }
9868
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309869 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009870 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309871
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309872 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009873 goto err_wiphy_unregister;
9874
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309875 wlan_hdd_init_chan_info(hdd_ctx);
9876
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009877 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009878
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309879 ret = hdd_register_notifiers(hdd_ctx);
9880 if (ret)
9881 goto err_ipa_cleanup;
9882
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009883 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009884
Jeff Johnson957bc272017-02-02 08:54:48 -08009885 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9886 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009887 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009888 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009889 }
9890
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009891 hdd_release_rtnl_lock();
9892 rtnl_held = false;
9893
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009894 wlan_hdd_update_11n_mode(hdd_ctx->config);
9895
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009896#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309897 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309898 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009899 hdd_skip_acs_scan_timer_handler,
9900 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309901 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009902 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009903 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009904#endif
9905
Prashanth Bhattaab004382016-10-11 16:08:11 -07009906 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009907
Jeff Johnson9afc5012016-09-23 13:56:27 -07009908 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009909
Nirav Shahbd36b062016-07-18 11:12:59 +05309910 if (hdd_ctx->rps)
9911 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009912
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309913 status = wlansap_global_init();
9914 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009915 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009916
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009917 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309918 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009919
Arun Khandavallifae92942016-08-01 13:31:08 +05309920 if (hdd_ctx->config->fIsImpsEnabled)
9921 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -07009922 else
9923 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309924
Mukul Sharma07bd8752017-10-10 16:58:14 +05309925 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309926 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309927 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309928 hdd_prevent_suspend_timeout(
9929 hdd_ctx->config->iface_change_wait_time,
9930 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
9931 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309932
Sachin Ahujadddd2632017-03-07 19:07:24 +05309933 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009934 goto success;
9935
Jeff Johnson957bc272017-02-02 08:54:48 -08009936err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009937 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009938
Jeff Johnson46bde382017-02-01 15:31:16 -08009939err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309940 if (rtnl_held)
9941 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009942
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309943 unregister_netdevice_notifier(&hdd_netdev_notifier);
9944
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309945err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309946 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009947
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009948err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009949 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009950
Arun Khandavallifae92942016-08-01 13:31:08 +05309951err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009952 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309953
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009954err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309955 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009956 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309957 if (!QDF_IS_STATUS_SUCCESS(status)) {
9958 hdd_err("Failed to close CDS Scheduler");
9959 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9960 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009961 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009962
Houston Hoffman47a4a052016-11-14 23:22:44 -08009963 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009964 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009965 hdd_exit_netlink_services(hdd_ctx);
9966
Dustin Brown20912462017-06-07 13:48:25 -07009967 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9968
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009969err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309970 if (cds_is_fw_down())
9971 hdd_err("Not setting the complete event as fw is down");
9972 else
9973 hdd_start_complete(ret);
9974
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309975 qdf_nbuf_deinit_replenish_timer();
Arun Khandavallifae92942016-08-01 13:31:08 +05309976 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9977 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009978 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07009979 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009980
9981success:
9982 EXIT();
9983 return 0;
9984}
9985
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009986/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309987 * hdd_wlan_update_target_info() - update target type info
9988 * @hdd_ctx: HDD context
9989 * @context: hif context
9990 *
9991 * Update target info received from firmware in hdd context
9992 * Return:None
9993 */
9994
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009995void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309996{
9997 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9998
9999 if (!tgt_info) {
10000 hdd_err("Target info is Null");
10001 return;
10002 }
10003
10004 hdd_ctx->target_type = tgt_info->target_type;
10005}
10006
10007/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010008 * hdd_get_nud_stats_cb() - callback api to update the stats
10009 * received from the firmware
10010 * @data: pointer to adapter.
10011 * @rsp: pointer to data received from FW.
10012 *
10013 * This is called when wlan driver received response event for
10014 * get arp stats to firmware.
10015 *
10016 * Return: None
10017 */
10018static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10019{
10020 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10021 struct hdd_nud_stats_context *context;
10022 int status;
10023 struct hdd_adapter *adapter = NULL;
10024
10025 ENTER();
10026
10027 if (!rsp) {
10028 hdd_err("data is null");
10029 return;
10030 }
10031
10032 status = wlan_hdd_validate_context(hdd_ctx);
10033 if (0 != status)
10034 return;
10035
10036 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10037 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10038 hdd_err("Invalid adapter or adapter has invalid magic");
10039 return;
10040 }
10041
10042 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10043 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10044 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10045 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10046 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10047 rsp->out_of_order_arp_rsp_drop_cnt);
10048 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10049 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10050 hdd_notice("rsp->ba_session_establishment_status :%x",
10051 rsp->ba_session_establishment_status);
10052
10053 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10054 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10055 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10056 adapter->dad |= rsp->dad_detected;
10057 adapter->con_status = rsp->connect_status;
10058
10059 spin_lock(&hdd_context_lock);
10060 context = &hdd_ctx->nud_stats_context;
10061 complete(&context->response_event);
10062 spin_unlock(&hdd_context_lock);
10063
10064 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010065}
10066
10067/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010068 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010069 * @hdd_ctx: HDD context
10070 *
10071 * Register the HDD callbacks to CDS/SME.
10072 *
10073 * Return: 0 for success or Error code for failure
10074 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010075int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010076{
10077 QDF_STATUS status;
10078 int ret = 0;
10079
10080 ENTER();
10081
10082 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10083
10084 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10085 hdd_send_oem_data_rsp_msg);
10086
10087 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10088 wlan_hdd_cfg80211_fw_mem_dump_cb);
10089 if (!QDF_IS_STATUS_SUCCESS(status)) {
10090 hdd_err("Failed to register memdump callback");
10091 ret = -EINVAL;
10092 return ret;
10093 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010094 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10095 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010096 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10097 sme_nan_register_callback(hdd_ctx->hHal,
10098 wlan_hdd_cfg80211_nan_callback);
10099 sme_stats_ext_register_callback(hdd_ctx->hHal,
10100 wlan_hdd_cfg80211_stats_ext_callback);
10101
10102 sme_ext_scan_register_callback(hdd_ctx->hHal,
10103 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010104 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10105 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010106
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010107 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10108 hdd_rssi_threshold_breached);
10109
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010110 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10111
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010112 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10113 wlan_hdd_cfg80211_link_layer_stats_callback);
10114
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010115 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10116
Zhang Qianca38fb12016-12-23 11:10:48 +080010117 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10118 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10119
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010120 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10121 hdd_lost_link_info_cb);
10122 /* print error and not block the startup process */
10123 if (!QDF_IS_STATUS_SUCCESS(status))
10124 hdd_err("set lost link info callback failed");
10125
Poddar, Siddarth34872782017-08-10 14:08:51 +053010126 ret = hdd_register_data_stall_detect_cb();
10127 if (ret) {
10128 hdd_err("Register data stall detect detect callback failed.");
10129 return ret;
10130 }
10131
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010132 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10133
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010134 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010135 hdd_set_connection_in_progress,
10136 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010137
10138 status = sme_congestion_register_callback(hdd_ctx->hHal,
10139 hdd_update_cca_info_cb);
10140 if (!QDF_IS_STATUS_SUCCESS(status))
10141 hdd_err("set congestion callback failed");
10142
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010143 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10144 hdd_bt_activity_cb);
10145 if (!QDF_IS_STATUS_SUCCESS(status))
10146 hdd_err("set bt activity info callback failed");
10147
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010148 EXIT();
10149
10150 return ret;
10151}
10152
10153/**
10154 * hdd_deregister_cb() - De-Register HDD callbacks.
10155 * @hdd_ctx: HDD context
10156 *
10157 * De-Register the HDD callbacks to CDS/SME.
10158 *
10159 * Return: void
10160 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010161void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010162{
10163 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010164 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010165
10166 ENTER();
10167
10168 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10169 if (!QDF_IS_STATUS_SUCCESS(status))
10170 hdd_err("De-register of dcc stats callback failed: %d",
10171 status);
10172
10173 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010174 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10175
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010176 sme_stats_ext_register_callback(hdd_ctx->hHal,
10177 wlan_hdd_cfg80211_stats_ext_callback);
10178
10179 sme_nan_deregister_callback(hdd_ctx->hHal);
10180 status = sme_reset_tsfcb(hdd_ctx->hHal);
10181 if (!QDF_IS_STATUS_SUCCESS(status))
10182 hdd_err("Failed to de-register tsfcb the callback:%d",
10183 status);
10184 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10185 if (!QDF_IS_STATUS_SUCCESS(status))
10186 hdd_err("Failed to de-register the fw mem dump callback: %d",
10187 status);
10188
Poddar, Siddarth34872782017-08-10 14:08:51 +053010189 ret = hdd_deregister_data_stall_detect_cb();
10190 if (ret)
10191 hdd_err("Failed to de-register data stall detect event callback");
10192
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010193 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10194 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10195
10196 EXIT();
10197}
10198
10199/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010200 * hdd_softap_sta_deauth() - handle deauth req from HDD
10201 * @adapter: Pointer to the HDD
10202 * @enable: bool value
10203 *
10204 * This to take counter measure to handle deauth req from HDD
10205 *
10206 * Return: None
10207 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010208QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010209 struct tagCsrDelStaParams *pDelStaParams)
10210{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010211 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010212
10213 ENTER();
10214
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010215 /* Ignore request to deauth bcmc station */
10216 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010217 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010218
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010219 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010220 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10221 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010222
10223 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010224 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010225}
10226
10227/**
10228 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10229 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010230 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010231 *
10232 * This to take counter measure to handle deauth req from HDD
10233 *
10234 * Return: None
10235 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010236void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010237 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010238{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010239 ENTER();
10240
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010241 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010242 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010243 return;
10244
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010245 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010246 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010247}
10248
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010249/**
10250 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10251 * @hdd_ctx: HDD Context
10252 *
10253 * API to find if there is any STA or P2P-Client is connected
10254 *
10255 * Return: true if connected; false otherwise
10256 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010257QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010258{
10259 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10260}
10261
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010262/**
10263 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10264 * @adapter: HDD adapter pointer
10265 *
10266 * This function loop through each adapter and disable roaming on each STA
10267 * device mode except the input adapter.
10268 *
10269 * Note: On the input adapter roaming is not enabled yet hence no need to
10270 * disable.
10271 *
10272 * Return: None
10273 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010274void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010275{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010276 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010277 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010278 hdd_adapter_list_node_t *adapterNode = NULL;
10279 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010280 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010281
10282 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010283 hdd_ctx->config->isRoamOffloadScanEnabled &&
10284 QDF_STA_MODE == adapter->device_mode &&
10285 policy_mgr_is_sta_active_connection_exists(
10286 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010287 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010288 adapter->sessionId);
10289 /*
10290 * Loop through adapter and disable roaming for each STA device
10291 * mode except the input adapter.
10292 */
10293 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10294
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010295 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010296 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010297
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010298 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010299 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010300 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010301 adapterIdx->sessionId);
10302 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10303 (adapterIdx),
10304 adapterIdx->sessionId, 0);
10305 }
10306
10307 status = hdd_get_next_adapter(hdd_ctx,
10308 adapterNode,
10309 &pNext);
10310 adapterNode = pNext;
10311 }
10312 }
10313}
10314
10315/**
10316 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10317 * @adapter: HDD adapter pointer
10318 *
10319 * This function loop through each adapter and enable roaming on each STA
10320 * device mode except the input adapter.
10321 * Note: On the input adapter no need to enable roaming because link got
10322 * disconnected on this.
10323 *
10324 * Return: None
10325 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010326void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010327{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010328 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010329 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010330 hdd_adapter_list_node_t *adapterNode = NULL;
10331 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010332 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010333
10334 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010335 hdd_ctx->config->isRoamOffloadScanEnabled &&
10336 QDF_STA_MODE == adapter->device_mode &&
10337 policy_mgr_is_sta_active_connection_exists(
10338 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010339 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010340 adapter->sessionId);
10341 /*
10342 * Loop through adapter and enable roaming for each STA device
10343 * mode except the input adapter.
10344 */
10345 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10346
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010347 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010348 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010349
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010350 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010351 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010352 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010353 adapterIdx->sessionId);
10354 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10355 (adapterIdx),
10356 adapterIdx->sessionId,
10357 REASON_CONNECT);
10358 }
10359
10360 status = hdd_get_next_adapter(hdd_ctx,
10361 adapterNode,
10362 &pNext);
10363 adapterNode = pNext;
10364 }
10365 }
10366}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010367
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010368/**
10369 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10370 * @skb: sk buffer pointer
10371 *
10372 * Sends the bcast message to SVC multicast group with generic nl socket
10373 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10374 *
10375 * Return: None
10376 */
10377static void nl_srv_bcast_svc(struct sk_buff *skb)
10378{
10379#ifdef CNSS_GENL
10380 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10381#else
10382 nl_srv_bcast(skb);
10383#endif
10384}
10385
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010386void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010387{
10388 struct sk_buff *skb;
10389 struct nlmsghdr *nlh;
10390 tAniMsgHdr *ani_hdr;
10391 void *nl_data = NULL;
10392 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010393 struct radio_index_tlv *radio_info;
10394 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010395
10396 if (in_interrupt() || irqs_disabled() || in_atomic())
10397 flags = GFP_ATOMIC;
10398
10399 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10400
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010401 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010402 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010403
10404 nlh = (struct nlmsghdr *)skb->data;
10405 nlh->nlmsg_pid = 0; /* from kernel */
10406 nlh->nlmsg_flags = 0;
10407 nlh->nlmsg_seq = 0;
10408 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10409
10410 ani_hdr = NLMSG_DATA(nlh);
10411 ani_hdr->type = type;
10412
10413 switch (type) {
10414 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010415 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010416 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010417 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010418 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010419 ani_hdr->length = 0;
10420 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010421 break;
10422 case WLAN_SVC_WLAN_STATUS_IND:
10423 case WLAN_SVC_WLAN_VERSION_IND:
10424 case WLAN_SVC_DFS_CAC_START_IND:
10425 case WLAN_SVC_DFS_CAC_END_IND:
10426 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10427 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10428 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010429 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010430 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010431 ani_hdr->length = len;
10432 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10433 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10434 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010435 break;
10436
10437 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010438 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010439 type);
10440 kfree_skb(skb);
10441 return;
10442 }
10443
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010444 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010445 * Add radio index at the end of the svc event in TLV format
10446 * to maintain the backward compatibility with userspace
10447 * applications.
10448 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010449
10450 tlv_len = 0;
10451
10452 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10453 < WLAN_NL_MAX_PAYLOAD) {
10454 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10455 sizeof(*ani_hdr) + len);
10456 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10457 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10458 radio_info->radio = radio;
10459 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010460 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010461 "Added radio index tlv - radio index %d",
10462 radio_info->radio);
10463 }
10464
10465 nlh->nlmsg_len += tlv_len;
10466 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10467
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010468 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010469}
10470
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010471#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10472void wlan_hdd_auto_shutdown_cb(void)
10473{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010474 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010475
10476 if (!hdd_ctx)
10477 return;
10478
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010479 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010480 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10481 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010482}
10483
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010484void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010485{
10486 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010487 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010488 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010489 bool ap_connected = false, sta_connected = false;
10490 tHalHandle hal_handle;
10491
10492 hal_handle = hdd_ctx->hHal;
10493 if (hal_handle == NULL)
10494 return;
10495
10496 if (hdd_ctx->config->WlanAutoShutdown == 0)
10497 return;
10498
10499 if (enable == false) {
10500 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010501 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010502 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010503 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010504 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010505 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010506 return;
10507 }
10508
10509 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010510 if (policy_mgr_concurrent_open_sessions_running(
10511 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010512 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10513
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010514 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010515 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010516 if (adapter
10517 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010518 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010519 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10520 conn_info.connState ==
10521 eConnectionState_Associated) {
10522 sta_connected = true;
10523 break;
10524 }
10525 }
10526 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010527 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010528 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10529 bApActive == true) {
10530 ap_connected = true;
10531 break;
10532 }
10533 }
10534 status = hdd_get_next_adapter(hdd_ctx,
10535 adapterNode,
10536 &pNext);
10537 adapterNode = pNext;
10538 }
10539 }
10540
10541 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010542 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010543 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010544 }
Jeff Johnson68755312017-02-10 11:46:55 -080010545
10546 if (sme_set_auto_shutdown_timer(hal_handle,
10547 hdd_ctx->config->WlanAutoShutdown)
10548 != QDF_STATUS_SUCCESS)
10549 hdd_err("Failed to start wlan auto shutdown timer");
10550 else
10551 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10552 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010553}
10554#endif
10555
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010556struct hdd_adapter *
10557hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10558 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010559{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010560 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010561 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010562 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010563 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10564
10565 con_sap_adapter = NULL;
10566
10567 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010568 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010569 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010570 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10571 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010572 adapter != this_sap_adapter) {
10573 if (check_start_bss) {
10574 if (test_bit(SOFTAP_BSS_STARTED,
10575 &adapter->event_flags)) {
10576 con_sap_adapter = adapter;
10577 break;
10578 }
10579 } else {
10580 con_sap_adapter = adapter;
10581 break;
10582 }
10583 }
10584 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10585 adapterNode = pNext;
10586 }
10587
10588 return con_sap_adapter;
10589}
10590
10591#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010592static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010593{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010594 return adapter->device_mode == QDF_STA_MODE ||
10595 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010596}
10597
Jeff Johnson9d295242017-08-29 14:39:48 -070010598static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010599{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010600 return adapter->device_mode == QDF_SAP_MODE ||
10601 adapter->device_mode == QDF_P2P_GO_MODE;
10602}
10603
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010604static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010605{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010606 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010607 hdd_adapter_list_node_t *node;
10608
10609 status = hdd_get_front_adapter(hdd_ctx, &node);
10610 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010611 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010612
10613 if (adapter &&
10614 hdd_adapter_is_sta(adapter) &&
10615 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10616 conn_info.connState == eConnectionState_Associated) {
10617 return true;
10618 }
10619
10620 if (adapter &&
10621 hdd_adapter_is_ap(adapter) &&
10622 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10623 return true;
10624 }
10625
10626 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10627 }
10628
10629 return false;
10630}
10631
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010632static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010633{
10634 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010635
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010636 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010637 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010638 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010639
Dustin Brown5ec6b552017-03-31 12:11:40 -070010640 return is_running;
10641}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010642
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010643static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010644{
10645 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10646 hdd_ctx->bus_bw_timer_running = true;
10647 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10648 hdd_ctx->config->busBandwidthComputeInterval);
10649 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10650}
10651
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010652void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010653{
10654 ENTER();
10655
10656 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10657 hdd_debug("Bandwidth compute timer already started");
10658 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010659 }
10660
Dustin Brown5ec6b552017-03-31 12:11:40 -070010661 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10662
10663 EXIT();
10664}
10665
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010666void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010667{
10668 ENTER();
10669
10670 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10671 hdd_debug("Bandwidth compute timer already started");
10672 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010673 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010674
10675 if (hdd_any_adapter_is_assoc(hdd_ctx))
10676 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10677
10678 EXIT();
10679}
10680
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010681static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010682{
10683 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10684
10685 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10686 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10687 hdd_ctx->bus_bw_timer_running = false;
10688 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10689
10690 hdd_reset_tcp_delack(hdd_ctx);
10691}
10692
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010693void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010694{
10695 ENTER();
10696
10697 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10698 hdd_debug("Bandwidth compute timer already stopped");
10699 return;
10700 }
10701
10702 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10703
10704 EXIT();
10705}
10706
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010707void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010708{
10709 ENTER();
10710
10711 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10712 hdd_debug("Bandwidth compute timer already stopped");
10713 return;
10714 }
10715
10716 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10717 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10718
10719 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010720}
10721#endif
10722
10723/**
10724 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10725 * and sta's operating channel.
10726 * @sta_adapter: Describe the first argument to foobar.
10727 * @ap_adapter: Describe the second argument to foobar.
10728 * @roam_profile: Roam profile of AP to which STA wants to connect.
10729 * @concurrent_chnl_same: If both SAP and STA channels are same then
10730 * set this flag to true else false.
10731 *
10732 * This function checks the sap's operating channel and sta's operating channel.
10733 * if both are same then it will return false else it will restart the sap in
10734 * sta's channel and return true.
10735 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010736 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010737 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010738QDF_STATUS
10739wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10740 struct hdd_adapter *ap_adapter,
10741 tCsrRoamProfile *roam_profile,
10742 tScanResultHandle *scan_cache,
10743 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010744{
Jeff Johnson87251032017-08-29 13:31:11 -070010745 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010746 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010747 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010748 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010749 *concurrent_chnl_same = true;
10750
10751 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10752 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010753 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010754 scan_cache,
10755 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010756 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010757 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010758 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10759 if (hdd_ap_ctx->operatingChannel != channel_id) {
10760 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010761 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010762 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010763 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010764 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10765 if (hdd_ap_ctx->operatingChannel != channel_id) {
10766 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010767 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010768 }
10769 }
10770 } else {
10771 /*
10772 * Lets handle worst case scenario here, Scan cache lookup is
10773 * failed so we have to stop the SAP to avoid any channel
10774 * discrepancy between SAP's channel and STA's channel.
10775 * Return the status as failure so caller function could know
10776 * that scan look up is failed.
10777 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010778 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010779 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010780 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010781 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010782}
10783
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010784/**
10785 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10786 * @ap_adapter: SAP adapter
10787 *
10788 * This function will process the stopping of sap adapter.
10789 *
10790 * Return: None
10791 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010792void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010793{
Jeff Johnson87251032017-08-29 13:31:11 -070010794 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010795 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010796 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010797 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010798
10799 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010800 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010801 return;
10802 }
10803
10804 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10805 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010806 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010807 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010808
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010809 mutex_lock(&hdd_ctx->sap_lock);
10810 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010811 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010812 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10813 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010814 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010815 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010816 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010817 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010818 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010819 qdf_stop_bss_event,
10820 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010821 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010822 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010823 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010824 return;
10825 }
10826 }
10827 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010828 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10829 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010830 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010831 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010832 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010833 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010834 }
10835 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010836}
10837
10838/**
10839 * wlan_hdd_start_sap() - this function starts bss of SAP.
10840 * @ap_adapter: SAP adapter
10841 *
10842 * This function will process the starting of sap adapter.
10843 *
10844 * Return: None
10845 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010846void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010847{
Jeff Johnson87251032017-08-29 13:31:11 -070010848 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010849 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010850 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010851 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010852 tsap_Config_t *sap_config;
10853
10854 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010855 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010856 return;
10857 }
10858
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010859 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010860 hdd_err("SoftAp role has not been enabled");
10861 return;
10862 }
10863
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010864 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10865 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10866 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10867 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10868
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010869 mutex_lock(&hdd_ctx->sap_lock);
10870 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10871 goto end;
10872
10873 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010874 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010875 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10876 goto end;
10877 }
10878
Wei Song2f76f642016-11-18 16:32:53 +080010879 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010880 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10881 &hdd_ap_ctx->sapConfig,
10882 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010883 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010884 goto end;
10885
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010886 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010887 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010888 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010889 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010890 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010891 goto end;
10892 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010893 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010894 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010895 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010896 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10897 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010898 ap_adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010899end:
10900 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010901 /* SAP context and beacon cleanup will happen during driver unload
10902 * in hdd_stop_adapter
10903 */
10904 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10905
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010906}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010907
10908/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010909 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10910 * mac scan config
10911 * @status: Status of set antenna mode
10912 *
10913 * Callback on setting the dual mac configuration
10914 *
10915 * Return: None
10916 */
10917void wlan_hdd_soc_set_antenna_mode_cb(
10918 enum set_antenna_mode_status status)
10919{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010920 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010921
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010922 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010923
10924 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10925 if (0 != wlan_hdd_validate_context(hdd_ctx))
10926 return;
10927
10928 /* Signal the completion of set dual mac config */
10929 complete(&hdd_ctx->set_antenna_mode_cmpl);
10930}
10931
10932/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010933 * hdd_get_fw_version() - Get FW version
10934 * @hdd_ctx: pointer to HDD context.
10935 * @major_spid: FW version - major spid.
10936 * @minor_spid: FW version - minor spid
10937 * @ssid: FW version - ssid
10938 * @crmid: FW version - crmid
10939 *
10940 * This function is called to get the firmware build version stored
10941 * as part of the HDD context
10942 *
10943 * Return: None
10944 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010945void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010946 uint32_t *major_spid, uint32_t *minor_spid,
10947 uint32_t *siid, uint32_t *crmid)
10948{
10949 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10950 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10951 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10952 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10953}
10954
10955#ifdef QCA_CONFIG_SMP
10956/**
10957 * wlan_hdd_get_cpu() - get cpu_index
10958 *
10959 * Return: cpu_index
10960 */
10961int wlan_hdd_get_cpu(void)
10962{
10963 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010964
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010965 put_cpu();
10966 return cpu_index;
10967}
10968#endif
10969
10970/**
10971 * hdd_get_fwpath() - get framework path
10972 *
10973 * This function is used to get the string written by
10974 * userspace to start the wlan driver
10975 *
10976 * Return: string
10977 */
10978const char *hdd_get_fwpath(void)
10979{
10980 return fwpath.string;
10981}
10982
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010983static int hdd_qdf_print_init(void)
10984{
10985 int qdf_print_idx;
10986 QDF_STATUS status;
10987
10988 status = qdf_print_setup();
10989 if (status != QDF_STATUS_SUCCESS) {
10990 pr_err("qdf_print_setup failed\n");
10991 return -EINVAL;
10992 }
10993
10994 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10995
10996 if (qdf_print_idx < 0) {
10997 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10998 qdf_print_idx);
10999 return -EINVAL;
11000 }
11001
11002 qdf_set_pidx(qdf_print_idx);
11003
11004 return 0;
11005}
11006
11007static void hdd_qdf_print_deinit(void)
11008{
11009 int qdf_print_idx;
11010
11011 qdf_print_idx = qdf_get_pidx();
11012 qdf_print_ctrl_cleanup(qdf_print_idx);
11013}
11014
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011015/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011016 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011017 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011018 * This function initilizes CDS global context with the help of cds_init. This
11019 * has to be the first function called after probe to get a valid global
11020 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011021 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011022 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011023 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011024int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011025{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011026 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011027 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011028
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011029 status = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011030
11031 wlan_init_bug_report_lock();
11032
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011033#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11034 wlan_logging_sock_init_svc();
11035#endif
11036
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011037 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011038 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011039 ret = -ENOMEM;
11040 goto err_out;
11041 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011042
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011043 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11044 (void *)hdd_drv_ops_inactivity_handler, NULL,
11045 QDF_TIMER_TYPE_SW);
11046
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011047 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011048 hdd_qdf_print_init();
11049
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011050 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011051
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011052err_out:
11053 return ret;
11054}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011055
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011056/**
11057 * hdd_deinit() - Deinitialize Driver
11058 *
11059 * This function frees CDS global context with the help of cds_deinit. This
11060 * has to be the last function call in remove callback to free the global
11061 * context.
11062 */
11063void hdd_deinit(void)
11064{
Dustin Brownedce4a52017-05-10 11:59:15 -070011065 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011066 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011067
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011068 wlan_destroy_bug_report_lock();
11069 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011070
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011071 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011072#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11073 wlan_logging_sock_deinit_svc();
11074#endif
11075}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011076
Yue Ma6e7b1a02017-04-03 14:17:46 -070011077#ifdef QCA_WIFI_NAPIER_EMULATION
11078#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11079#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011080#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011081#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011082
Sachin Ahujadddd2632017-03-07 19:07:24 +053011083static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11084 struct file *file)
11085{
11086 return 0;
11087}
11088
11089static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11090 const char __user *user_buf,
11091 size_t count,
11092 loff_t *f_pos)
11093{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011094 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011095 static const char wlan_off_str[] = "OFF";
11096 static const char wlan_on_str[] = "ON";
11097 int ret;
11098 unsigned long rc;
11099
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011100 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011101 pr_err("Failed to read buffer\n");
11102 return -EINVAL;
11103 }
11104
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011105 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011106 pr_debug("Wifi turning off from UI\n");
11107 goto exit;
11108 }
11109
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011110 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011111 pr_err("Invalid value received from framework");
11112 goto exit;
11113 }
11114
11115 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011116 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011117 rc = wait_for_completion_timeout(&wlan_start_comp,
11118 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11119 if (!rc) {
11120 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11121 ret = -EINVAL;
11122 hdd_start_complete(ret);
11123 return ret;
11124 }
11125
11126 hdd_start_complete(0);
11127 }
11128
11129exit:
11130 return count;
11131}
11132
11133
11134const struct file_operations wlan_hdd_state_fops = {
11135 .owner = THIS_MODULE,
11136 .open = wlan_hdd_state_ctrl_param_open,
11137 .write = wlan_hdd_state_ctrl_param_write,
11138};
11139
11140static int wlan_hdd_state_ctrl_param_create(void)
11141{
11142 unsigned int wlan_hdd_state_major = 0;
11143 int ret;
11144 struct device *dev;
11145
11146 device = MKDEV(wlan_hdd_state_major, 0);
11147
11148 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11149 if (ret) {
11150 pr_err("Failed to register qcwlanstate");
11151 goto dev_alloc_err;
11152 }
11153 wlan_hdd_state_major = MAJOR(device);
11154
11155 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11156 if (IS_ERR(class)) {
11157 pr_err("wlan_hdd_state class_create error");
11158 goto class_err;
11159 }
11160
11161 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11162 if (IS_ERR(dev)) {
11163 pr_err("wlan_hdd_statedevice_create error");
11164 goto err_class_destroy;
11165 }
11166
11167 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11168 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11169 if (ret) {
11170 pr_err("Failed to add cdev error");
11171 goto cdev_add_err;
11172 }
11173
11174 pr_info("wlan_hdd_state %s major(%d) initialized",
11175 WLAN_MODULE_NAME, wlan_hdd_state_major);
11176
11177 return 0;
11178
11179cdev_add_err:
11180 device_destroy(class, device);
11181err_class_destroy:
11182 class_destroy(class);
11183class_err:
11184 unregister_chrdev_region(device, dev_num);
11185dev_alloc_err:
11186 return -ENODEV;
11187}
11188
11189static void wlan_hdd_state_ctrl_param_destroy(void)
11190{
11191 cdev_del(&wlan_hdd_state_cdev);
11192 device_destroy(class, device);
11193 class_destroy(class);
11194 unregister_chrdev_region(device, dev_num);
11195
11196 pr_info("Device node unregistered");
11197}
11198
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011199/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011200 * component_init - API to init cld component's
11201 *
11202 * Return: None
11203 */
11204static void component_init(void)
11205{
11206 pmo_init();
11207}
11208
11209/**
11210 * component_deinit - API to deinit cld component's
11211 *
11212 * Return: None
11213 */
11214static void component_deinit(void)
11215{
11216 pmo_deinit();
11217}
11218
11219/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011220 * __hdd_module_init - Module init helper
11221 *
11222 * Module init helper function used by both module and static driver.
11223 *
11224 * Return: 0 for success, errno on failure
11225 */
11226static int __hdd_module_init(void)
11227{
11228 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011229
Dustin Brownab482ac2017-06-09 17:00:44 -070011230 pr_err("%s: Loading driver v%s (%s)%s\n",
11231 WLAN_MODULE_NAME,
11232 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011233 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011234 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011235
Sachin Ahujadddd2632017-03-07 19:07:24 +053011236 ret = wlan_hdd_state_ctrl_param_create();
11237 if (ret) {
11238 pr_err("wlan_hdd_state_create:%x\n", ret);
11239 goto err_dev_state;
11240 }
11241
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011242 pld_init();
11243
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011244 ret = hdd_init();
11245 if (ret) {
11246 pr_err("hdd_init failed %x\n", ret);
11247 goto err_hdd_init;
11248 }
11249
Rajeev Kumar97767a02016-11-30 11:20:40 -080011250 dispatcher_init();
11251
Mukul Sharmad75a6672017-06-22 15:40:53 +053011252 /* Ensure to call post objmgr init */
11253 component_init();
11254
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011255 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011256
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011257 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011258
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011259 ret = wlan_hdd_register_driver();
11260 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011261 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11262 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011263 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011264 }
11265
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011266 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011267
11268 return 0;
11269out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011270 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011271 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011272 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011273
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011274err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011275 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011276 wlan_hdd_state_ctrl_param_destroy();
11277err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011278 return ret;
11279}
11280
11281/**
11282 * __hdd_module_exit - Module exit helper
11283 *
11284 * Module exit helper function used by both module and static driver.
11285 */
11286static void __hdd_module_exit(void)
11287{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011288
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011289 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11290 QWLAN_VERSIONSTR);
11291
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011292 hdd_wait_for_recovery_completion();
11293
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011294 wlan_hdd_unregister_driver();
11295
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011296 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011297
Mukul Sharmad75a6672017-06-22 15:40:53 +053011298 /* Ensure to call prior to objmgr deinit */
11299 component_deinit();
11300
Rajeev Kumar97767a02016-11-30 11:20:40 -080011301 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011302 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011303 pld_deinit();
11304
Sachin Ahujadddd2632017-03-07 19:07:24 +053011305 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011306}
11307
Arun Khandavallifae92942016-08-01 13:31:08 +053011308#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011309/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011310 * wlan_boot_cb() - Wlan boot callback
11311 * @kobj: object whose directory we're creating the link in.
11312 * @attr: attribute the user is interacting with
11313 * @buff: the buffer containing the user data
11314 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011315 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011316 * This callback is invoked when the fs is ready to start the
11317 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011318 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011319 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011320 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011321static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011322 struct kobj_attribute *attr,
11323 const char *buf,
11324 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011325{
Arun Khandavallifae92942016-08-01 13:31:08 +053011326
Arun Khandavallifae92942016-08-01 13:31:08 +053011327 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011328 pr_err("%s: wlan driver already initialized\n", __func__);
11329 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011330 }
11331
Arun Khandavallifae92942016-08-01 13:31:08 +053011332 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011333 pr_err("%s: wlan driver initialization failed\n", __func__);
11334 return -EIO;
11335 }
11336
11337 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011338
11339 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011340}
Arun Khandavallifae92942016-08-01 13:31:08 +053011341
11342/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011343 * hdd_sysfs_cleanup() - cleanup sysfs
11344 *
11345 * Return: None
11346 *
11347 */
11348static void hdd_sysfs_cleanup(void)
11349{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011350 /* remove from group */
11351 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11352 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11353 wlan_loader->attr_group);
11354
11355 /* unlink the object from parent */
11356 kobject_del(wlan_loader->boot_wlan_obj);
11357
11358 /* free the object */
11359 kobject_put(wlan_loader->boot_wlan_obj);
11360
11361 kfree(wlan_loader->attr_group);
11362 kfree(wlan_loader);
11363
11364 wlan_loader = NULL;
11365}
11366
11367/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011368 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11369 * ready
11370 *
11371 * This is creates the syfs entry boot_wlan. Which shall be invoked
11372 * when the filesystem is ready.
11373 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011374 * QDF API cannot be used here since this function is called even before
11375 * initializing WLAN driver.
11376 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011377 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011378 */
11379static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011380{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011381 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011382
11383 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011384 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011385 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011386
11387 wlan_loader->boot_wlan_obj = NULL;
11388 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11389 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011390 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011391 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011392
11393 wlan_loader->loaded_state = 0;
11394 wlan_loader->attr_group->attrs = attrs;
11395
11396 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11397 kernel_kobj);
11398 if (!wlan_loader->boot_wlan_obj) {
11399 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011400 goto error_return;
11401 }
11402
11403 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11404 wlan_loader->attr_group);
11405 if (ret) {
11406 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11407 goto error_return;
11408 }
11409
11410 return 0;
11411
11412error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011413 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011414
11415 return ret;
11416}
11417
11418/**
11419 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11420 *
11421 * Return: 0 on success or errno on failure
11422 */
11423static int wlan_deinit_sysfs(void)
11424{
Arun Khandavallifae92942016-08-01 13:31:08 +053011425 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011426 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011427 return -EINVAL;
11428 }
11429
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011430 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011431 return 0;
11432}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011433
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011434#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011435
11436#ifdef MODULE
11437/**
11438 * __hdd_module_init - Module init helper
11439 *
11440 * Module init helper function used by both module and static driver.
11441 *
11442 * Return: 0 for success, errno on failure
11443 */
11444static int hdd_module_init(void)
11445{
Arun Khandavallifae92942016-08-01 13:31:08 +053011446 if (__hdd_module_init()) {
11447 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011448 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011449 }
11450
Dustin Brownab482ac2017-06-09 17:00:44 -070011451 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011452}
11453#else
11454static int __init hdd_module_init(void)
11455{
11456 int ret = -EINVAL;
11457
11458 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011459 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011460 pr_err("Failed to create sysfs entry for loading wlan");
11461
11462 return ret;
11463}
11464#endif
11465
11466
11467#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011468/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011469 * hdd_module_exit() - Exit function
11470 *
11471 * This is the driver exit point (invoked when module is unloaded using rmmod)
11472 *
11473 * Return: None
11474 */
11475static void __exit hdd_module_exit(void)
11476{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011477 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011478}
Arun Khandavallifae92942016-08-01 13:31:08 +053011479#else
11480static void __exit hdd_module_exit(void)
11481{
11482 __hdd_module_exit();
11483 wlan_deinit_sysfs();
11484}
11485#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011486
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011487static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11488{
11489 return param_set_copystring(kmessage, kp);
11490}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011491
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011492/**
11493 * is_con_mode_valid() check con mode is valid or not
11494 * @mode: global con mode
11495 *
11496 * Return: TRUE on success FALSE on failure
11497 */
11498static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11499{
11500 switch (mode) {
11501 case QDF_GLOBAL_MONITOR_MODE:
11502 case QDF_GLOBAL_FTM_MODE:
11503 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011504 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011505 return true;
11506 default:
11507 return false;
11508 }
11509}
11510
11511/**
11512 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11513 * @mode: global con mode
11514 *
11515 * Return: adapter mode
11516 */
11517static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11518 enum tQDF_GLOBAL_CON_MODE mode)
11519{
11520
11521 switch (mode) {
11522 case QDF_GLOBAL_MISSION_MODE:
11523 return QDF_STA_MODE;
11524 case QDF_GLOBAL_MONITOR_MODE:
11525 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011526 case QDF_GLOBAL_EPPING_MODE:
11527 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011528 case QDF_GLOBAL_FTM_MODE:
11529 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011530 case QDF_GLOBAL_QVIT_MODE:
11531 return QDF_QVIT_MODE;
11532 default:
11533 return QDF_MAX_NO_OF_MODE;
11534 }
11535}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011536
Dustin Brown27cd9942017-09-27 16:11:44 -070011537static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11538 enum tQDF_GLOBAL_CON_MODE curr_mode)
11539{
11540 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11541 return;
11542
11543 switch (curr_mode) {
11544 case QDF_GLOBAL_MISSION_MODE:
11545 case QDF_GLOBAL_MONITOR_MODE:
11546 case QDF_GLOBAL_FTM_MODE:
11547 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11548 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11549
11550 /* re-use the existing session */
11551 hdd_stop_all_adapters(hdd_ctx, false);
11552 break;
11553 default:
11554 break;
11555 }
11556}
11557
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011558static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011559 enum tQDF_GLOBAL_CON_MODE curr_mode)
11560{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011561 int driver_status;
11562
11563 driver_status = hdd_ctx->driver_status;
11564
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011565 switch (curr_mode) {
11566 case QDF_GLOBAL_MISSION_MODE:
11567 case QDF_GLOBAL_MONITOR_MODE:
11568 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011569 hdd_deinit_all_adapters(hdd_ctx, false);
11570 hdd_close_all_adapters(hdd_ctx, false);
11571 break;
11572 case QDF_GLOBAL_EPPING_MODE:
11573 epping_disable();
11574 epping_close();
11575 break;
11576 default:
11577 return;
11578 }
11579}
11580
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011581static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011582 enum tQDF_GLOBAL_CON_MODE mode)
11583{
Jeff Johnson9d295242017-08-29 14:39:48 -070011584 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011585 int ret = 0;
11586 bool rtnl_held;
11587 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11588 QDF_STATUS status;
11589
11590 if (!qdf_dev) {
11591 hdd_err("qdf device context is Null return!");
11592 return -EINVAL;
11593 }
11594
11595 rtnl_held = hdd_hold_rtnl_lock();
11596 switch (mode) {
11597 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011598 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11599 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011600 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011601 break;
11602 case QDF_GLOBAL_FTM_MODE:
11603 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11604 wlan_hdd_get_intf_addr(hdd_ctx),
11605 NET_NAME_UNKNOWN, rtnl_held);
11606 if (adapter == NULL)
11607 ret = -EINVAL;
11608 break;
11609 case QDF_GLOBAL_MONITOR_MODE:
11610 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11611 wlan_hdd_get_intf_addr(hdd_ctx),
11612 NET_NAME_UNKNOWN, rtnl_held);
11613 if (adapter == NULL)
11614 ret = -EINVAL;
11615 break;
11616 case QDF_GLOBAL_EPPING_MODE:
11617 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011618 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011619 hdd_err("Failed to open in eeping mode: %d", status);
11620 ret = -EINVAL;
11621 break;
11622 }
11623 ret = epping_enable(qdf_dev->dev);
11624 if (ret) {
11625 hdd_err("Failed to enable in epping mode : %d", ret);
11626 epping_close();
11627 }
11628 break;
11629 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011630 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011631 ret = -ENOTSUPP;
11632 break;
11633 }
11634 hdd_release_rtnl_lock();
11635 rtnl_held = false;
11636 return ret;
11637}
11638
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011639/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011640 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011641 * @kmessage: con mode name on which driver to be bring up
11642 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011643 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011644 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011645 * This function is invoked when user updates con mode using sys entry,
11646 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011647 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011648 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011649 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011650static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011651 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011652{
11653 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011654 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011655 enum tQDF_GLOBAL_CON_MODE curr_mode;
11656 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011657
Dustin Brownab6029b2017-05-24 13:04:19 -070011658 hdd_info("con_mode handler: %s", kmessage);
11659
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011660 ret = wlan_hdd_validate_context(hdd_ctx);
11661 if (ret)
11662 return ret;
11663
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011664 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011665
11666 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011667
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011668 if (!(is_con_mode_valid(con_mode))) {
11669 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011670 ret = -EINVAL;
11671 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011672 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011673
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011674 curr_mode = hdd_get_conparam();
11675 if (curr_mode == con_mode) {
11676 hdd_err("curr mode: %d is same as user triggered mode %d",
11677 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011678 ret = 0;
11679 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011680 }
11681
Dustin Brown27cd9942017-09-27 16:11:44 -070011682 /* ensure adapters are stopped */
11683 hdd_stop_present_mode(hdd_ctx, curr_mode);
11684
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011685 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011686 if (ret) {
11687 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011688 goto reset_flags;
11689 }
11690
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011691 /* Cleanup present mode before switching to new mode */
11692 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11693
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011694 hdd_set_conparam(con_mode);
11695
11696 /* Register for new con_mode & then kick_start modules again */
11697 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11698 if (ret) {
11699 hdd_err("Failed to register for new mode");
11700 goto reset_flags;
11701 }
11702
11703 adapter_mode = hdd_get_adpter_mode(con_mode);
11704 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11705 hdd_err("invalid adapter");
11706 ret = -EINVAL;
11707 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011708 }
11709
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011710 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011711 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011712 hdd_err("Failed to get adapter:%d", adapter_mode);
11713 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011714 }
11715
11716 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11717 if (ret) {
11718 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011719 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011720 }
11721
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011722 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011723 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011724 if (hdd_start_adapter(adapter)) {
11725 hdd_err("Failed to start %s adapter", kmessage);
11726 ret = -EINVAL;
11727 goto reset_flags;
11728 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011729 }
11730
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011731 hdd_info("Mode successfully changed to %s", kmessage);
11732 ret = 0;
11733
11734reset_flags:
11735 cds_set_load_in_progress(false);
11736 return ret;
11737}
11738
11739
11740static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11741{
11742 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011743 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011744
11745 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11746 ret = wlan_hdd_validate_context(hdd_ctx);
11747 if (ret)
11748 return ret;
11749
11750 cds_ssr_protect(__func__);
11751 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11752 cds_ssr_unprotect(__func__);
11753
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011754 return ret;
11755}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011756
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011757static int con_mode_handler_ftm(const char *kmessage,
11758 struct kernel_param *kp)
11759{
11760 int ret;
11761
11762 ret = param_set_int(kmessage, kp);
11763
11764 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11765 pr_err("Only FTM mode supported!");
11766 return -ENOTSUPP;
11767 }
11768
11769 hdd_set_conparam(con_mode_ftm);
11770 con_mode = con_mode_ftm;
11771
11772 return ret;
11773}
11774
Ravi Joshia307f632017-07-17 23:41:41 -070011775static int con_mode_handler_monitor(const char *kmessage,
11776 struct kernel_param *kp)
11777{
11778 int ret;
11779
11780 ret = param_set_int(kmessage, kp);
11781
11782 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11783 pr_err("Only Monitor mode supported!");
11784 return -ENOTSUPP;
11785 }
11786
11787 hdd_set_conparam(con_mode_monitor);
11788 con_mode = con_mode_monitor;
11789
11790 return ret;
11791}
11792
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011793/**
11794 * hdd_get_conparam() - driver exit point
11795 *
11796 * This is the driver exit point (invoked when module is unloaded using rmmod)
11797 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011798 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011799 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011800enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011801{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011802 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011803}
11804
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011805void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011806{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011807 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011808}
11809
Komal Seelamc11bb222016-01-27 18:57:10 +053011810/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011811 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11812 * @hdd_ctx: HDD context
11813 *
11814 * Cleans up the pre cac interface, if it exists
11815 *
11816 * Return: None
11817 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011818void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011819{
11820 uint8_t session_id;
11821 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011822 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011823
11824 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11825 if (QDF_IS_STATUS_ERROR(status)) {
11826 hdd_err("failed to get pre cac vdev id");
11827 return;
11828 }
11829
11830 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11831 if (!precac_adapter) {
11832 hdd_err("invalid pre cac adapater");
11833 return;
11834 }
11835
11836 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11837 wlan_hdd_sap_pre_cac_failure,
11838 (void *)precac_adapter);
11839 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11840
11841}
11842
11843/**
Komal Seelamec702b02016-02-24 18:42:16 +053011844 * hdd_update_ol_config - API to update ol configuration parameters
11845 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011846 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011847 * Return: void
11848 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011849static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011850{
Komal Seelamec702b02016-02-24 18:42:16 +053011851 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011852 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011853
Komal Seelamec702b02016-02-24 18:42:16 +053011854 if (!ol_ctx)
11855 return;
11856
11857 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11858 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11859 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11860 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011861 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011862
11863 ol_init_ini_config(ol_ctx, &cfg);
11864}
11865
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011866#ifdef FEATURE_RUNTIME_PM
11867/**
11868 * hdd_populate_runtime_cfg() - populate runtime configuration
11869 * @hdd_ctx: hdd context
11870 * @cfg: pointer to the configuration memory being populated
11871 *
11872 * Return: void
11873 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011874static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011875 struct hif_config_info *cfg)
11876{
11877 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11878 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11879}
11880#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011881static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011882 struct hif_config_info *cfg)
11883{
11884}
11885#endif
11886
Komal Seelamec702b02016-02-24 18:42:16 +053011887/**
11888 * hdd_update_hif_config - API to update HIF configuration parameters
11889 * @hdd_ctx: HDD Context
11890 *
11891 * Return: void
11892 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011893static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011894{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011895 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011896 struct hif_config_info cfg;
11897
11898 if (!scn)
11899 return;
11900
11901 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011902 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011903 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011904
11905 if (hdd_ctx->config->prevent_link_down)
11906 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011907}
11908
11909/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011910 * hdd_update_dp_config() - Propagate config parameters to Lithium
11911 * datapath
11912 * @hdd_ctx: HDD Context
11913 *
11914 * Return: 0 for success/errno for failure
11915 */
11916static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
11917{
11918 struct cdp_config_params params;
11919 QDF_STATUS status;
11920
11921 params.tso_enable = hdd_ctx->config->tso_enable;
11922 params.lro_enable = hdd_ctx->config->lro_enable;
11923#ifdef QCA_LL_TX_FLOW_CONTROL_V2
11924 params.tx_flow_stop_queue_threshold =
11925 hdd_ctx->config->TxFlowStopQueueThreshold;
11926 params.tx_flow_start_queue_offset =
11927 hdd_ctx->config->TxFlowStartQueueOffset;
11928#endif
11929 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
11930 params.napi_enable = hdd_ctx->napi_enable;
11931 params.tcp_udp_checksumoffload =
11932 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
11933
11934 status = cdp_update_config_parameters(
11935 cds_get_context(QDF_MODULE_ID_SOC),
11936 &params);
11937 if (status) {
11938 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
11939 "%s: Failed to attach config parameters", __func__);
11940 return status;
11941 }
11942
11943 return 0;
11944}
11945
11946/**
Komal Seelamec702b02016-02-24 18:42:16 +053011947 * hdd_update_config() - Initialize driver per module ini parameters
11948 * @hdd_ctx: HDD Context
11949 *
11950 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011951 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011952 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011953int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011954{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011955 int ret;
11956
Komal Seelamec702b02016-02-24 18:42:16 +053011957 hdd_update_ol_config(hdd_ctx);
11958 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011959 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11960 ret = hdd_update_cds_config_ftm(hdd_ctx);
11961 else
11962 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011963 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011964
11965 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011966}
11967
Mukul Sharma9d797a02017-01-05 20:26:03 +053011968#ifdef FEATURE_WLAN_RA_FILTERING
11969/**
11970 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11971 * @psoc_cfg: pmo psoc Configuration
11972 * @hdd_ctx: Pointer to hdd context
11973 *
11974 * Return: none
11975 */
11976static inline void hdd_ra_populate_pmo_config(
11977 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011978 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011979{
11980 psoc_cfg->ra_ratelimit_interval =
11981 hdd_ctx->config->RArateLimitInterval;
11982 psoc_cfg->ra_ratelimit_enable =
11983 hdd_ctx->config->IsRArateLimitEnabled;
11984}
11985#else
11986static inline void hdd_ra_populate_pmo_config(
11987 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011988 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011989{
11990}
11991#endif
11992/**
11993 * hdd_update_pmo_config - API to update pmo configuration parameters
11994 * @hdd_ctx: HDD context
11995 *
11996 * Return: void
11997 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011998static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011999{
12000 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12001 struct pmo_psoc_cfg psoc_cfg;
12002 QDF_STATUS status;
12003
12004 /*
12005 * Value of hdd_ctx->wowEnable can be,
12006 * 0 - Disable both magic pattern match and pattern byte match.
12007 * 1 - Enable magic pattern match on all interfaces.
12008 * 2 - Enable pattern byte match on all interfaces.
12009 * 3 - Enable both magic patter and pattern byte match on
12010 * all interfaces.
12011 */
12012 psoc_cfg.magic_ptrn_enable =
12013 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12014 psoc_cfg.ptrn_match_enable_all_vdev =
12015 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012016 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12017 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012018 psoc_cfg.bpf_enable =
12019 hdd_ctx->config->bpf_packet_filter_enable;
12020 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012021 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012022 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12023 if (hdd_ctx->config->fhostNSOffload)
12024 psoc_cfg.ns_offload_enable_dynamic = true;
12025 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12026 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12027 psoc_cfg.active_mode_offload =
12028 hdd_ctx->config->active_mode_offload;
12029 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
12030 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012031 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12032 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12033 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12034 psoc_cfg.power_save_mode =
12035 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012036 psoc_cfg.auto_power_save_fail_mode =
12037 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012038
12039 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012040 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12041 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012042 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
12043 if (status != QDF_STATUS_SUCCESS) {
12044 hdd_err("failed pmo psoc configuration");
12045 return -EINVAL;
12046 }
12047
12048 return 0;
12049}
12050
Abhishek Singhb20db962017-03-03 21:28:46 +053012051#ifdef FEATURE_WLAN_SCAN_PNO
12052static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12053 struct hdd_config *cfg)
12054{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012055 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12056
Abhishek Singhb20db962017-03-03 21:28:46 +053012057 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12058 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12059 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12060 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12061 pno_cfg->channel_prediction_full_scan =
12062 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012063 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12064 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12065 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12066 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012067}
12068#else
12069static inline void
12070hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012071 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012072{
Abhishek Singhb20db962017-03-03 21:28:46 +053012073}
12074#endif
12075
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012076void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12077 struct hdd_config *cfg)
12078{
12079 uint8_t i = 0;
12080
12081 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12082 if (!ie_whitelist->white_list)
12083 return;
12084
12085 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12086 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12087 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12088 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12089 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12090 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12091 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12092 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12093
12094 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12095 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12096 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12097}
12098
Abhishek Singh257a9482017-03-06 16:52:39 +053012099/**
12100 * hdd_update_scan_config - API to update scan configuration parameters
12101 * @hdd_ctx: HDD context
12102 *
12103 * Return: 0 if success else err
12104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012105static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012106{
12107 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12108 struct scan_user_cfg scan_cfg;
12109 struct hdd_config *cfg = hdd_ctx->config;
12110 QDF_STATUS status;
12111
12112 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12113 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12114 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12115 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12116 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12117 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12118 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012119 /* convert to ms */
12120 scan_cfg.scan_cache_aging_time =
12121 cfg->scanAgingTimeout * 1000;
12122 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12123 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12124 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12125 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012126 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012127 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012128 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Abhishek Singh257a9482017-03-06 16:52:39 +053012129
Abhishek Singhb20db962017-03-03 21:28:46 +053012130 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012131 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012132
Abhishek Singh257a9482017-03-06 16:52:39 +053012133 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12134 if (status != QDF_STATUS_SUCCESS) {
12135 hdd_err("failed pmo psoc configuration");
12136 return -EINVAL;
12137 }
12138
12139 return 0;
12140}
Abhishek Singh257a9482017-03-06 16:52:39 +053012141
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012142static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012143{
12144 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12145 struct tdls_start_params tdls_cfg;
12146 struct tdls_user_config *config = &tdls_cfg.config;
12147 struct hdd_config *cfg = hdd_ctx->config;
12148 QDF_STATUS status;
12149
12150 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12151 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12152 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12153 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12154 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12155 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12156 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12157 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12158 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12159 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12160 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12161 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12162 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12163 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12164 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12165 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12166 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12167 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12168 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12169 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12170 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12171 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12172 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12173 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12174 (cfg->fEnableTDLSImplicitTrigger ?
12175 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12176 (cfg->fTDLSExternalControl ?
12177 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12178
12179 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12180 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12181 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12182 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012183 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012184 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012185 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12186 tdls_cfg.tdls_evt_cb_data = psoc;
12187 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12188 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12189 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012190 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12191 tdls_cfg.tdls_wmm_cb_data = psoc;
12192 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12193 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012194 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012195
12196 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12197 if (status != QDF_STATUS_SUCCESS) {
12198 hdd_err("failed pmo psoc configuration");
12199 return -EINVAL;
12200 }
12201
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012202 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012203 /* enable napier specific tdls data path */
12204 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012205
Frank Liud4b2fa02017-03-29 11:46:48 +080012206 return 0;
12207}
Frank Liud4b2fa02017-03-29 11:46:48 +080012208
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012209int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012210{
12211 int ret;
12212
12213 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012214 if (ret)
12215 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012216
Abhishek Singh257a9482017-03-06 16:52:39 +053012217 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012218 if (ret)
12219 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012220
Frank Liud4b2fa02017-03-29 11:46:48 +080012221 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012222 if (ret)
12223 return ret;
12224
12225 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012226
12227 return ret;
12228}
12229
Agrawal Ashish65634612016-08-18 13:24:32 +053012230/**
12231 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12232 * @mode : cfg80211 DFS mode
12233 *
12234 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12235 */
12236enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12237{
12238 switch (mode) {
12239 case DFS_MODE_ENABLE:
12240 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012241 case DFS_MODE_DISABLE:
12242 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012243 case DFS_MODE_DEPRIORITIZE:
12244 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012245 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012246 hdd_debug("ACS dfs mode is NONE");
12247 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012248 }
12249}
12250
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012251/**
12252 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12253 * @hddctx: pointer to hdd context
12254 * @set_value: enable/disable
12255 *
12256 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12257 * Host(even though it is duplicate). When Host send vendor command
12258 * disable,FW doesn't perform any action. Whenever any change in
12259 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12260 *
12261 * return - 0 on success, appropriate error values on failure.
12262 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012263int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012264{
12265 QDF_STATUS status;
12266
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012267 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012268 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012269
12270 if (!hddctx->config->goptimize_chan_avoid_event) {
12271 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12272 return -EINVAL;
12273 }
12274
12275 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12276 if (!QDF_IS_STATUS_SUCCESS(status)) {
12277 hdd_err("Failed to send chan avoid command to SME");
12278 return -EINVAL;
12279 }
12280 return 0;
12281}
Agrawal Ashish65634612016-08-18 13:24:32 +053012282
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012283/**
12284 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12285 * @value: value to set
12286 *
12287 * This function will set the passed value to roaming in progress flag.
12288 *
12289 * Return: None
12290 */
12291void hdd_set_roaming_in_progress(bool value)
12292{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012293 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012294
12295 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12296 if (!hdd_ctx) {
12297 hdd_err("HDD context is NULL");
12298 return;
12299 }
12300
12301 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012302 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012303}
12304
12305/**
12306 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012307 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012308 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012309 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012310 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012311bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012312{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012313 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012314 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012315
12316 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12317 if (!hdd_ctx) {
12318 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012319 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012320 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012321 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12322 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012323 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12324 hdd_ctx->roaming_in_progress);
12325
12326 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012327}
12328
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012329/**
12330 * hdd_is_connection_in_progress() - check if connection is in
12331 * progress
12332 * @session_id: session id
12333 * @reason: scan reject reason
12334 *
12335 * Go through each adapter and check if Connection is in progress
12336 *
12337 * Return: true if connection is in progress else false
12338 */
12339bool hdd_is_connection_in_progress(uint8_t *session_id,
12340 enum scan_reject_states *reason)
12341{
12342 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012343 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012344 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012345 QDF_STATUS status = 0;
12346 uint8_t sta_id = 0;
12347 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012348 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012349
12350 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12351 if (!hdd_ctx) {
12352 hdd_err("HDD context is NULL");
12353 return false;
12354 }
12355
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012356 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12357 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012358 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012359 if (!adapter)
12360 goto end;
12361
12362 hdd_info("Adapter with device mode %s(%d) exists",
12363 hdd_device_mode_to_string(adapter->device_mode),
12364 adapter->device_mode);
12365 if (((QDF_STA_MODE == adapter->device_mode)
12366 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12367 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12368 && (eConnectionState_Connecting ==
12369 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12370 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012371 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012372 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12373 adapter->sessionId);
12374 if (session_id && reason) {
12375 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012376 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012377 }
12378 return true;
12379 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012380 /*
12381 * sme_neighbor_middle_of_roaming is for LFR2
12382 * hdd_is_roaming_in_progress is for LFR3
12383 */
12384 if (((QDF_STA_MODE == adapter->device_mode) &&
12385 sme_neighbor_middle_of_roaming(
12386 WLAN_HDD_GET_HAL_CTX(adapter),
12387 adapter->sessionId)) ||
12388 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012389 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012390 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12391 adapter->sessionId);
12392 if (session_id && reason) {
12393 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012394 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012395 }
12396 return true;
12397 }
12398 if ((QDF_STA_MODE == adapter->device_mode) ||
12399 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12400 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12401 hdd_sta_ctx =
12402 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12403 if ((eConnectionState_Associated ==
12404 hdd_sta_ctx->conn_info.connState)
12405 && (false ==
12406 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12407 sta_mac = (uint8_t *)
12408 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012409 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012410 " is in middle of WPS/EAPOL exchange.",
12411 MAC_ADDR_ARRAY(sta_mac));
12412 if (session_id && reason) {
12413 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012414 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012415 }
12416 return true;
12417 }
12418 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12419 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12420 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12421 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012422 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012423 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012424 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012425 continue;
12426
12427 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012428 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070012429 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012430 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012431 " of SAP/GO is in middle of WPS/EAPOL exchange",
12432 MAC_ADDR_ARRAY(sta_mac));
12433 if (session_id && reason) {
12434 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012435 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012436 }
12437 return true;
12438 }
12439 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012440 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012441 return true;
12442 }
12443 }
12444end:
12445 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12446 adapter_node = next;
12447 }
12448 return false;
12449}
12450
12451/**
12452 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012453 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012454 *
12455 * Return: None
12456 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012457void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012458{
Jeff Johnson87251032017-08-29 13:31:11 -070012459 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012460 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012461 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012462 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012463 tsap_Config_t *sap_config;
12464 void *sap_ctx;
12465
12466 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12467 sap_config = &hdd_ap_ctx->sapConfig;
12468 sap_ctx = hdd_ap_ctx->sapContext;
12469
12470 mutex_lock(&hdd_ctx->sap_lock);
12471 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12472 wlan_hdd_del_station(ap_adapter);
12473 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12474 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12475 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12476 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12477 qdf_status =
12478 qdf_wait_single_event(&hostapd_state->
12479 qdf_stop_bss_event,
12480 SME_CMD_TIMEOUT_VALUE);
12481
12482 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012483 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012484 goto end;
12485 }
12486 }
12487 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012488 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012489 ap_adapter->device_mode, ap_adapter->sessionId);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012490 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012491
12492 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012493 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012494 wlansap_reset_sap_config_add_ie(sap_config,
12495 eUPDATE_IE_ALL);
12496 goto end;
12497 }
12498
12499 qdf_event_reset(&hostapd_state->qdf_event);
12500 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12501 sap_config,
12502 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012503 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012504 wlansap_reset_sap_config_add_ie(sap_config,
12505 eUPDATE_IE_ALL);
12506 goto end;
12507 }
12508
Jeff Johnson6867ec32017-09-29 20:30:20 -070012509 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012510 qdf_status =
12511 qdf_wait_single_event(&hostapd_state->qdf_event,
12512 SME_CMD_TIMEOUT_VALUE);
12513 wlansap_reset_sap_config_add_ie(sap_config,
12514 eUPDATE_IE_ALL);
12515 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012516 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012517 goto end;
12518 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012519 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012520 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12521 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012522 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12523 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012524 ap_adapter->sessionId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012525 }
12526end:
12527 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012528}
12529
12530/**
12531 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12532 * with non dfs acs
12533 *
12534 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12535 *
12536 * Return: None
12537 */
12538void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12539{
Jeff Johnson9d295242017-08-29 14:39:48 -070012540 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012541 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012542 cds_context_type *cds_ctx;
12543
12544 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12545 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012546 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012547 return;
12548 }
12549
12550 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12551 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012552 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012553 return;
12554 }
12555
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012556 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12557 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012558 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012559 return;
12560 }
12561
12562 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012563 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12564 &ap_adapter->event_flags) &&
12565 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12566 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012567
Jeff Johnson6867ec32017-09-29 20:30:20 -070012568 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012569 ap_adapter->sessionCtx.ap.sapConfig.channel =
12570 AUTO_CHANNEL_SELECT;
12571 ap_adapter->sessionCtx.ap.sapConfig.
12572 acs_cfg.acs_mode = true;
12573
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012574 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012575 }
12576}
12577
12578/**
12579 * hdd_set_connection_in_progress() - to set the connection in
12580 * progress flag
12581 * @value: value to set
12582 *
12583 * This function will set the passed value to connection in progress flag.
12584 * If value is previously being set to true then no need to set it again.
12585 *
12586 * Return: true if value is being set correctly and false otherwise.
12587 */
12588bool hdd_set_connection_in_progress(bool value)
12589{
12590 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012591 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012592
12593 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12594 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012595 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012596 return false;
12597 }
12598
12599 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12600 /*
12601 * if the value is set to true previously and if someone is
12602 * trying to make it true again then it could be some race
12603 * condition being triggered. Avoid this situation by returning
12604 * false
12605 */
12606 if (hdd_ctx->connection_in_progress && value)
12607 status = false;
12608 else
12609 hdd_ctx->connection_in_progress = value;
12610 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12611 return status;
12612}
12613
Jeff Johnson9d295242017-08-29 14:39:48 -070012614int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012615{
12616 if (!adapter) {
12617 hdd_err("Invalid adapter");
12618 return -EINVAL;
12619 }
12620 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012621 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012622 WMA_VDEV_MCC_SET_TIME_QUOTA,
12623 set_value, VDEV_CMD);
12624 return 0;
12625
12626}
12627
Jeff Johnson9d295242017-08-29 14:39:48 -070012628int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012629{
12630 if (!adapter) {
12631 hdd_err("Invalid adapter");
12632 return -EINVAL;
12633 }
12634
12635 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012636 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012637 WMA_VDEV_MCC_SET_TIME_LATENCY,
12638 set_value, VDEV_CMD);
12639 return 0;
12640}
12641
Jeff Johnson9d295242017-08-29 14:39:48 -070012642struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012643 *psoc, uint8_t vdev_id)
12644{
Jeff Johnson9d295242017-08-29 14:39:48 -070012645 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012646 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012647
12648 /*
12649 * Currently PSOC is not being used. But this logic will
12650 * change once we have the converged implementation of
12651 * HDD context per PSOC in place. This would break if
12652 * multiple vdev objects reuse the vdev id.
12653 */
12654 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12655 if (!adapter)
12656 hdd_err("Get adapter by vdev id failed");
12657
12658 return adapter;
12659}
12660
Jeff Johnson9d295242017-08-29 14:39:48 -070012661int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012662 int8_t *rssi, int8_t *snr)
12663{
12664 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012665 struct hdd_wext_state *wext_state =
12666 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012667 tCsrRoamProfile *profile = &wext_state->roamProfile;
12668
12669 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12670 profile, bssid, rssi, snr);
12671 if (QDF_STATUS_SUCCESS != status) {
12672 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12673 return -EINVAL;
12674 }
12675
12676 return 0;
12677}
12678
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012679/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012680 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12681 * @adapter - HDD adapter
12682 * @tos - type of service
12683 * @status - status of the traffic
12684 *
12685 * Return: 0 on success and non zero value on failure
12686 */
12687
12688int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12689 bool is_tos_active)
12690{
12691 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012692 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012693 uint32_t max_off_chan_time = 0;
12694 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012695 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012696 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012697
12698 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12699 ret = wlan_hdd_validate_context(hdd_ctx);
12700
12701 if (ret < 0) {
12702 hdd_err("failed to set limit off chan params");
12703 return ret;
12704 }
12705
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012706 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12707
12708 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012709 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012710 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012711 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012712
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012713 if (adapter->active_ac) {
12714 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012715 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012716 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12717 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12718 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012719 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012720 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012721 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12722 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12723 PM_LATENCY);
12724 } else {
12725 /*ignore this command if only BE/BK is active */
12726 is_tos_active = false;
12727 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12728 hdd_ctx->config->conc_system_pref);
12729 }
12730 } else {
12731 /* No active tos */
12732 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12733 hdd_ctx->config->conc_system_pref);
12734 }
12735
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012736 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12737 is_tos_active, max_off_chan_time,
12738 hdd_ctx->config->nRestTimeConc, true);
12739 if (!QDF_IS_STATUS_SUCCESS(status)) {
12740 hdd_err("failed to set limit off chan params");
12741 ret = -EINVAL;
12742 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012743
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012744 return ret;
12745}
12746
12747/**
12748 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
12749 * @adapter - HDD adapter
12750 *
12751 * Return: 0 on success and non zero value on failure
12752 */
12753int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
12754{
12755 struct hdd_context *hdd_ctx;
12756 int ret;
12757 QDF_STATUS status;
12758 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
12759
12760 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12761 ret = wlan_hdd_validate_context(hdd_ctx);
12762 if (ret < 0)
12763 return ret;
12764
12765 /* set the system preferece to default */
12766 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12767 hdd_ctx->config->conc_system_pref);
12768
12769 /* clear the bitmap */
12770 adapter->active_ac = 0;
12771
12772 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
12773 adapter->sessionId, adapter->active_ac);
12774
12775 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12776 false, 0, 0, false);
12777 if (!QDF_IS_STATUS_SUCCESS(status)) {
12778 hdd_err("failed to reset limit off chan params");
12779 ret = -EINVAL;
12780 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012781
12782 return ret;
12783}
12784
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012785/**
12786 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12787 * @drv_op: Enum indicating driver op
12788 *
12789 * Return: none
12790 */
12791void hdd_start_driver_ops_timer(int drv_op)
12792{
12793 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12794 switch (drv_op) {
12795 case eHDD_DRV_OP_PROBE:
12796 memcpy(drv_ops_string, "probe", sizeof("probe"));
12797 break;
12798 case eHDD_DRV_OP_REMOVE:
12799 memcpy(drv_ops_string, "remove", sizeof("remove"));
12800 break;
12801 case eHDD_DRV_OP_SHUTDOWN:
12802 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12803 break;
12804 case eHDD_DRV_OP_REINIT:
12805 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12806 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053012807 case eHDD_DRV_OP_IFF_UP:
12808 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
12809 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012810 }
12811
12812 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12813 HDD_OPS_INACTIVITY_TIMEOUT);
12814}
12815
12816/**
12817 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12818 *
12819 * Return: none
12820 */
12821void hdd_stop_driver_ops_timer(void)
12822{
12823 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12824}
12825
12826/**
12827 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12828 * inactivity timer
12829 *
12830 * Return: None
12831 */
12832void hdd_drv_ops_inactivity_handler(void)
12833{
12834 hdd_err("%s: %d Sec timer expired while in .%s",
12835 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12836
12837 /* Driver shutdown is stuck, no recovery possible at this point */
12838 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12839 sizeof("shutdown")))
12840 QDF_BUG(0);
12841
12842 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012843 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012844 else
12845 QDF_BUG(0);
12846}
12847
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012848void hdd_pld_ipa_uc_shutdown_pipes(void)
12849{
12850 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12851
12852 if (!hdd_ctx)
12853 return;
12854
12855 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12856}
12857
Yun Parkff6a16a2017-09-26 16:38:18 -070012858/**
12859 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
12860 * @struct hdd_context *hdd_ctx
12861 * @struct hdd_adapter *padapter
12862 * @bool enble
12863 *
12864 * Return: none
12865 */
12866void hdd_set_rx_mode_rps(bool enable)
12867{
12868 struct cds_config_info *cds_cfg = cds_get_ini_config();
12869 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12870 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
12871
12872 if (adapter && hdd_ctx &&
12873 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
12874 if (enable && !cds_cfg->rps_enabled)
12875 hdd_send_rps_ind(adapter);
12876 else if (!enable && cds_cfg->rps_enabled)
12877 hdd_send_rps_disable_ind(adapter);
12878 }
12879}
12880
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012881/* Register the module init/exit functions */
12882module_init(hdd_module_init);
12883module_exit(hdd_module_exit);
12884
12885MODULE_LICENSE("Dual BSD/GPL");
12886MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12887MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12888
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012889module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12890 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012891
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012892module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12893 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12894
Ravi Joshia307f632017-07-17 23:41:41 -070012895module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12896 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12897
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012898module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12899 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12900
12901module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12902
12903module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12904
12905module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);