blob: 9568bac393a215f271351be6fca0cbd1cd9f9dff [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnsond9f08602016-12-02 11:31:30 -08002 * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_main.c
30 *
31 * WLAN Host Device Driver implementation
32 *
33 */
34
35/* Include Files */
36#include <wlan_hdd_includes.h>
37#include <cds_api.h>
38#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053039#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include <linux/etherdevice.h>
41#include <linux/firmware.h>
42#include <wlan_hdd_tx_rx.h>
43#include <wni_api.h>
44#include <wlan_hdd_cfg.h>
45#include <wlan_ptt_sock_svc.h>
46#include <dbglog_host.h>
47#include <wlan_logging_sock_svc.h>
48#include <wlan_hdd_wowl.h>
49#include <wlan_hdd_misc.h>
50#include <wlan_hdd_wext.h>
51#include "wlan_hdd_trace.h"
52#include "wlan_hdd_ioctl.h"
53#include "wlan_hdd_ftm.h"
54#include "wlan_hdd_power.h"
55#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070056#include "wlan_hdd_scan.h"
Jeff Johnsonce0032c2017-01-20 07:18:27 -080057#include "wlan_hdd_request_manager.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053058#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053059#include "qdf_trace.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070060#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080061#include <cdp_txrx_misc.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062
63#include <net/addrconf.h>
64#include <linux/wireless.h>
65#include <net/cfg80211.h>
66#include <linux/inetdevice.h>
67#include <net/addrconf.h>
68#include "wlan_hdd_cfg80211.h"
69#include "wlan_hdd_ext_scan.h"
70#include "wlan_hdd_p2p.h"
71#include <linux/rtnetlink.h>
72#include "sap_api.h"
73#include <linux/semaphore.h>
74#include <linux/ctype.h>
75#include <linux/compat.h>
76#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077#include <soc/qcom/subsystem_restart.h>
78#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#include <wlan_hdd_hostapd.h>
80#include <wlan_hdd_softap_tx_rx.h>
81#include "cfg_api.h"
82#include "qwlan_version.h"
83#include "wma_types.h"
84#include "wlan_hdd_tdls.h"
85#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053086#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070088#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070089#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080090#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#include "wlan_hdd_nan.h"
92#include "wlan_hdd_debugfs.h"
93#include "wlan_hdd_driver_ops.h"
94#include "epping_main.h"
95#include "wlan_hdd_memdump.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053096#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097
98#include <wlan_hdd_ipa.h>
99#include "hif.h"
100#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800101#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700102#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800103#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530104#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700105#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700106#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530107#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700108#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530109#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800110#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800111#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530112#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800113#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800114#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530115#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530116#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800117#include "os_if_wifi_pos.h"
118#include "wifi_pos_api.h"
119#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800120#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700121#include "os_if_nan.h"
122#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700123#include "wlan_reg_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700124#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530125#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530126#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700127#include <cdp_txrx_cmn_struct.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800128
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530129#ifdef CNSS_GENL
130#include <net/cnss_nl.h>
131#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800132#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800134#ifdef MODULE
135#define WLAN_MODULE_NAME module_name(THIS_MODULE)
136#else
137#define WLAN_MODULE_NAME "wlan"
138#endif
139
140#ifdef TIMER_MANAGER
141#define TIMER_MANAGER_STR " +TIMER_MANAGER"
142#else
143#define TIMER_MANAGER_STR ""
144#endif
145
146#ifdef MEMORY_DEBUG
147#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
148#else
149#define MEMORY_DEBUG_STR ""
150#endif
151
Sachin Ahujadddd2632017-03-07 19:07:24 +0530152int wlan_start_ret_val;
153static DECLARE_COMPLETION(wlan_start_comp);
154static unsigned int dev_num = 1;
155static struct cdev wlan_hdd_state_cdev;
156static struct class *class;
157static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530158#ifndef MODULE
159static struct gwlan_loader *wlan_loader;
160static ssize_t wlan_boot_cb(struct kobject *kobj,
161 struct kobj_attribute *attr,
162 const char *buf, size_t count);
163struct gwlan_loader {
164 bool loaded_state;
165 struct kobject *boot_wlan_obj;
166 struct attribute_group *attr_group;
167};
168
169static struct kobj_attribute wlan_boot_attribute =
170 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
171
172static struct attribute *attrs[] = {
173 &wlan_boot_attribute.attr,
174 NULL,
175};
176
177#define MODULE_INITIALIZED 1
178#endif
179
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530180#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
181#define MAX_OPS_NAME_STRING_SIZE 20
182
183static qdf_timer_t hdd_drv_ops_inactivity_timer;
184static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
185
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800186/* the Android framework expects this param even though we don't use it */
187#define BUF_LEN 20
188static char fwpath_buffer[BUF_LEN];
189static struct kparam_string fwpath = {
190 .string = fwpath_buffer,
191 .maxlen = BUF_LEN,
192};
193
194static char *country_code;
195static int enable_11d = -1;
196static int enable_dfs_chan_scan = -1;
197
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800198/*
199 * spinlock for synchronizing asynchronous request/response
200 * (full description of use in wlan_hdd_main.h)
201 */
202DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530203DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800204
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800205#define WLAN_NLINK_CESIUM 30
206
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530207static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800208
209#define WOW_MAX_FILTER_LISTS 1
210#define WOW_MAX_FILTERS_PER_LIST 4
211#define WOW_MIN_PATTERN_SIZE 6
212#define WOW_MAX_PATTERN_SIZE 64
213
214#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
215static const struct wiphy_wowlan_support wowlan_support_reg_init = {
216 .flags = WIPHY_WOWLAN_ANY |
217 WIPHY_WOWLAN_MAGIC_PKT |
218 WIPHY_WOWLAN_DISCONNECT |
219 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
220 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
221 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
222 WIPHY_WOWLAN_4WAY_HANDSHAKE |
223 WIPHY_WOWLAN_RFKILL_RELEASE,
224 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
225 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
226 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
227};
228#endif
229
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700230static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
231 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
232 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
233 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
234 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
235 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
236 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
237 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
243 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
244 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
245 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
246 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
247 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700265 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700266 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700267 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700268};
269
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530270int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
271 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
272 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
273 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
274 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
275};
276
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800277/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530278struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800279
280struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800281#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700282static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800283#endif
284
Sachin Ahujadddd2632017-03-07 19:07:24 +0530285void hdd_start_complete(int ret)
286{
287 wlan_start_ret_val = ret;
288
289 complete(&wlan_start_comp);
290}
291
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800292/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530293 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700294 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530295 *
296 * Return: none
297 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700298static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530299{
Jeff Johnson9d295242017-08-29 14:39:48 -0700300 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530301 hdd_adapter_list_node_t *adapter_node, *next;
302 QDF_STATUS status = QDF_STATUS_SUCCESS;
303
304 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
305 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -0700306 adapter = adapter_node->adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530307 if (NULL != adapter)
308 hdd_send_rps_ind(adapter);
309 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
310 adapter_node = next;
311 }
312}
313
314/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800315 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
316 * @vdev_id: vdev_id
317 * @action: action type
318 * @reason: reason type
319 *
320 * Return: none
321 */
322void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
323 enum netif_action_type action, enum netif_reason_type reason)
324{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700325 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700326 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800327
328 if (!hdd_ctx) {
329 hdd_err("hdd ctx is NULL");
330 return;
331 }
332 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
333
334 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800335}
336
337/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700338 * Store WLAN driver version and timestamp info in global variables such that
339 * crash debugger can extract them from driver debug symbol and crashdump for
340 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800341 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800342#ifdef BUILD_TAG
343uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
344#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800345uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700346#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800347
348/**
349 * hdd_device_mode_to_string() - return string conversion of device mode
350 * @device_mode: device mode
351 *
352 * This utility function helps log string conversion of device mode.
353 *
354 * Return: string conversion of device mode, if match found;
355 * "Unknown" otherwise.
356 */
357const char *hdd_device_mode_to_string(uint8_t device_mode)
358{
359 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800360 CASE_RETURN_STRING(QDF_STA_MODE);
361 CASE_RETURN_STRING(QDF_SAP_MODE);
362 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
363 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
364 CASE_RETURN_STRING(QDF_FTM_MODE);
365 CASE_RETURN_STRING(QDF_IBSS_MODE);
366 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
367 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700368 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800369 default:
370 return "Unknown";
371 }
372}
373
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530374/**
375 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
376 * @adapter: HDD adapter
377 * @chan_number: Channel number
378 * @chan_bw: Bandwidth
379 *
380 * Checks if the given bandwidth is valid for the given channel number.
381 *
382 * Return: 0 for success, non-zero for failure
383 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700384int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530385 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800386 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530387{
388 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
389 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
390 bool found = false;
391 tHalHandle hal;
392
393 hal = WLAN_HDD_GET_HAL_CTX(adapter);
394 if (!hal) {
395 hdd_err("Invalid HAL context");
396 return -EINVAL;
397 }
398
399 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
400 hdd_err("No valid channel list");
401 return -EOPNOTSUPP;
402 }
403
404 for (i = 0; i < len; i++) {
405 if (chan[i] == chan_number) {
406 found = true;
407 break;
408 }
409 }
410
411 if (found == false) {
412 hdd_err("Channel not in driver's valid channel list");
413 return -EOPNOTSUPP;
414 }
415
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700416 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
417 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530418 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
419 return -EINVAL;
420 }
421
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700422 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530423 if (chan_bw == CH_WIDTH_80MHZ) {
424 hdd_err("BW80 not possible in 2.4GHz band");
425 return -EINVAL;
426 }
427 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
428 (chan_bw != CH_WIDTH_MAX)) {
429 hdd_err("Only BW20 possible on channel 14");
430 return -EINVAL;
431 }
432 }
433
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700434 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530435 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
436 (chan_bw != CH_WIDTH_MAX)) {
437 hdd_err("Only BW20 possible on channel 165");
438 return -EINVAL;
439 }
440 }
441
442 return 0;
443}
444
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530445/**
446 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
447 *
448 * Block the unloading of the driver (or) interface up until the
449 * cds recovery is completed
450 *
451 * Return: true for recovery completion else false
452 */
453static bool hdd_wait_for_recovery_completion(void)
454{
455 int retry = 0;
456
457 /* Wait for recovery to complete */
458 while (cds_is_driver_recovering()) {
459 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
460 hdd_err("Recovery in progress; wait here!!!");
461 msleep(1000);
462 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
463 hdd_err("SSR never completed, error");
464 /*
465 * Trigger the bug_on in the internal builds, in the
466 * customer builds self-recovery will be enabled
467 * in those cases just return error.
468 */
469 if (cds_is_self_recovery_enabled())
470 return false;
471 QDF_BUG(0);
472 }
473 }
474
475 hdd_info("Recovery completed successfully!");
476 return true;
477}
478
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800479static int __hdd_netdev_notifier_call(struct notifier_block *nb,
480 unsigned long state, void *data)
481{
482#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
483 struct netdev_notifier_info *dev_notif_info = data;
484 struct net_device *dev = dev_notif_info->dev;
485#else
486 struct net_device *dev = data;
487#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700488 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700489 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800490
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800491 ENTER_DEV(dev);
492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800493 /* Make sure that this callback corresponds to our device. */
494 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
495 return NOTIFY_DONE;
496
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530497 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700499 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800500 return NOTIFY_DONE;
501 }
502
503 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700504 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800505 return NOTIFY_DONE;
506 }
507
508 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
509 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800510 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530511 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800512 return NOTIFY_DONE;
513 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800514
515 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
516 hdd_err("%s: Driver module is closed", __func__);
517 return NOTIFY_DONE;
518 }
519
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530520 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800521 return NOTIFY_DONE;
522
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800523 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800524 dev->name, state);
525
526 switch (state) {
527 case NETDEV_REGISTER:
528 break;
529
530 case NETDEV_UNREGISTER:
531 break;
532
533 case NETDEV_UP:
534 sme_ch_avoid_update_req(hdd_ctx->hHal);
535 break;
536
537 case NETDEV_DOWN:
538 break;
539
540 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700541 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800542 complete(&adapter->linkup_event_var);
543 break;
544
545 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700546 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
547 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530548 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700549 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800550 } else {
hqueaa33ee2017-05-04 17:56:35 +0800551 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800552 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800553 }
554 break;
555
556 default:
557 break;
558 }
559
560 return NOTIFY_DONE;
561}
562
563/**
564 * hdd_netdev_notifier_call() - netdev notifier callback function
565 * @nb: pointer to notifier block
566 * @state: state
567 * @ndev: ndev pointer
568 *
569 * Return: 0 on success, error number otherwise.
570 */
571static int hdd_netdev_notifier_call(struct notifier_block *nb,
572 unsigned long state,
573 void *ndev)
574{
575 int ret;
576
577 cds_ssr_protect(__func__);
578 ret = __hdd_netdev_notifier_call(nb, state, ndev);
579 cds_ssr_unprotect(__func__);
580
581 return ret;
582}
583
584struct notifier_block hdd_netdev_notifier = {
585 .notifier_call = hdd_netdev_notifier_call,
586};
587
588/* variable to hold the insmod parameters */
589static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800590
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530591static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700592int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530593
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800594/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800595static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800596
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530597/**
598 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
599 * @ch_width: NL channel width
600 *
601 * Converts the NL channel width to the driver's internal representation
602 *
603 * Return: Converted channel width. In case of non matching NL channel width,
604 * CH_WIDTH_MAX will be returned.
605 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800606enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530607{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800608 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700609
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800610 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530611 switch (ch_width) {
612 case NL80211_CHAN_WIDTH_20_NOHT:
613 case NL80211_CHAN_WIDTH_20:
614 return CH_WIDTH_20MHZ;
615 case NL80211_CHAN_WIDTH_40:
616 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530617 case NL80211_CHAN_WIDTH_80:
618 return CH_WIDTH_80MHZ;
619 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800620 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
621 return CH_WIDTH_80P80MHZ;
622 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
623 return CH_WIDTH_160MHZ;
624 else
625 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530626 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800627 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
628 return CH_WIDTH_160MHZ;
629 else
630 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530631 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800632 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530633 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800634 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530635 default:
636 hdd_err("Invalid channel width %d, setting to default",
637 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800638 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530639 }
640}
641
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530642/* wlan_hdd_find_opclass() - Find operating class for a channel
643 * @hal: handler to HAL
644 * @channel: channel id
645 * @bw_offset: bandwidth offset
646 *
647 * Function invokes sme api to find the operating class
648 *
649 * Return: operating class
650 */
651uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
652 uint8_t bw_offset)
653{
654 uint8_t opclass = 0;
655
656 sme_get_opclass(hal, channel, bw_offset, &opclass);
657 return opclass;
658}
659
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800660/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530661 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530662 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800663 * @bitmask: Bitmask of log levels to be enabled
664 *
665 * Called immediately after the cfg.ini is read in order to configure
666 * the desired trace levels.
667 *
668 * Return: None
669 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530670int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800671{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530672 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530673 int qdf_print_idx = -1;
674 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800675 /*
676 * if the bitmask is the default value, then a bitmask was not
677 * specified in cfg.ini, so leave the logging level alone (it
678 * will remain at the "compiled in" default value)
679 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700680 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530681 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800682
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530683 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800684
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530685 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530686 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530687 QDF_TRACE_LEVEL_NONE, 0);
688
689 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530690 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530692 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693 while (0 != bitmask) {
694 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530695 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530696 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530697 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530698 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800699 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700700
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800701 level++;
702 bitmask >>= 1;
703 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530704 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800705}
706
707/**
Chris Guo1751acf2017-07-03 14:09:01 +0800708 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
709 * @hdd_ctx: HDD context pointer
710 *
711 * Return: 0 if the context is valid. Error code otherwise
712 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700713int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800714{
715 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
716 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
717 return -ENODEV;
718 }
719
720 if (cds_is_driver_recovering()) {
721 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
722 (void *)_RET_IP_, cds_get_driver_state());
723 return -EAGAIN;
724 }
725
726 if (hdd_ctx->start_modules_in_progress ||
727 hdd_ctx->stop_modules_in_progress) {
728 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
729 (void *)_RET_IP_);
730 return -EAGAIN;
731 }
732
733 return 0;
734}
735
736
737/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 * wlan_hdd_validate_context() - check the HDD context
739 * @hdd_ctx: HDD context pointer
740 *
741 * Return: 0 if the context is valid. Error code otherwise
742 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700743int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800744{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530746 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747 return -ENODEV;
748 }
749
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800750 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800751 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530752 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800753 return -EAGAIN;
754 }
755
Yue Ma9f275d92017-09-14 16:58:41 -0700756 if (cds_is_load_or_unload_in_progress()) {
757 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
758 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700760 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530761
762 if (hdd_ctx->start_modules_in_progress ||
763 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800764 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530765 (void *)_RET_IP_);
766 return -EAGAIN;
767 }
768
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530769 if (cds_is_driver_in_bad_state()) {
770 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
771 (void *)_RET_IP_, cds_get_driver_state());
772 return -ENODEV;
773 }
774
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 return 0;
776}
777
Jeff Johnson9d295242017-08-29 14:39:48 -0700778int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700779{
780 if (!adapter) {
781 hdd_err("adapter is null");
782 return -EINVAL;
783 }
784
785 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
786 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
787 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
788 return -EINVAL;
789 }
790
791 if (!adapter->dev) {
792 hdd_err("adapter net_device is null");
793 return -EINVAL;
794 }
795
796 if (!(adapter->dev->flags & IFF_UP)) {
797 hdd_info("adapter net_device is not up");
798 return -EAGAIN;
799 }
800
Jeff Johnson1b780e42017-10-31 14:11:45 -0700801 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700802 hdd_info("adapter session is not open");
803 return -EAGAIN;
804 }
805
Jeff Johnson1b780e42017-10-31 14:11:45 -0700806 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
807 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700808 return -EINVAL;
809 }
810
811 return 0;
812}
813
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530815 * wlan_hdd_validate_modules_state() - Check modules status
816 * @hdd_ctx: HDD context pointer
817 *
818 * Check's the driver module's state and returns true if the
819 * modules are enabled returns false if modules are closed.
820 *
821 * Return: True if modules are enabled or false.
822 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700823bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530824{
825 mutex_lock(&hdd_ctx->iface_change_lock);
826 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
827 mutex_unlock(&hdd_ctx->iface_change_lock);
828 hdd_notice("Modules not enabled, Present status: %d",
829 hdd_ctx->driver_status);
830 return false;
831 }
832 mutex_unlock(&hdd_ctx->iface_change_lock);
833 return true;
834}
835
836/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700838 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800839 *
840 * This function sets the IBSS power save config parameters to WMA
841 * which will send it to firmware if FW supports IBSS power save
842 * before vdev start.
843 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530844 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 * on failure.
846 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700847QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800848{
849 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700850 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851
852 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700853 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530854 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800855 }
856
Jeff Johnson1b780e42017-10-31 14:11:45 -0700857 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800858 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
859 hdd_ctx->config->ibssATIMWinSize,
860 VDEV_CMD);
861 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700862 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530863 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864 }
865
Jeff Johnson1b780e42017-10-31 14:11:45 -0700866 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
868 hdd_ctx->config->isIbssPowerSaveAllowed,
869 VDEV_CMD);
870 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700871 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
872 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530873 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874 }
875
Jeff Johnson1b780e42017-10-31 14:11:45 -0700876 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
878 hdd_ctx->config->
879 isIbssPowerCollapseAllowed, VDEV_CMD);
880 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700881 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
882 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530883 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800884 }
885
Jeff Johnson1b780e42017-10-31 14:11:45 -0700886 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800887 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
888 hdd_ctx->config->isIbssAwakeOnTxRx,
889 VDEV_CMD);
890 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700891 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530892 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893 }
894
Jeff Johnson1b780e42017-10-31 14:11:45 -0700895 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
897 hdd_ctx->config->ibssInactivityCount,
898 VDEV_CMD);
899 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700900 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530901 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800902 }
903
Jeff Johnson1b780e42017-10-31 14:11:45 -0700904 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800905 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
906 hdd_ctx->config->ibssTxSpEndInactivityTime,
907 VDEV_CMD);
908 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700909 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
910 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530911 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 }
913
Jeff Johnson1b780e42017-10-31 14:11:45 -0700914 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
916 hdd_ctx->config->ibssPsWarmupTime,
917 VDEV_CMD);
918 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700919 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
920 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530921 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800922 }
923
Jeff Johnson1b780e42017-10-31 14:11:45 -0700924 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
926 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
927 VDEV_CMD);
928 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700929 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
930 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530931 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800932 }
933
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530934 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800935}
936
Yue Macd359b72017-10-03 15:21:00 -0700937#ifdef FEATURE_RUNTIME_PM
938/**
939 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
940 * @hdd_ctx: HDD context
941 *
942 * Return: None
943 */
944static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
945{
946 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
947
Yue Macd359b72017-10-03 15:21:00 -0700948 qdf_runtime_lock_init(&ctx->dfs);
949
950 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
951}
952
953/**
954 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
955 * @hdd_ctx: HDD Context
956 *
957 * Return: None
958 */
959static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
960{
961 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
962
Yue Macd359b72017-10-03 15:21:00 -0700963 qdf_runtime_lock_deinit(&ctx->dfs);
964
965 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
966}
967
968static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
969{
970 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
971
972 qdf_runtime_lock_init(&ctx->connect);
973}
974
Yue Ma9e89e832017-11-14 11:40:23 -0800975static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter)
Yue Macd359b72017-10-03 15:21:00 -0700976{
977 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
978
979 qdf_runtime_lock_deinit(&ctx->connect);
980}
981#else /* FEATURE_RUNTIME_PM */
982static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
983static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
984static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
Yue Ma9e89e832017-11-14 11:40:23 -0800985static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter) {}
Yue Macd359b72017-10-03 15:21:00 -0700986#endif /* FEATURE_RUNTIME_PM */
987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988#define INTF_MACADDR_MASK 0x7
989
990/**
991 * hdd_update_macaddr() - update mac address
992 * @config: hdd configuration
993 * @hw_macaddr: mac address
994 *
995 * Mac address for multiple virtual interface is found as following
996 * i) The mac address of the first interface is just the actual hw mac address.
997 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
998 * define the mac address for the remaining interfaces and locally
999 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1000 * supported virtual interfaces, right now this is 0x07 (meaning 8
1001 * interface).
1002 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1003 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1004 *
1005 * Return: None
1006 */
1007void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301008 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009{
1010 int8_t i;
1011 uint8_t macaddr_b3, tmp_br3;
1012
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301013 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301014 QDF_MAC_ADDR_SIZE);
1015 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301016 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301017 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1019 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1020 INTF_MACADDR_MASK;
1021 macaddr_b3 += tmp_br3;
1022
1023 /* XOR-ing bit-24 of the mac address. This will give enough
1024 * mac address range before collision
1025 */
1026 macaddr_b3 ^= (1 << 7);
1027
1028 /* Set locally administered bit */
1029 config->intfMacAddr[i].bytes[0] |= 0x02;
1030 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001031 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001032 MAC_ADDRESS_STR, i,
1033 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1034 }
1035}
1036
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001037static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 struct wma_tgt_services *cfg)
1039{
1040 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001041
1042 /* Set up UAPSD */
1043 config->apUapsdEnabled &= cfg->uapsd;
1044
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001045 /* 11AX mode support */
1046 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1047 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1048 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1049
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050 /* 11AC mode support */
1051 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1052 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1053 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054
1055 /* ARP offload: override user setting if invalid */
1056 config->fhostArpOffload &= cfg->arp_offload;
1057
1058#ifdef FEATURE_WLAN_SCAN_PNO
1059 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001060 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061 if (cfg->pno_offload)
1062 config->PnoOffload = true;
1063#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064#ifdef FEATURE_WLAN_TDLS
1065 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301066 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1067 cfg->en_tdls_offchan;
1068 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1069 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001070 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001071 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001072 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001075#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1076 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1077#endif
Will Huang496b36c2017-07-11 16:38:50 +08001078 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001079 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001080 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001081
1082}
1083
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001084/**
1085 * hdd_update_vdev_nss() - sets the vdev nss
1086 * @hdd_ctx: HDD context
1087 *
1088 * Sets the Nss per vdev type based on INI
1089 *
1090 * Return: None
1091 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001092static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001093{
1094 struct hdd_config *cfg_ini = hdd_ctx->config;
1095 uint8_t max_supp_nss = 1;
1096
Naveen Rawat10b1c152017-01-18 11:16:06 -08001097 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001098 max_supp_nss = 2;
1099
1100 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1101 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1102
1103 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1104 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1105}
1106
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301107/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301108 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1109 * @hdd_ctx: HDD context
1110 *
1111 * Updates wiphy vhtcap fields
1112 *
1113 * Return: None
1114 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001115static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301116{
1117 struct ieee80211_supported_band *band_5g =
1118 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1119 uint32_t val;
1120
1121 if (!band_5g) {
1122 hdd_debug("5GHz band disabled, skipping capability population");
1123 return;
1124 }
1125
1126 val = hdd_ctx->config->txBFCsnValue;
1127 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1128
1129 val = NUM_OF_SOUNDING_DIMENSIONS;
1130 band_5g->vht_cap.cap |=
1131 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1132
1133 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1134 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1135}
1136
1137/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301138 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1139 * @hdd_ctx: HDD context
1140 *
1141 * Sets the DBS capability as per INI and firmware capability
1142 *
1143 * Return: None
1144 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001145static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301146{
1147 struct hdd_config *cfg_ini = hdd_ctx->config;
1148 uint8_t hw_dbs_capable = 0;
1149
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001150 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1151 ((cfg_ini->dual_mac_feature_disable ==
1152 ENABLE_DBS_CXN_AND_SCAN) ||
1153 (cfg_ini->dual_mac_feature_disable ==
1154 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301155 hw_dbs_capable = 1;
1156
1157 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1158}
1159
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001160static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161 struct wma_tgt_ht_cap *cfg)
1162{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301163 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001164 uint32_t value, val32;
1165 uint16_t val16;
1166 struct hdd_config *pconfig = hdd_ctx->config;
1167 tSirMacHTCapabilityInfo *phtCapInfo;
1168 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1169 uint8_t enable_tx_stbc;
1170
1171 /* check and update RX STBC */
1172 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1173 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1174
1175 /* get the MPDU density */
1176 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1177
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301178 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001179 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001180 value = 0;
1181 }
1182
1183 /*
1184 * MPDU density:
1185 * override user's setting if value is larger
1186 * than the one supported by target
1187 */
1188 if (value > cfg->mpdu_density) {
1189 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1190 cfg->mpdu_density);
1191
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301192 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001193 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001194 }
1195
1196 /* get the HT capability info */
1197 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301198 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001199 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001200 return;
1201 }
1202 val16 = (uint16_t) val32;
1203 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1204
1205 /* Set the LDPC capability */
1206 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1207
1208 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1209 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1210
1211 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1212 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1213
1214 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1215 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1216
1217 enable_tx_stbc = pconfig->enableTxSTBC;
1218
1219 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1220 pconfig->enable2x2 = 1;
1221 } else {
1222 pconfig->enable2x2 = 0;
1223 enable_tx_stbc = 0;
1224
1225 /* 1x1 */
1226 /* Update Rx Highest Long GI data Rate */
1227 if (sme_cfg_set_int(hdd_ctx->hHal,
1228 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001229 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301230 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001231 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001232 }
1233
1234 /* Update Tx Highest Long GI data Rate */
1235 if (sme_cfg_set_int
1236 (hdd_ctx->hHal,
1237 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001238 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301239 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001240 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241 }
1242 }
1243 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1244 enable_tx_stbc = 0;
1245 phtCapInfo->txSTBC = enable_tx_stbc;
1246
1247 val32 = val16;
1248 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301249 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001250 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1252 value = SIZE_OF_SUPPORTED_MCS_SET;
1253 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301254 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001255 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001256
1257 if (pconfig->enable2x2) {
1258 for (value = 0; value < cfg->num_rf_chains; value++)
1259 mcs_set[value] =
1260 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1261
1262 status =
1263 sme_cfg_set_str(hdd_ctx->hHal,
1264 WNI_CFG_SUPPORTED_MCS_SET,
1265 mcs_set,
1266 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301267 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001268 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269 }
1270 }
1271#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1272}
1273
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001274static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001275 struct wma_tgt_vht_cap *cfg)
1276{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301277 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001278 uint32_t value = 0;
1279 struct hdd_config *pconfig = hdd_ctx->config;
1280 struct wiphy *wiphy = hdd_ctx->wiphy;
1281 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001282 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001283 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001284 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001285 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001286
Dustin Brown5e06bd32016-10-04 12:49:10 -07001287 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001288 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001289 return;
1290 }
1291
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001292 /* Get the current MPDU length */
1293 status =
1294 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1295 &value);
1296
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301297 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001298 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299 value = 0;
1300 }
1301
1302 /*
1303 * VHT max MPDU length:
1304 * override if user configured value is too high
1305 * that the target cannot support
1306 */
1307 if (value > cfg->vht_max_mpdu) {
1308 status = sme_cfg_set_int(hdd_ctx->hHal,
1309 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1310 cfg->vht_max_mpdu);
1311
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001312 if (status == QDF_STATUS_E_FAILURE)
1313 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001314 }
1315
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001316 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1317 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1318
1319 if (pconfig->enable2x2)
1320 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1321
1322 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1323 QDF_STATUS_E_FAILURE) {
1324 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1325 }
1326
1327 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1328 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1329 if (pconfig->enable2x2)
1330 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1331
1332 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1333 QDF_STATUS_E_FAILURE) {
1334 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1335 }
1336
1337 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1338 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1339 if (pconfig->enable2x2)
1340 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1341
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001342 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001343 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1344
1345 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1346 QDF_STATUS_E_FAILURE) {
1347 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1348 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001349 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001350 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 &value);
1352
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301353 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001354 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001355 value = 0;
1356 }
1357
jiad4a7a33c2017-08-08 15:32:24 +08001358 /* Set HW RX LDPC capability */
1359 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1360 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 status = sme_cfg_set_int(hdd_ctx->hHal,
1362 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001363 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001365 if (status == QDF_STATUS_E_FAILURE)
1366 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001367 }
1368
1369 /* Get current GI 80 value */
1370 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1371 &value);
1372
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301373 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001374 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001375 value = 0;
1376 }
1377
1378 /* set the Guard interval 80MHz */
1379 if (value && !cfg->vht_short_gi_80) {
1380 status = sme_cfg_set_int(hdd_ctx->hHal,
1381 WNI_CFG_VHT_SHORT_GI_80MHZ,
1382 cfg->vht_short_gi_80);
1383
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001384 if (status == QDF_STATUS_E_FAILURE)
1385 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386 }
1387
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001388 /* Get VHT TX STBC cap */
1389 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1390
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301391 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001392 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001393 value = 0;
1394 }
1395
1396 /* VHT TX STBC cap */
1397 if (value && !cfg->vht_tx_stbc) {
1398 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1399 cfg->vht_tx_stbc);
1400
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001401 if (status == QDF_STATUS_E_FAILURE)
1402 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 }
1404
1405 /* Get VHT RX STBC cap */
1406 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1407
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301408 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001409 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001410 value = 0;
1411 }
1412
1413 /* VHT RX STBC cap */
1414 if (value && !cfg->vht_rx_stbc) {
1415 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1416 cfg->vht_rx_stbc);
1417
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001418 if (status == QDF_STATUS_E_FAILURE)
1419 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420 }
1421
1422 /* Get VHT SU Beamformer cap */
1423 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1424 &value);
1425
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301426 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001427 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 value = 0;
1429 }
1430
1431 /* set VHT SU Beamformer cap */
1432 if (value && !cfg->vht_su_bformer) {
1433 status = sme_cfg_set_int(hdd_ctx->hHal,
1434 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1435 cfg->vht_su_bformer);
1436
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001437 if (status == QDF_STATUS_E_FAILURE)
1438 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001439 }
1440
1441 /* check and update SU BEAMFORMEE capabality */
1442 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1443 pconfig->enableTxBF = cfg->vht_su_bformee;
1444
1445 status = sme_cfg_set_int(hdd_ctx->hHal,
1446 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1447 pconfig->enableTxBF);
1448
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001449 if (status == QDF_STATUS_E_FAILURE)
1450 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451
1452 /* Get VHT MU Beamformer cap */
1453 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1454 &value);
1455
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301456 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001457 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 value = 0;
1459 }
1460
1461 /* set VHT MU Beamformer cap */
1462 if (value && !cfg->vht_mu_bformer) {
1463 status = sme_cfg_set_int(hdd_ctx->hHal,
1464 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1465 cfg->vht_mu_bformer);
1466
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001467 if (status == QDF_STATUS_E_FAILURE)
1468 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001469 }
1470
1471 /* Get VHT MU Beamformee cap */
1472 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1473 &value);
1474
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301475 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001476 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001477 value = 0;
1478 }
1479
1480 /* set VHT MU Beamformee cap */
1481 if (value && !cfg->vht_mu_bformee) {
1482 status = sme_cfg_set_int(hdd_ctx->hHal,
1483 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1484 cfg->vht_mu_bformee);
1485
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001486 if (status == QDF_STATUS_E_FAILURE)
1487 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001488 }
1489
1490 /* Get VHT MAX AMPDU Len exp */
1491 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1492 &value);
1493
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301494 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001495 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496 value = 0;
1497 }
1498
1499 /*
1500 * VHT max AMPDU len exp:
1501 * override if user configured value is too high
1502 * that the target cannot support.
1503 * Even though Rome publish ampdu_len=7, it can
1504 * only support 4 because of some h/w bug.
1505 */
1506
1507 if (value > cfg->vht_max_ampdu_len_exp) {
1508 status = sme_cfg_set_int(hdd_ctx->hHal,
1509 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1510 cfg->vht_max_ampdu_len_exp);
1511
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001512 if (status == QDF_STATUS_E_FAILURE)
1513 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514 }
1515
1516 /* Get VHT TXOP PS CAP */
1517 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1518
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301519 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001520 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001521 value = 0;
1522 }
1523
1524 /* set VHT TXOP PS cap */
1525 if (value && !cfg->vht_txop_ps) {
1526 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1527 cfg->vht_txop_ps);
1528
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001529 if (status == QDF_STATUS_E_FAILURE)
1530 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001531 }
1532
1533 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1534 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1535 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1536 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1537 else
1538 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1539
1540
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001541 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1542 status = sme_cfg_set_int(hdd_ctx->hHal,
1543 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1544 VHT_CAP_160_AND_80P80_SUPP);
1545 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001546 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001547 band_5g->vht_cap.cap |=
1548 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001549 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1550 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1551 status = sme_cfg_set_int(hdd_ctx->hHal,
1552 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1553 VHT_CAP_160_SUPP);
1554 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001555 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001556 band_5g->vht_cap.cap |=
1557 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001558 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1559 }
1560 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1561 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301562 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001563 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301564 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001565 &value);
1566 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301567 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001568 value = 0;
1569 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301570 /* set the Guard interval 160MHz */
1571 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001572 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301573 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1574 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001575
1576 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301577 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001578 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579
1580 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1581 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1582
1583 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1584 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1585 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1586 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1587
1588 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1589 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1590
1591 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1592 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1593 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1594 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1595 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1596 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1597
1598 band_5g->vht_cap.cap |=
1599 (cfg->vht_max_ampdu_len_exp <<
1600 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1601
1602 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1603 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1604 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1605 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1606 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1607 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1608 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1609 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1610
1611 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1612 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1613
1614}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001616/**
1617 * hdd_generate_macaddr_auto() - Auto-generate mac address
1618 * @hdd_ctx: Pointer to the HDD context
1619 *
1620 * Auto-generate mac address using device serial number.
1621 * Keep the first 3 bytes of OUI as before and replace
1622 * the last 3 bytes with the lower 3 bytes of serial number.
1623 *
1624 * Return: 0 for success
1625 * Non zero failure code for errors
1626 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001627static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001628{
1629 unsigned int serialno = 0;
1630 struct qdf_mac_addr mac_addr = {
1631 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1632 };
1633
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001634 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001635 if (serialno == 0)
1636 return -EINVAL;
1637
1638 serialno &= 0x00ffffff;
1639
1640 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1641 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1642 mac_addr.bytes[5] = serialno & 0xff;
1643
1644 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1645 return 0;
1646}
1647
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301648/**
1649 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1650 * configuration to cfg_ini in HDD
1651 * @hdd_ctx: Pointer to hdd_ctx
1652 * @cfg: target configuration
1653 *
1654 * Return: None
1655 */
1656#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001657static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301658 struct wma_tgt_cfg *cfg)
1659{
1660 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1661}
1662#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001663static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301664 struct wma_tgt_cfg *cfg)
1665{
1666}
1667#endif
1668
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001669void hdd_update_tgt_cfg(void *context, void *param)
1670{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001671 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001672 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001673 struct wma_tgt_cfg *cfg = param;
1674 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001675 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301676 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301677
Yue Mae3e86ab2017-05-08 10:48:24 -07001678 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301679 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1680 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1681 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1682 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1683 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001684 /* Restore pdev to MAC/WMA contexts */
1685 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001686 } else {
1687 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1688 if (ret) {
1689 hdd_err("pdev creation fails!");
1690 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301691 } else
1692 hdd_debug("New pdev has been created with pdev_id = %u",
1693 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301694 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001695
Naveen Rawat64e477e2016-05-20 10:34:56 -07001696 if (cds_cfg) {
1697 if (hdd_ctx->config->enable_sub_20_channel_width !=
1698 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1699 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1700 cds_cfg->sub_20_channel_width =
1701 WLAN_SUB_20_CH_WIDTH_NONE;
1702 } else {
1703 cds_cfg->sub_20_channel_width =
1704 hdd_ctx->config->enable_sub_20_channel_width;
1705 }
1706 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001707
1708 /* first store the INI band capability */
1709 temp_band_cap = hdd_ctx->config->nBandCapability;
1710
1711 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301712 hdd_ctx->is_fils_roaming_supported =
1713 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001715 /*
1716 * now overwrite the target band capability with INI
1717 * setting if INI setting is a subset
1718 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001719
1720 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1721 (temp_band_cap != eCSR_BAND_ALL))
1722 hdd_ctx->config->nBandCapability = temp_band_cap;
1723 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1724 (temp_band_cap != eCSR_BAND_ALL) &&
1725 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001726 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001727 }
1728
Amar Singhal58b45ef2017-08-01 13:43:54 -07001729 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1730
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301731 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1733 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1734 }
1735
1736 /* This can be extended to other configurations like ht, vht cap... */
1737
Anurag Chouhanc5548422016-02-24 18:33:27 +05301738 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001739 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001740 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001741 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001742 static struct qdf_mac_addr default_mac_addr = {
1743 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1744 };
1745 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1746 &default_mac_addr)) {
1747 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1748 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1749 MAC_ADDRESS_STR,
1750 MAC_ADDR_ARRAY(hdd_ctx->config->
1751 intfMacAddr[0].bytes));
1752 } else {
1753 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1754 MAC_ADDRESS_STR,
1755 MAC_ADDR_ARRAY(hdd_ctx->config->
1756 intfMacAddr[0].bytes));
1757 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001758 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001759 }
1760
1761 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001762 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001763
1764 hdd_ctx->max_intf_count = cfg->max_intf_count;
1765
Jeff Johnsonc875e242016-09-23 18:12:34 -07001766 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001767 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001768
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001769 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1770 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1771
1772 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1773
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001774 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001775 if (cfg->services.en_11ax) {
1776 hdd_info("11AX: 11ax is enabled - update HDD config");
1777 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1778 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001779
1780 hdd_update_vdev_nss(hdd_ctx);
1781
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301782 hdd_update_hw_dbs_capable(hdd_ctx);
1783
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001784 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001785 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001786 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001787 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001788
Nitesh Shahe50711f2017-04-26 16:30:45 +05301789 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1790 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1791 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001792 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001793 hdd_ctx->current_antenna_mode);
1794
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001795 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1796 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301797 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301798 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301799
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301800 if ((hdd_ctx->config->txBFCsnValue >
1801 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1802 !cfg->tx_bfee_8ss_enabled)
1803 hdd_ctx->config->txBFCsnValue =
1804 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1805
1806 if (sme_cfg_set_int(hdd_ctx->hHal,
1807 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1808 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1809 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1810
1811
1812 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1813 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1814 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301815
1816 /*
1817 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1818 */
1819 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301820
1821 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1822
Arun Khandavallid454d422016-08-17 12:47:05 +05301823 /*
1824 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1825 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1826 * configure the STA mode wow pattern.
1827 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301828 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301829 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301830
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301831 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1832
Yue Macd359b72017-10-03 15:21:00 -07001833 /*
1834 * This needs to be done after HDD pdev is created and stored since
1835 * it will access the HDD pdev object lock.
1836 */
1837 hdd_runtime_suspend_context_init(hdd_ctx);
1838
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001839 /* Configure NAN datapath features */
1840 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001841 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001842}
1843
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001844bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001845{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001846 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001847 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301848 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001849 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001850
Arif Hussaincd151632017-02-11 16:57:19 -08001851 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001852 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001853 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301854 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001855 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856
Arif Hussaincd151632017-02-11 16:57:19 -08001857 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1858 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001859 adapter = adapterNode->adapter;
Arif Hussaincd151632017-02-11 16:57:19 -08001860 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1861
1862 if ((QDF_SAP_MODE == adapter->device_mode ||
1863 QDF_P2P_GO_MODE == adapter->device_mode) &&
1864 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07001865 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08001866 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1867 true;
1868 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07001869 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301870 }
Arif Hussaincd151632017-02-11 16:57:19 -08001871 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1872 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001873 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301874
1875 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001876}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877
1878/**
1879 * hdd_is_valid_mac_address() - validate MAC address
1880 * @pMacAddr: Pointer to the input MAC address
1881 *
1882 * This function validates whether the given MAC address is valid or not
1883 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1884 * where X is the hexa decimal digit character and separated by ':'
1885 * This algorithm works even if MAC address is not separated by ':'
1886 *
1887 * This code checks given input string mac contains exactly 12 hexadecimal
1888 * digits and a separator colon : appears in the input string only after
1889 * an even number of hex digits.
1890 *
1891 * Return: 1 for valid and 0 for invalid
1892 */
1893bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1894{
1895 int xdigit = 0;
1896 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001897
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001898 while (*pMacAddr) {
1899 if (isxdigit(*pMacAddr)) {
1900 xdigit++;
1901 } else if (':' == *pMacAddr) {
1902 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1903 break;
1904
1905 ++separator;
1906 } else {
1907 /* Invalid MAC found */
1908 return 0;
1909 }
1910 ++pMacAddr;
1911 }
1912 return xdigit == 12 && (separator == 5 || separator == 0);
1913}
1914
1915/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301916 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1917 * @dev: Handle to struct net_device to be updated.
1918 *
1919 * Return: None
1920 */
1921static void hdd_mon_mode_ether_setup(struct net_device *dev)
1922{
1923 dev->header_ops = NULL;
1924 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1925 dev->hard_header_len = ETH_HLEN;
1926 dev->mtu = ETH_DATA_LEN;
1927 dev->addr_len = ETH_ALEN;
1928 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1929 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1930 dev->priv_flags |= IFF_TX_SKB_SHARING;
1931
1932 memset(dev->broadcast, 0xFF, ETH_ALEN);
1933}
1934
1935/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001936 * __hdd__mon_open() - HDD Open function
1937 * @dev: Pointer to net_device structure
1938 *
1939 * This is called in response to ifconfig up
1940 *
1941 * Return: 0 for success; non-zero for failure
1942 */
1943static int __hdd_mon_open(struct net_device *dev)
1944{
1945 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001946 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1947 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001948
1949 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001950
1951 ret = wlan_hdd_validate_context(hdd_ctx);
1952 if (ret)
1953 return ret;
1954
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301955 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001956
1957 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1958 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1959 if (ret) {
1960 hdd_err("Failed to start WLAN modules return");
1961 return ret;
1962 }
1963 hdd_err("hdd_wlan_start_modules() successful !");
1964
1965 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1966 ret = hdd_start_adapter(adapter);
1967 if (ret) {
1968 hdd_err("Failed to start adapter :%d",
1969 adapter->device_mode);
1970 return ret;
1971 }
1972 hdd_err("hdd_start_adapters() successful !");
1973 }
1974 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1975 }
1976
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001977 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001978
1979 if (!ret)
1980 ret = hdd_enable_monitor_mode(dev);
1981
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001982 return ret;
1983}
1984
1985/**
1986 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1987 * @dev: Pointer to net_device structure
1988 *
1989 * This is called in response to ifconfig up
1990 *
1991 * Return: 0 for success; non-zero for failure
1992 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001993static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001994{
1995 int ret;
1996
1997 cds_ssr_protect(__func__);
1998 ret = __hdd_mon_open(dev);
1999 cds_ssr_unprotect(__func__);
2000
2001 return ret;
2002}
2003
2004/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302005 * hdd_start_adapter() - Wrapper function for device specific adapter
2006 * @adapter: pointer to HDD adapter
2007 *
2008 * This function is called to start the device specific adapter for
2009 * the mode passed in the adapter's device_mode.
2010 *
2011 * Return: 0 for success; non-zero for failure
2012 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002013int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302014{
2015
2016 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002017 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302018
2019 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002020 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302021
2022 switch (device_mode) {
2023 case QDF_P2P_CLIENT_MODE:
2024 case QDF_P2P_DEVICE_MODE:
2025 case QDF_OCB_MODE:
2026 case QDF_STA_MODE:
2027 case QDF_MONITOR_MODE:
2028 ret = hdd_start_station_adapter(adapter);
2029 if (ret)
2030 goto err_start_adapter;
2031 break;
2032 case QDF_P2P_GO_MODE:
2033 case QDF_SAP_MODE:
2034 ret = hdd_start_ap_adapter(adapter);
2035 if (ret)
2036 goto err_start_adapter;
2037 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302038 case QDF_IBSS_MODE:
2039 /*
2040 * For IBSS interface is initialized as part of
2041 * hdd_init_station_mode()
2042 */
2043 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302044 case QDF_FTM_MODE:
2045 ret = hdd_start_ftm_adapter(adapter);
2046 if (ret)
2047 goto err_start_adapter;
2048 break;
2049 default:
2050 hdd_err("Invalid session type %d", device_mode);
2051 QDF_ASSERT(0);
2052 goto err_start_adapter;
2053 }
2054 if (hdd_set_fw_params(adapter))
2055 hdd_err("Failed to set the FW params for the adapter!");
2056
2057 /*
2058 * Action frame registered in one adapter which will
2059 * applicable to all interfaces
2060 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302061 ret = wlan_hdd_cfg80211_register_frames(adapter);
2062 if (ret < 0) {
2063 hdd_err("Failed to register frames - ret %d", ret);
2064 goto err_start_adapter;
2065 }
2066
Arun Khandavallifae92942016-08-01 13:31:08 +05302067 EXIT();
2068 return 0;
2069err_start_adapter:
2070 return -EINVAL;
2071}
2072
2073/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302074 * hdd_enable_power_management() - API to Enable Power Management
2075 *
2076 * API invokes Bus Interface Layer power management functionality
2077 *
2078 * Return: None
2079 */
2080static void hdd_enable_power_management(void)
2081{
2082 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2083
2084 if (!hif_ctx) {
2085 hdd_err("Bus Interface Context is Invalid");
2086 return;
2087 }
2088
2089 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2090}
2091
2092/**
2093 * hdd_disable_power_management() - API to disable Power Management
2094 *
2095 * API disable Bus Interface Layer Power management functionality
2096 *
2097 * Return: None
2098 */
2099static void hdd_disable_power_management(void)
2100{
2101 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2102
2103 if (!hif_ctx) {
2104 hdd_err("Bus Interface Context is Invalid");
2105 return;
2106 }
2107
2108 hif_disable_power_management(hif_ctx);
2109}
2110
2111/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302112 * hdd_update_hw_sw_info() - API to update the HW/SW information
2113 *
2114 * API to update the HW and SW information in the driver
2115 *
2116 * Return: None
2117 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002118static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302119{
2120 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002121 size_t target_hw_name_len;
2122 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302123
2124 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2125 if (!hif_sc) {
2126 hdd_err("HIF context is NULL");
2127 return;
2128 }
2129
2130 /*
2131 * target hw version/revision would only be retrieved after firmware
2132 * download
2133 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002134 hif_get_hw_info(hif_sc,
2135 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302136 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002137 &target_hw_name);
2138
2139 if (hdd_ctx->target_hw_name)
2140 qdf_mem_free(hdd_ctx->target_hw_name);
2141
2142 target_hw_name_len = strlen(target_hw_name) + 1;
2143 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2144 if (hdd_ctx->target_hw_name)
2145 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2146 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302147
2148 /* Get the wlan hw/fw version */
2149 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302150}
2151
2152/**
gbian62edd7e2017-03-07 13:12:13 +08002153 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2154 * @hdd_ctx: Pointer to hdd context
2155 *
2156 * Return: none
2157 */
2158static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002159hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002160{
2161 uint8_t num_entries = 0;
2162 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2163 uint8_t *tx_sched_wrr_ac;
2164 int i;
2165 cds_context_type *cds_ctx;
2166
2167 if (NULL == hdd_ctx)
2168 return;
2169
2170 if (NULL == hdd_ctx->config) {
2171 /* Do nothing if hdd_ctx is invalid */
2172 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2173 return;
2174 }
2175
2176 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2177
2178 if (!cds_ctx) {
2179 hdd_err("Invalid CDS Context");
2180 return;
2181 }
2182
2183 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2184 switch (i) {
2185 case OL_TX_WMM_AC_BE:
2186 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2187 break;
2188 case OL_TX_WMM_AC_BK:
2189 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2190 break;
2191 case OL_TX_WMM_AC_VI:
2192 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2193 break;
2194 case OL_TX_WMM_AC_VO:
2195 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2196 break;
2197 default:
2198 tx_sched_wrr_ac = NULL;
2199 break;
2200 }
2201
2202 hdd_string_to_u8_array(tx_sched_wrr_ac,
2203 tx_sched_wrr_param,
2204 &num_entries,
2205 sizeof(tx_sched_wrr_param));
2206
2207 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2208 cds_ctx->ac_specs[i].wrr_skip_weight =
2209 tx_sched_wrr_param[0];
2210 cds_ctx->ac_specs[i].credit_threshold =
2211 tx_sched_wrr_param[1];
2212 cds_ctx->ac_specs[i].send_limit =
2213 tx_sched_wrr_param[2];
2214 cds_ctx->ac_specs[i].credit_reserve =
2215 tx_sched_wrr_param[3];
2216 cds_ctx->ac_specs[i].discard_weight =
2217 tx_sched_wrr_param[4];
2218 }
2219
2220 num_entries = 0;
2221 }
2222}
2223
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002224#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002225static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2226 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2227{
Jeff Johnson9d295242017-08-29 14:39:48 -07002228 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002229 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002230
2231 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2232 if (!adapter) {
2233 hdd_err("Adapter is NULL");
2234 return PM_MAX_NUM_OF_MODE;
2235 }
2236
2237 return policy_mgr_convert_device_mode_to_qdf_type(
2238 adapter->device_mode);
2239}
2240
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002241static void hdd_register_policy_manager_callback(
2242 struct wlan_objmgr_psoc *psoc)
2243{
2244 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002245
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002246 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002247 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002248 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2249 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002250 hdd_cbacks.get_mode_for_non_connected_vdev =
2251 wlan_hdd_get_mode_for_non_connected_vdev;
2252
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002253 if (QDF_STATUS_SUCCESS !=
2254 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2255 hdd_err("HDD callback registration with policy manager failed");
2256 }
2257}
2258#else
2259static void hdd_register_policy_manager_callback(
2260 struct wlan_objmgr_psoc *psoc)
2261{
2262}
2263#endif
2264
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002265#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002266static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002267{
2268 struct nan_callbacks cb_obj = {0};
2269
2270 cb_obj.ndi_open = hdd_ndi_open;
2271 cb_obj.ndi_close = hdd_ndi_close;
2272 cb_obj.ndi_start = hdd_ndi_start;
2273 cb_obj.ndi_delete = hdd_ndi_delete;
2274 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2275 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2276
Naveen Rawat37f62c82017-03-26 22:24:43 -07002277 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2278 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002279 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002280
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002281 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2282}
2283#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002284static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002285{
2286}
2287#endif
2288
gbian62edd7e2017-03-07 13:12:13 +08002289/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302290 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2291 * @hdd_ctx: HDD context
2292 * @adapter: HDD adapter
2293 * @reinit: flag to indicate from SSR or normal path
2294 *
2295 * This function maintains the driver state machine it will be invoked from
2296 * startup, reinit and change interface. Depending on the driver state shall
2297 * perform the opening of the modules.
2298 *
2299 * Return: 0 for success; non-zero for failure
2300 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002301int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2302 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302303 bool reinit)
2304{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002305 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302306 qdf_device_t qdf_dev;
2307 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302308 bool unint = false;
2309 void *hif_ctx;
2310
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002311 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302312
2313 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2314 if (!qdf_dev) {
2315 hdd_err("QDF Device Context is Invalid return");
2316 return -EINVAL;
2317 }
2318
Dustin Brown6f427922017-09-19 12:19:00 -07002319 hdd_set_idle_ps_config(hdd_ctx, false);
2320 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302321
Dustin Brown1fe30a82017-10-03 16:13:36 -07002322 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302323 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2324 mutex_unlock(&hdd_ctx->iface_change_lock);
2325 hdd_info("Driver modules already Enabled");
2326 EXIT();
2327 return 0;
2328 }
2329
Dustin Brown1fe30a82017-10-03 16:13:36 -07002330 hdd_ctx->start_modules_in_progress = true;
2331
Arun Khandavallifae92942016-08-01 13:31:08 +05302332 switch (hdd_ctx->driver_status) {
2333 case DRIVER_MODULES_UNINITIALIZED:
2334 unint = true;
2335 /* Fall through dont add break here */
2336 case DRIVER_MODULES_CLOSED:
2337 if (!reinit && !unint) {
2338 ret = pld_power_on(qdf_dev->dev);
2339 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002340 hdd_err("Failed to Powerup the device; errno: %d",
2341 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302342 goto release_lock;
2343 }
2344 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002345
2346 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2347 hdd_ctx->config->enable_fw_log);
2348
Arun Khandavallifae92942016-08-01 13:31:08 +05302349 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2350 qdf_dev->bus_type,
2351 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2352 HIF_ENABLE_TYPE_PROBE);
2353 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002354 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302355 goto power_down;
2356 }
2357
2358 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302359 if (!hif_ctx) {
2360 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002361 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302362 goto power_down;
2363 }
2364
Arun Khandavallifae92942016-08-01 13:31:08 +05302365 status = ol_cds_init(qdf_dev, hif_ctx);
2366 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002367 hdd_err("No Memory to Create BMI Context; status: %d",
2368 status);
2369 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302370 goto hif_close;
2371 }
2372
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002373 ret = hdd_update_config(hdd_ctx);
2374 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002375 hdd_err("Failed to update configuration; errno: %d",
2376 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002377 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002378 }
2379
gbian62edd7e2017-03-07 13:12:13 +08002380 hdd_update_cds_ac_specs_params(hdd_ctx);
2381
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302382 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002383 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002384 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002385 ret = qdf_status_to_os_return(status);
2386 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302387 }
2388
Mukul Sharma9d797a02017-01-05 20:26:03 +05302389 /* initalize components configurations after psoc open */
2390 ret = hdd_update_components_config(hdd_ctx);
2391 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002392 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302393 ret);
2394 goto close;
2395 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002396 status = cds_dp_open(hdd_ctx->hdd_psoc);
2397 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002398 hdd_err("Failed to Open cds post open; status: %d",
2399 status);
2400 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002401 goto close;
2402 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302403
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002404 /*
2405 * NAN compoenet requires certian operations like, open adapter,
2406 * close adapter, etc. to be initiated by HDD, for those
2407 * register HDD callbacks with UMAC's NAN componenet.
2408 */
2409 hdd_nan_register_callbacks(hdd_ctx);
2410
Arun Khandavallifae92942016-08-01 13:31:08 +05302411 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2412
Jeff Johnson3a280122017-09-13 07:42:00 -07002413 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302414 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002415 hdd_err("Failed to pre-enable CDS; status: %d", status);
2416 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002417 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302418 }
2419
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002420 hdd_register_policy_manager_callback(
2421 hdd_ctx->hdd_psoc);
2422
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302423 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302424 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302425
Arun Khandavallifae92942016-08-01 13:31:08 +05302426 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2427 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2428 hdd_ftm_mc_process_msg);
2429 break;
2430 }
2431 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002432 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302433 break;
2434 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302435
2436 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002437 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2438 if (ret) {
2439 hdd_err("HDD IPA UC reinit failed; errno: %d",
2440 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002441 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002442 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302443 }
2444
Arun Khandavallifae92942016-08-01 13:31:08 +05302445 /* Fall through dont add break here */
2446 case DRIVER_MODULES_OPENED:
2447 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002448 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002449 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002450 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302451 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302452 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2453 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002454 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302455 break;
2456 }
Dustin Browndca39692017-11-09 15:30:25 -08002457
2458 ret = hdd_configure_cds(hdd_ctx, adapter);
2459 if (ret) {
2460 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002461 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302462 }
Dustin Browndca39692017-11-09 15:30:25 -08002463
Komal Seelamf2136bb2016-09-28 18:30:44 +05302464 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302465 hdd_info("Driver Modules Successfully Enabled");
2466 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2467 break;
Arun Khandavallifae92942016-08-01 13:31:08 +05302468 default:
2469 hdd_err("WLAN start invoked in wrong state! :%d\n",
2470 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002471 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302472 goto release_lock;
2473 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302474 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302475 mutex_unlock(&hdd_ctx->iface_change_lock);
2476 EXIT();
2477 return 0;
2478
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002479post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002480 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002481
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002482cds_txrx_free:
2483 cds_dp_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302484close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002485 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002486 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302487
Dustin Brown28b17892017-10-10 13:29:38 -07002488deinit_config:
2489 cds_deinit_ini_config();
2490
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002491cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302492 ol_cds_free();
2493
2494hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002495 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2496 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302497power_down:
2498 if (!reinit && !unint)
2499 pld_power_off(qdf_dev->dev);
2500release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302501 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302502 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302503 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002504
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002505 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302506}
2507
Naveen Rawat910726a2017-03-06 11:42:51 -08002508#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002509static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002510{
2511 int ret = os_if_wifi_pos_register_nl();
2512
2513 if (ret)
2514 hdd_err("os_if_wifi_pos_register_nl failed");
2515
2516 return ret;
2517}
2518
2519static int hdd_deactivate_wifi_pos(void)
2520{
2521 int ret = os_if_wifi_pos_deregister_nl();
2522
2523 if (ret)
2524 hdd_err("os_if_wifi_pos_deregister_nl failed");
2525
2526 return ret;
2527}
2528
2529/**
2530 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2531 * @hdd_ctx: hdd context
2532 *
2533 * Return: status of operation
2534 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002535static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002536{
2537 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2538 struct hdd_config *cfg = hdd_ctx->config;
2539
2540 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2541 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2542 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2543 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2544 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2545 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2546 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2547 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2548}
2549#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002550static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002551{
2552 return oem_activate_service(hdd_ctx);
2553}
2554
2555static int hdd_deactivate_wifi_pos(void)
2556{
2557 return 0;
2558}
2559
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002560static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002561{
2562}
2563#endif
2564
Arun Khandavallifae92942016-08-01 13:31:08 +05302565/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002566 * __hdd_open() - HDD Open function
2567 * @dev: Pointer to net_device structure
2568 *
2569 * This is called in response to ifconfig up
2570 *
2571 * Return: 0 for success; non-zero for failure
2572 */
2573static int __hdd_open(struct net_device *dev)
2574{
Jeff Johnson9d295242017-08-29 14:39:48 -07002575 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002576 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002577 int ret;
2578
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002579 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302580 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002581 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002582
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302583 /* Nothing to be done if device is unloading */
2584 if (cds_is_driver_unloading()) {
2585 hdd_err("Driver is unloading can not open the hdd");
2586 return -EBUSY;
2587 }
2588
Dustin Brown01847752017-10-25 13:56:27 -07002589 if (cds_is_driver_recovering()) {
2590 hdd_err("WLAN is currently recovering; Please try again.");
2591 return -EBUSY;
2592 }
2593
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302594 mutex_lock(&hdd_init_deinit_lock);
2595
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302596 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2597
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302598 /*
2599 * This scenario can be hit in cases where in the wlan driver after
2600 * registering the netdevices and there is a failure in driver
2601 * initialization. So return error gracefully because the netdevices
2602 * will be de-registered as part of the load failure.
2603 */
2604
2605 if (!cds_is_driver_loaded()) {
2606 hdd_err("Failed to start the wlan driver!!");
2607 ret = -EIO;
2608 goto err_hdd_hdd_init_deinit_lock;
2609 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302610
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002611
Arun Khandavallifae92942016-08-01 13:31:08 +05302612 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2613 if (ret) {
2614 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302615 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302616 }
2617
2618
2619 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2620 ret = hdd_start_adapter(adapter);
2621 if (ret) {
2622 hdd_err("Failed to start adapter :%d",
2623 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302624 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302625 }
2626 }
2627
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002628 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2629 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002630 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002631 /* Enable TX queues only when we are connected */
2632 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302633 WLAN_START_ALL_NETIF_QUEUE,
2634 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002635 }
2636
Naveen Rawat286def52016-09-23 15:38:02 -07002637 /* Enable carrier and transmit queues for NDI */
2638 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002639 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002640 wlan_hdd_netif_queue_control(adapter,
2641 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2642 WLAN_CONTROL_PATH);
2643 }
2644
Naveen Rawat910726a2017-03-06 11:42:51 -08002645 hdd_populate_wifi_pos_cfg(hdd_ctx);
2646
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302647err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302648 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302649 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002650 return ret;
2651}
2652
Arun Khandavallifae92942016-08-01 13:31:08 +05302653
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002654/**
2655 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2656 * @dev: Pointer to net_device structure
2657 *
2658 * This is called in response to ifconfig up
2659 *
2660 * Return: 0 for success; non-zero for failure
2661 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002662static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002663{
2664 int ret;
2665
2666 cds_ssr_protect(__func__);
2667 ret = __hdd_open(dev);
2668 cds_ssr_unprotect(__func__);
2669
2670 return ret;
2671}
2672
2673/**
2674 * __hdd_stop() - HDD stop function
2675 * @dev: Pointer to net_device structure
2676 *
2677 * This is called in response to ifconfig down
2678 *
2679 * Return: 0 for success; non-zero for failure
2680 */
2681static int __hdd_stop(struct net_device *dev)
2682{
Jeff Johnson9d295242017-08-29 14:39:48 -07002683 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002684 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002685 int ret;
2686
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002687 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002688
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302689 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002690 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002691
2692 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302693 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002694 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002695
2696 /* Nothing to be done if the interface is not opened */
2697 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002698 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002699 return -ENODEV;
2700 }
2701
2702 /* Make sure the interface is marked as closed */
2703 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302704
2705 hdd_debug("Disabling Auto Power save timer");
2706 sme_ps_disable_auto_ps_timer(
2707 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002708 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302709
2710 /*
2711 * Disable TX on the interface, after this hard_start_xmit() will not
2712 * be called on that interface
2713 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002714 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2715 hdd_device_mode_to_string(adapter->device_mode),
2716 adapter->device_mode);
2717
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302718 wlan_hdd_netif_queue_control(adapter,
2719 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2720 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002721
2722 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002723 * NAN data interface is different in some sense. The traffic on NDI is
2724 * bursty in nature and depends on the need to transfer. The service
2725 * layer may down the interface after the usage and up again when
2726 * required. In some sense, the NDI is expected to be available
2727 * (like SAP) iface until NDI delete request is issued by the service
2728 * layer. Skip BSS termination and adapter deletion for NAN Data
2729 * interface (NDI).
2730 */
2731 if (WLAN_HDD_IS_NDI(adapter))
2732 return 0;
2733
Tushnim Bhattacharyya86294892017-10-25 16:29:11 -07002734 policy_mgr_check_and_stop_opportunistic_timer(hdd_ctx->hdd_psoc);
2735
Naveen Rawat286def52016-09-23 15:38:02 -07002736 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002737 * The interface is marked as down for outside world (aka kernel)
2738 * But the driver is pretty much alive inside. The driver needs to
2739 * tear down the existing connection on the netdev (session)
2740 * cleanup the data pipes and wait until the control plane is stabilized
2741 * for this interface. The call also needs to wait until the above
2742 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002743 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002744 * That is intentional to be able to scan if it is a STA/P2P interface
2745 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302746 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002747
2748 /* DeInit the adapter. This ensures datapath cleanup as well */
2749 hdd_deinit_adapter(hdd_ctx, adapter, true);
2750
Arun Khandavallifae92942016-08-01 13:31:08 +05302751
2752 /*
2753 * Find if any iface is up. If any iface is up then can't put device to
2754 * sleep/power save mode
2755 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302756 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002757 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07002758 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
2759 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302760 hdd_prevent_suspend_timeout(
2761 hdd_ctx->config->iface_change_wait_time,
2762 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302763 }
2764
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002765 EXIT();
2766 return 0;
2767}
2768
2769/**
2770 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2771 * @dev: pointer to net_device structure
2772 *
2773 * This is called in response to ifconfig down
2774 *
2775 * Return: 0 for success and error number for failure
2776 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002777static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002778{
2779 int ret;
2780
2781 cds_ssr_protect(__func__);
2782 ret = __hdd_stop(dev);
2783 cds_ssr_unprotect(__func__);
2784
2785 return ret;
2786}
2787
2788/**
2789 * __hdd_uninit() - HDD uninit function
2790 * @dev: Pointer to net_device structure
2791 *
2792 * This is called during the netdev unregister to uninitialize all data
2793 * associated with the device
2794 *
2795 * Return: None
2796 */
2797static void __hdd_uninit(struct net_device *dev)
2798{
Jeff Johnson9d295242017-08-29 14:39:48 -07002799 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002800 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002801
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002802 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002803
2804 do {
2805 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002806 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002807 break;
2808 }
2809
Jeff Johnson399c6272017-08-30 10:51:00 -07002810 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2811 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002812 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002813 break;
2814 }
2815
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002816 if (dev != adapter->dev)
2817 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002818
Jeff Johnson399c6272017-08-30 10:51:00 -07002819 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002820
2821 /* after uninit our adapter structure will no longer be valid */
2822 adapter->dev = NULL;
2823 adapter->magic = 0;
2824 } while (0);
2825
2826 EXIT();
2827}
2828
2829/**
2830 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2831 * @dev: pointer to net_device structure
2832 *
2833 * This is called during the netdev unregister to uninitialize all data
2834 * associated with the device
2835 *
2836 * Return: none
2837 */
2838static void hdd_uninit(struct net_device *dev)
2839{
2840 cds_ssr_protect(__func__);
2841 __hdd_uninit(dev);
2842 cds_ssr_unprotect(__func__);
2843}
2844
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002845static int hdd_open_cesium_nl_sock(void)
2846{
2847#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2848 struct netlink_kernel_cfg cfg = {
2849 .groups = WLAN_NLINK_MCAST_GRP_ID,
2850 .input = NULL
2851 };
2852#endif
2853 int ret = 0;
2854
2855#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2856 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2857#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2858 THIS_MODULE,
2859#endif
2860 &cfg);
2861#else
2862 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2863 WLAN_NLINK_MCAST_GRP_ID,
2864 NULL, NULL, THIS_MODULE);
2865#endif
2866
2867 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002868 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002869 ret = -ECONNREFUSED;
2870 }
2871
2872 return ret;
2873}
2874
2875static void hdd_close_cesium_nl_sock(void)
2876{
2877 if (NULL != cesium_nl_srv_sock) {
2878 netlink_kernel_release(cesium_nl_srv_sock);
2879 cesium_nl_srv_sock = NULL;
2880 }
2881}
2882
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002883/**
2884 * __hdd_set_mac_address() - set the user specified mac address
2885 * @dev: Pointer to the net device.
2886 * @addr: Pointer to the sockaddr.
2887 *
2888 * This function sets the user specified mac address using
2889 * the command ifconfig wlanX hw ether <mac adress>.
2890 *
2891 * Return: 0 for success, non zero for failure
2892 */
2893static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2894{
Jeff Johnson9d295242017-08-29 14:39:48 -07002895 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002896 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002897 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302898 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002899 int ret;
2900
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002901 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002902
2903 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2904 ret = wlan_hdd_validate_context(hdd_ctx);
2905 if (0 != ret)
2906 return ret;
2907
Jeff Johnson1e851a12017-10-28 14:36:12 -07002908 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002909 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2910
2911 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302912 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002913}
2914
2915/**
2916 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2917 * function from SSR
2918 * @dev: pointer to net_device structure
2919 * @addr: Pointer to the sockaddr
2920 *
2921 * This function sets the user specified mac address using
2922 * the command ifconfig wlanX hw ether <mac adress>.
2923 *
2924 * Return: 0 for success.
2925 */
2926static int hdd_set_mac_address(struct net_device *dev, void *addr)
2927{
2928 int ret;
2929
2930 cds_ssr_protect(__func__);
2931 ret = __hdd_set_mac_address(dev, addr);
2932 cds_ssr_unprotect(__func__);
2933
2934 return ret;
2935}
2936
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002937uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002938{
2939 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002940
Anurag Chouhan6d760662016-02-20 16:05:43 +05302941 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002942 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2943 break;
2944 }
2945
Anurag Chouhan6d760662016-02-20 16:05:43 +05302946 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947 return NULL;
2948
2949 hdd_ctx->config->intfAddrMask |= (1 << i);
2950 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2951}
2952
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07002953void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
2954 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002955{
2956 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002957
Anurag Chouhan6d760662016-02-20 16:05:43 +05302958 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002959 if (!memcmp(releaseAddr,
2960 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2961 6)) {
2962 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2963 break;
2964 }
2965 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002966}
2967
2968#ifdef WLAN_FEATURE_PACKET_FILTERING
2969/**
2970 * __hdd_set_multicast_list() - set the multicast address list
2971 * @dev: Pointer to the WLAN device.
2972 * @skb: Pointer to OS packet (sk_buff).
2973 *
2974 * This funciton sets the multicast address list.
2975 *
2976 * Return: None
2977 */
2978static void __hdd_set_multicast_list(struct net_device *dev)
2979{
Jeff Johnson9d295242017-08-29 14:39:48 -07002980 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002981 int i = 0, status;
2982 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002983 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302984 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2985 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2986 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002987
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002988 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302989 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302990 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302991
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302993 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302994 goto out;
2995
Dustin Brownc788acb2017-08-01 17:43:51 -07002996 status = hdd_validate_adapter(adapter);
2997 if (status)
2998 goto out;
2999
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303000 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3001 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003002 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303003 goto out;
3004 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003005
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303006 /* Delete already configured multicast address list */
3007 if (adapter->mc_addr_list.mc_cnt > 0) {
3008 hdd_info("clear previously configured MC address list");
3009 hdd_disable_and_flush_mc_addr_list(adapter,
3010 pmo_mc_list_change_notify);
3011 }
3012
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003013 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003014 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303015 hdd_disable_and_flush_mc_addr_list(adapter,
3016 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003017 } else {
3018 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303019 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003020 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303021 pmo_ucfg_max_mc_addr_supported(psoc));
3022 hdd_disable_and_flush_mc_addr_list(adapter,
3023 pmo_mc_list_change_notify);
3024 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003025 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003026 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003027 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303028 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029 if (i == mc_count)
3030 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303031 memset(&(mc_list_request->mc_addr[i].bytes),
3032 0, ETH_ALEN);
3033 memcpy(&(mc_list_request->mc_addr[i].bytes),
3034 ha->addr, ETH_ALEN);
3035 hdd_info("mlist[%d] = %pM", i,
3036 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003037 i++;
3038 }
3039 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303040
3041 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003042 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303043 mc_list_request->count = mc_count;
3044 status = hdd_cache_mc_addr_list(mc_list_request);
3045 if (status == 0) {
3046 hdd_enable_mc_addr_filtering(adapter,
3047 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003048 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303049 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003050 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303051out:
3052 if (mc_list_request)
3053 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303054 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003055}
3056
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303057
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003058/**
3059 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3060 * @dev: pointer to net_device
3061 *
3062 * Return: none
3063 */
3064static void hdd_set_multicast_list(struct net_device *dev)
3065{
3066 cds_ssr_protect(__func__);
3067 __hdd_set_multicast_list(dev);
3068 cds_ssr_unprotect(__func__);
3069}
3070#endif
3071
3072/**
3073 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3074 * @dev: Pointer to the WLAN device.
3075 * @skb: Pointer to OS packet (sk_buff).
3076 *
3077 * This function is registered with the Linux OS for network
3078 * core to decide which queue to use first.
3079 *
3080 * Return: ac, Queue Index/access category corresponding to UP in IP header
3081 */
3082static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3083#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3084 , void *accel_priv
3085#endif
3086#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3087 , select_queue_fallback_t fallback
3088#endif
3089)
3090{
3091 return hdd_wmm_select_queue(dev, skb);
3092}
3093
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003094static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003095 .ndo_open = hdd_open,
3096 .ndo_stop = hdd_stop,
3097 .ndo_uninit = hdd_uninit,
3098 .ndo_start_xmit = hdd_hard_start_xmit,
3099 .ndo_tx_timeout = hdd_tx_timeout,
3100 .ndo_get_stats = hdd_get_stats,
3101 .ndo_do_ioctl = hdd_ioctl,
3102 .ndo_set_mac_address = hdd_set_mac_address,
3103 .ndo_select_queue = hdd_select_queue,
3104#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106#endif
3107};
3108
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003109/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003110static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003111 .ndo_open = hdd_mon_open,
3112 .ndo_stop = hdd_stop,
3113 .ndo_get_stats = hdd_get_stats,
3114};
3115
3116/**
3117 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003118 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003119 * Return: None
3120 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003121void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003123 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003124 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003125 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003126 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003127}
3128
3129/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003130 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3131 * @hdd_ctx: global hdd context
3132 * @macAddr: mac address to assign to the interface
3133 * @name: User-visible name of the interface
3134 *
3135 * hdd adapter pointer would point to the netdev->priv space, this function
3136 * would retrive the pointer, and setup the hdd adapter configuration.
3137 *
3138 * Return: the pointer to hdd adapter, otherwise NULL
3139 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003140static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003141 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003142 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003143 const char *name)
3144{
Jeff Johnson5505db82017-11-02 21:19:23 -07003145 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003146 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003147 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 /*
3149 * cfg80211 initialization and registration....
3150 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003151 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003152#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3153 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003155 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3156 hdd_mon_mode_ether_setup : ether_setup),
3157 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003158
Jeff Johnson5505db82017-11-02 21:19:23 -07003159 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003160
3161 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003162 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003163
Jeff Johnson9d295242017-08-29 14:39:48 -07003164 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003165 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303166 qdf_mem_set(sta_ctx->conn_info.staId,
3167 sizeof(sta_ctx->conn_info.staId),
3168 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003169 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003170 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003171 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003172 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173
3174 init_completion(&adapter->session_open_comp_var);
3175 init_completion(&adapter->session_close_comp_var);
3176 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303177 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178 init_completion(&adapter->linkup_event_var);
3179 init_completion(&adapter->cancel_rem_on_chan_var);
3180 init_completion(&adapter->rem_on_chan_ready_event);
3181 init_completion(&adapter->sta_authorized_event);
3182 init_completion(&adapter->offchannel_tx_event);
3183 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003184 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003185 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303186 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003187
3188 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003189 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003191 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192
Jeff Johnson5505db82017-11-02 21:19:23 -07003193 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003195 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003196 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003197 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198
3199 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003200 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003201 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003202 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003203
Jeff Johnson5505db82017-11-02 21:19:23 -07003204 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003205
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206 hdd_set_station_ops(adapter->dev);
3207
Jeff Johnson5505db82017-11-02 21:19:23 -07003208 hdd_dev_setup_destructor(dev);
3209 dev->ieee80211_ptr = &adapter->wdev;
3210 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003212 adapter->wdev.netdev = dev;
3213 /* set dev's parent to underlying device */
3214 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303216 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303218 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003219 }
3220
3221 return adapter;
3222}
3223
Jeff Johnson9d295242017-08-29 14:39:48 -07003224static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003225{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003226 struct net_device *dev = adapter->dev;
3227 int ret;
3228
3229 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003230
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003231 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003232 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3233
3234 ret = dev_alloc_name(dev, dev->name);
3235 if (ret < 0) {
3236 hdd_err(
3237 "unable to get dev name: %s, err = 0x%x",
3238 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303239 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003240 }
3241 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003242
3243 ret = register_netdevice(dev);
3244 if (ret) {
3245 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3246 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303247 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003248 }
3249 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003250 ret = register_netdev(dev);
3251 if (ret) {
3252 hdd_err("register_netdev(%s) failed, err = 0x%x",
3253 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303254 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003255 }
3256 }
3257 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3258
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003259 EXIT();
3260
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303261 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003262}
3263
Krunal Sonib51eec72017-11-20 21:53:01 -08003264QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003265{
Krunal Sonib51eec72017-11-20 21:53:01 -08003266 struct hdd_adapter *adapter;
3267 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268
Krunal Sonib51eec72017-11-20 21:53:01 -08003269 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3270 if (!hdd_ctx) {
3271 hdd_err("Invalid HDD_CTX");
3272 return QDF_STATUS_E_FAILURE;
3273 }
3274
3275 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3276 if (NULL == adapter) {
3277 hdd_err("NULL adapter");
3278 return QDF_STATUS_E_INVAL;
3279 }
3280 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3281 complete(&adapter->session_open_comp_var);
3282 hdd_debug("session %d opened", adapter->session_id);
3283
3284 return QDF_STATUS_SUCCESS;
3285}
3286
3287QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3288{
3289 struct hdd_adapter *adapter;
3290 struct hdd_context *hdd_ctx;
3291
3292 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3293 if (!hdd_ctx) {
3294 hdd_err("Invalid HDD_CTX");
3295 return QDF_STATUS_E_FAILURE;
3296 }
3297
3298 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003299 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003300 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303301 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003302 }
3303
3304 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003305 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303306 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307 }
3308
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003309 /*
3310 * For NAN Data interface, the close session results in the final
3311 * indication to the userspace
3312 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003313 if (adapter->device_mode == QDF_NDI_MODE)
3314 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003315
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003316 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3317
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003318 /*
3319 * We can be blocked while waiting for scheduled work to be
3320 * flushed, and the adapter structure can potentially be freed, in
3321 * which case the magic will have been reset. So make sure the
3322 * magic is still good, and hence the adapter structure is still
3323 * valid, before signaling completion
3324 */
3325 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3326 complete(&adapter->session_close_comp_var);
3327
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303328 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003329}
3330
Jeff Johnson9d295242017-08-29 14:39:48 -07003331int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003332{
Dustin Brownd28772b2017-03-17 14:16:07 -07003333 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003334
Dustin Brownd28772b2017-03-17 14:16:07 -07003335 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003336 if (QDF_IS_STATUS_ERROR(status))
3337 return qdf_status_to_os_return(status);
3338
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003339 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003340 if (QDF_IS_STATUS_ERROR(status))
3341 return qdf_status_to_os_return(status);
3342
3343 if (wma_capability_enhanced_mcast_filter())
3344 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3345 else
3346 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003347
3348 return qdf_status_to_os_return(status);
3349}
3350
Jeff Johnson9d295242017-08-29 14:39:48 -07003351int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003352{
3353 QDF_STATUS status;
3354 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003355 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003356 unsigned long rc;
3357
Jeff Johnson1b780e42017-10-31 14:11:45 -07003358 hdd_info("destroying vdev %d", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003359
3360 /* vdev created sanity check */
3361 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003362 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003363 return -EINVAL;
3364 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003365 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003366 /*
3367 * In SSR case, there is no need to destroy vdev in firmware since
3368 * it has already asserted. vdev can be released directly.
3369 */
Krunal Sonib51eec72017-11-20 21:53:01 -08003370 if (cds_is_driver_recovering()) {
3371 hdd_debug("SSR: silently release the vdev for session-id: %d",
3372 adapter->session_id);
3373 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Yue Maf9782842017-05-08 12:49:49 -07003374 goto release_vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08003375 }
Yue Maf9782842017-05-08 12:49:49 -07003376
Dustin Brownd28772b2017-03-17 14:16:07 -07003377 /* close sme session (destroy vdev in firmware via legacy API) */
3378 INIT_COMPLETION(adapter->session_close_comp_var);
3379 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003380 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003381 if (QDF_IS_STATUS_ERROR(status)) {
3382 hdd_err("failed to close sme session: %d", status);
3383 return qdf_status_to_os_return(status);
3384 }
3385
3386 /* block on a completion variable until sme session is closed */
3387 rc = wait_for_completion_timeout(
3388 &adapter->session_close_comp_var,
3389 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3390 if (!rc) {
3391 hdd_err("timed out waiting for close sme session: %ld", rc);
3392 if (adapter->device_mode == QDF_NDI_MODE)
3393 hdd_ndp_session_end_handler(adapter);
3394 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3395 return -ETIMEDOUT;
3396 }
Yue Maf9782842017-05-08 12:49:49 -07003397release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003398 /* do vdev logical destroy via objmgr */
3399 errno = hdd_objmgr_destroy_vdev(adapter);
3400 if (errno) {
3401 hdd_err("failed to destroy objmgr vdev: %d", errno);
3402 return errno;
3403 }
3404
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003405 /* now that sme session is closed, allow physical vdev destroy */
3406 errno = hdd_objmgr_release_vdev(adapter);
3407 if (errno) {
3408 hdd_err("failed to release objmgr vdev: %d", errno);
3409 return errno;
3410 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003411 hdd_info("vdev destroyed successfully");
3412
3413 return 0;
3414}
3415
Krunal Sonib51eec72017-11-20 21:53:01 -08003416static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3417 struct sme_session_params *session_param,
3418 csr_roam_completeCallback callback,
3419 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003420{
Dustin Brownd28772b2017-03-17 14:16:07 -07003421 uint32_t type;
3422 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003423 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003424
3425 /* determine vdev (sub)type */
3426 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303427 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003428 hdd_err("failed to get vdev type: %d", status);
3429 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003431 session_param->sme_session_id = adapter->session_id;
3432 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3433 session_param->type_of_persona = type;
3434 session_param->subtype_of_persona = sub_type;
3435 session_param->session_open_cb = hdd_sme_open_session_callback;
3436 session_param->session_close_cb = hdd_sme_close_session_callback;
3437 session_param->callback = callback;
3438 session_param->callback_ctx = callback_ctx;
3439
3440 return 0;
3441}
3442
3443int hdd_vdev_create(struct hdd_adapter *adapter,
3444 csr_roam_completeCallback callback, void *ctx)
3445{
3446 QDF_STATUS status;
3447 int errno;
3448 struct hdd_context *hdd_ctx;
3449 struct sme_session_params sme_session_params = {0};
3450 unsigned long rc;
3451
3452 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003453
3454 /* do vdev create via objmgr */
3455 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003456 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003457 if (errno) {
3458 hdd_err("failed to create objmgr vdev: %d", errno);
3459 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003461
3462 /* Open a SME session (prepare vdev in firmware via legacy API) */
3463 INIT_COMPLETION(adapter->session_open_comp_var);
Krunal Sonib51eec72017-11-20 21:53:01 -08003464 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3465 callback, ctx);
3466 if (errno) {
3467 hdd_err("failed to populating SME params");
3468 goto objmgr_vdev_destroy_procedure;
3469 }
3470
3471 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003472 if (QDF_IS_STATUS_ERROR(status)) {
3473 hdd_err("failed to open sme session: %d", status);
3474 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003475 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003476 }
3477
3478 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 rc = wait_for_completion_timeout(
3480 &adapter->session_open_comp_var,
3481 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3482 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003483 hdd_err("timed out waiting for open sme session: %ld", rc);
3484 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303485 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Krunal Soni4a020c72017-10-30 20:58:40 -07003486 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003487 }
3488
3489 /* firmware ready for component communication, raise vdev_ready event */
3490 errno = hdd_vdev_ready(adapter);
3491 if (errno) {
3492 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003493 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003494 }
3495
Jeff Johnson1b780e42017-10-31 14:11:45 -07003496 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003497
3498 return 0;
3499
3500 /*
3501 * Due to legacy constraints, we need to destroy in the same order as
3502 * create. So, split error handling into 2 cases to accommodate.
3503 */
3504
Krunal Soni4a020c72017-10-30 20:58:40 -07003505objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003506 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003507
3508 return errno;
3509
Krunal Soni4a020c72017-10-30 20:58:40 -07003510hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003511 QDF_BUG(!hdd_vdev_destroy(adapter));
3512
3513 return errno;
3514}
3515
Jeff Johnson9d295242017-08-29 14:39:48 -07003516QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003517{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003518 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003519 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003520 QDF_STATUS status;
3521 int ret_val;
3522
Dustin Brownd28772b2017-03-17 14:16:07 -07003523 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3524 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3525 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003526 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003527
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003529 status = hdd_register_wext(adapter->dev);
3530 if (QDF_IS_STATUS_ERROR(status)) {
3531 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003532 goto error_register_wext;
3533 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003534 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003535
Jeff Johnsond377dce2017-10-04 10:32:42 -07003536 qdf_mem_set(sta_ctx->conn_info.staId,
3537 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303538
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003539 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003540 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003541 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003543 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003544 hdd_ctx->config->OperatingChannel;
3545
3546 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003547 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003548
3549 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303550 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003551 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003552 status, status);
3553 goto error_init_txrx;
3554 }
3555
3556 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3557
3558 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303559 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003560 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003561 status, status);
3562 goto error_wmm_init;
3563 }
3564
3565 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3566
Jeff Johnson1b780e42017-10-31 14:11:45 -07003567 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003568 WMI_PDEV_PARAM_BURST_ENABLE,
3569 hdd_ctx->config->enableSifsBurst,
3570 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003571 if (ret_val)
3572 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003573
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303574 /*
3575 * In case of USB tethering, LRO is disabled. If SSR happened
3576 * during that time, then as part of SSR init, do not enable
3577 * the LRO again. Keep the LRO state same as before SSR.
3578 */
3579 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003580 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303581
3582 /* rcpi info initialization */
3583 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3584
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303585 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003586
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587error_wmm_init:
3588 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3589 hdd_deinit_tx_rx(adapter);
3590error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003591 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003593 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003595 return status;
3596}
3597
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303598/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003599 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303600 * @hdd_ctx: global hdd context
3601 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003602 * @rtnl_held: Used to indicate whether or not the caller is holding
3603 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303604 *
3605 * This function De-initializes the STA/P2P/OCB adapter.
3606 *
3607 * Return: None.
3608 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003609static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003610 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003611 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303612{
3613 ENTER_DEV(adapter->dev);
3614
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303615 if (adapter->dev) {
3616 if (rtnl_held)
3617 adapter->dev->wireless_handlers = NULL;
3618 else {
3619 rtnl_lock();
3620 adapter->dev->wireless_handlers = NULL;
3621 rtnl_unlock();
3622 }
3623 }
3624
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303625 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3626 hdd_deinit_tx_rx(adapter);
3627 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3628 }
3629
3630 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3631 hdd_wmm_adapter_close(adapter);
3632 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3633 }
3634
Krunal Sonib51eec72017-11-20 21:53:01 -08003635
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303636 EXIT();
3637}
3638
Krunal Sonib51eec72017-11-20 21:53:01 -08003639void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
3640 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 bool rtnl_held)
3642{
3643 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303644
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003646 case QDF_STA_MODE:
3647 case QDF_P2P_CLIENT_MODE:
3648 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08003649 case QDF_IBSS_MODE:
3650 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003651 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003652 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653 break;
3654 }
3655
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003656 case QDF_SAP_MODE:
3657 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003658 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003659 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 break;
3661 }
3662
3663 default:
3664 break;
3665 }
3666
3667 EXIT();
3668}
3669
Jeff Johnson9d295242017-08-29 14:39:48 -07003670static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003671 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003672{
Jeff Johnson5505db82017-11-02 21:19:23 -07003673 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674
3675 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003676 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003678 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679 return;
3680 }
3681
Rajeev Kumardca5f812016-02-04 17:28:06 -08003682 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303683
3684 if (adapter->scan_info.default_scan_ies) {
3685 qdf_mem_free(adapter->scan_info.default_scan_ies);
3686 adapter->scan_info.default_scan_ies = NULL;
3687 }
3688
Yue Ma9e89e832017-11-14 11:40:23 -08003689 hdd_adapter_runtime_suspend_deinit(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303690
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003691 /*
3692 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3693 * the driver is almost closed and cannot handle either control
3694 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003695 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3696 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003697 * is not right. Setting this flag helps hdd_stop() to recognize that
3698 * the interface is closed and restricts any operations on that
3699 */
3700 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3701
3702 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003703 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003704 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003705 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003706 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707 /*
3708 * Note that the adapter is no longer valid at this point
3709 * since the memory has been reclaimed
3710 */
3711 }
3712}
3713
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003714static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003715 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003716{
3717 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003718 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303719 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003720
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003721 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303722 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003723 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003724 if (adapter
Jeff Johnson1e851a12017-10-28 14:36:12 -07003725 && !qdf_mem_cmp(adapter->mac_addr.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003726 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303727 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003728 }
3729 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3730 adapterNode = pNext;
3731 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303732 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003733}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003734
Arun Khandavalli2358d522016-05-16 18:05:37 +05303735#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3736/**
3737 * hdd_set_fw_log_params() - Set log parameters to FW
3738 * @hdd_ctx: HDD Context
3739 * @adapter: HDD Adapter
3740 *
3741 * This function set the FW Debug log level based on the INI.
3742 *
3743 * Return: None
3744 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003745static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003746 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303747{
3748 uint8_t count = 0, numentries = 0,
3749 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3750 uint32_t value = 0;
3751 int ret;
3752
Arun Khandavallifae92942016-08-01 13:31:08 +05303753 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3754 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003755 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303756 return;
3757 }
3758
Arun Khandavallifae92942016-08-01 13:31:08 +05303759 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303760 hdd_ctx->fw_log_settings.dl_type =
3761 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003762 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303763 WMI_DBGLOG_TYPE,
3764 hdd_ctx->config->enableFwLogType,
3765 DBG_CMD);
3766 if (ret != 0)
3767 hdd_err("Failed to enable FW log type ret %d",
3768 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303769
3770 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303771 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003772 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303773 WMI_DBGLOG_LOG_LEVEL,
3774 hdd_ctx->config->enableFwLogLevel,
3775 DBG_CMD);
3776 if (ret != 0)
3777 hdd_err("Failed to enable FW log level ret %d",
3778 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303779
3780 hdd_string_to_u8_array(
3781 hdd_ctx->config->enableFwModuleLogLevel,
3782 moduleloglevel,
3783 &numentries,
3784 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3785
3786 while (count < numentries) {
3787 /*
3788 * FW module log level input string looks like
3789 * below:
3790 * gFwDebugModuleLoglevel=<FW Module ID>,
3791 * <Log Level>,...
3792 * For example:
3793 * gFwDebugModuleLoglevel=
3794 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3795 * Above input string means :
3796 * For FW module ID 1 enable log level 0
3797 * For FW module ID 2 enable log level 1
3798 * For FW module ID 3 enable log level 2
3799 * For FW module ID 4 enable log level 3
3800 * For FW module ID 5 enable log level 4
3801 * For FW module ID 6 enable log level 5
3802 * For FW module ID 7 enable log level 6
3803 */
3804
Nishank Aggarwale239d962017-03-03 12:26:02 +05303805 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3806 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3807 hdd_err("Module id %d and dbglog level %d input length is more than max",
3808 moduleloglevel[count],
3809 moduleloglevel[count + 1]);
3810 return;
3811 }
3812
3813 value = moduleloglevel[count] << 16;
3814 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07003815 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303816 WMI_DBGLOG_MOD_LOG_LEVEL,
3817 value, DBG_CMD);
3818 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303819 hdd_err("Failed to enable FW module log level %d ret %d",
3820 value, ret);
3821
3822 count += 2;
3823 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303824
Arun Khandavalli2358d522016-05-16 18:05:37 +05303825}
3826#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003827static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003828 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303829{
3830}
3831
3832#endif
3833
3834/**
3835 * hdd_set_fw_params() - Set parameters to firmware
3836 * @adapter: HDD adapter
3837 *
3838 * This function Sets various parameters to fw once the
3839 * adapter is started.
3840 *
3841 * Return: 0 on success or errno on failure
3842 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003843int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303844{
3845 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003846 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303847
3848 ENTER_DEV(adapter->dev);
3849
3850 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3851 if (!hdd_ctx)
3852 return -EINVAL;
3853
Dustin Brown732ab9c2017-06-15 13:24:09 -07003854 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3855 hdd_debug("FTM Mode is active; nothing to do");
3856 return 0;
3857 }
3858
Jeff Johnson1b780e42017-10-31 14:11:45 -07003859 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303860 WMI_PDEV_PARAM_DTIM_SYNTH,
3861 hdd_ctx->config->enable_lprx, PDEV_CMD);
3862 if (ret) {
3863 hdd_err("Failed to set LPRx");
3864 goto error;
3865 }
3866
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303867 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003868 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303869 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3870 hdd_ctx->config->upper_brssi_thresh);
3871
Jeff Johnson1b780e42017-10-31 14:11:45 -07003872 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303873 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3874 hdd_ctx->config->lower_brssi_thresh);
3875
Jeff Johnson1b780e42017-10-31 14:11:45 -07003876 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303877 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3878 hdd_ctx->config->enable_dtim_1chrx);
3879 }
3880
Dustin Brown732ab9c2017-06-15 13:24:09 -07003881 if (hdd_ctx->config->enable2x2) {
3882 hdd_debug("configuring 2x2 mode fw params");
3883
Jeff Johnson1b780e42017-10-31 14:11:45 -07003884 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003885 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3886 hdd_ctx->config->enable_cck_tx_fir_override,
3887 PDEV_CMD);
3888 if (ret) {
3889 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3890 ret);
3891 goto error;
3892 }
3893 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303894#define HDD_DTIM_1CHAIN_RX_ID 0x5
3895#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003896 hdd_debug("configuring 1x1 mode fw params");
3897
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003898 /*
3899 * Disable DTIM 1 chain Rx when in 1x1,
3900 * we are passing two value
3901 * as param_id << 29 | param_value.
3902 * Below param_value = 0(disable)
3903 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003904 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003905 WMI_STA_SMPS_PARAM_CMDID,
3906 HDD_DTIM_1CHAIN_RX_ID <<
3907 HDD_SMPS_PARAM_VALUE_S,
3908 VDEV_CMD);
3909 if (ret) {
3910 hdd_err("DTIM 1 chain set failed %d", ret);
3911 goto error;
3912 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303913
Jeff Johnson1b780e42017-10-31 14:11:45 -07003914 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003915 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3916 hdd_ctx->config->txchainmask1x1,
3917 PDEV_CMD);
3918 if (ret) {
3919 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3920 ret);
3921 goto error;
3922 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303923
Jeff Johnson1b780e42017-10-31 14:11:45 -07003924 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003925 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3926 hdd_ctx->config->rxchainmask1x1,
3927 PDEV_CMD);
3928 if (ret) {
3929 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3930 ret);
3931 goto error;
3932 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303933#undef HDD_DTIM_1CHAIN_RX_ID
3934#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003935 }
3936
Jeff Johnson1b780e42017-10-31 14:11:45 -07003937 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003938 WMI_PDEV_PARAM_HYST_EN,
3939 hdd_ctx->config->enableMemDeepSleep,
3940 PDEV_CMD);
3941 if (ret) {
3942 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3943 goto error;
3944 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303945
Jeff Johnson1b780e42017-10-31 14:11:45 -07003946 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003947 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3948 hdd_ctx->config->rts_profile,
3949 VDEV_CMD);
3950 if (ret) {
3951 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3952 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303953 }
3954
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003955 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3956
Jeff Johnson1b780e42017-10-31 14:11:45 -07003957 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003958 GEN_VDEV_PARAM_AMSDU,
3959 hdd_ctx->config->max_amsdu_num,
3960 GEN_CMD);
3961 if (ret != 0) {
3962 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3963 goto error;
3964 }
3965
Arun Khandavalli2358d522016-05-16 18:05:37 +05303966 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303967 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003968
Arun Khandavalli2358d522016-05-16 18:05:37 +05303969 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303970
Arun Khandavalli2358d522016-05-16 18:05:37 +05303971error:
3972 return -EINVAL;
3973}
3974
Ryan Hsu07495ea2016-01-21 15:25:39 -08003975/**
3976 * hdd_open_adapter() - open and setup the hdd adatper
3977 * @hdd_ctx: global hdd context
3978 * @session_type: type of the interface to be created
3979 * @iface_name: User-visible name of the interface
3980 * @macAddr: MAC address to assign to the interface
3981 * @name_assign_type: the name of assign type of the netdev
3982 * @rtnl_held: the rtnl lock hold flag
3983 *
3984 * This function open and setup the hdd adpater according to the device
3985 * type request, assign the name, the mac address assigned, and then prepared
3986 * the hdd related parameters, queue, lock and ready to start.
3987 *
3988 * Return: the pointer of hdd adapter, otherwise NULL.
3989 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003990struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003992 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003993 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994{
Jeff Johnson9d295242017-08-29 14:39:48 -07003995 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303997 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998
3999 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4000 /*
4001 * Max limit reached on the number of vdevs configured by the
4002 * host. Return error
4003 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304004 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4005 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006 return NULL;
4007 }
4008
4009 if (macAddr == NULL) {
4010 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304011 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012 return NULL;
4013 }
4014 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304015 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304016 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4017 " already exists",
4018 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 return NULL;
4020 }
4021
4022 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004023 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024 /* Reset locally administered bit if the device mode is STA */
4025 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304026 hdd_info("locally administered bit reset in sta mode: "
4027 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004028 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004029 case QDF_P2P_CLIENT_MODE:
4030 case QDF_P2P_DEVICE_MODE:
4031 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004032 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304033 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004034 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4035 name_assign_type,
4036 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004037
4038 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304039 hdd_err("failed to allocate adapter for session %d",
4040 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041 return NULL;
4042 }
4043
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004044 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004045 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004046 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004047 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304048 else if (QDF_MONITOR_MODE == session_type)
4049 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050 else
4051 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4052
4053 adapter->device_mode = session_type;
4054
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004055
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056 /*
4057 * Workqueue which gets scheduled in IPv4 notification
4058 * callback
4059 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004060 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004062
4063#ifdef WLAN_NS_OFFLOAD
4064 /*
4065 * Workqueue which gets scheduled in IPv6
4066 * notification callback.
4067 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004068 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069 hdd_ipv6_notifier_work_queue);
4070#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004071 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004072 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004073 goto err_deinit_adapter_runtime_pm;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004074
4075 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004076 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304078 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4079 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304080
Ravi Joshi1a292562017-05-18 16:28:54 -07004081 /* Initialize NAN Data Interface */
4082 if (QDF_NDI_MODE == session_type) {
4083 status = hdd_init_nan_data_mode(adapter);
4084 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004085 goto err_deinit_adapter_runtime_pm;
Ravi Joshi1a292562017-05-18 16:28:54 -07004086 }
4087
4088 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004089
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004090 case QDF_P2P_GO_MODE:
4091 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004092 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4093 name_assign_type,
4094 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004096 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304097 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098 return NULL;
4099 }
4100
4101 adapter->wdev.iftype =
4102 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004103 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104 NL80211_IFTYPE_P2P_GO;
4105 adapter->device_mode = session_type;
4106
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004107 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004108 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004110
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004111 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304113 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4114 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304115
4116 /*
4117 * Workqueue which gets scheduled in IPv4 notification
4118 * callback
4119 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004120 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304121 hdd_ipv4_notifier_work_queue);
4122
4123#ifdef WLAN_NS_OFFLOAD
4124 /*
4125 * Workqueue which gets scheduled in IPv6
4126 * notification callback.
4127 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004128 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304129 hdd_ipv6_notifier_work_queue);
4130#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004131 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304132 case QDF_FTM_MODE:
4133 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4134 name_assign_type,
4135 "wlan0");
4136 if (NULL == adapter) {
4137 hdd_err("Failed to allocate adapter for FTM mode");
4138 return NULL;
4139 }
4140 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4141 adapter->device_mode = session_type;
4142 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004143 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004144 goto err_deinit_adapter_runtime_pm;
Krunal Sonib51eec72017-11-20 21:53:01 -08004145
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304146 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004147 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304148 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304149 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4150 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304151 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004153 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304154 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004155 return NULL;
4156 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004157
hqueaa33ee2017-05-04 17:56:35 +08004158 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4159
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304160 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004161 /* Add it to the hdd's session list. */
4162 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304163 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004164 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304165 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004166 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004167 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4169 }
4170 }
4171
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304172 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004173 if (NULL != adapter) {
4174 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4175 adapter = NULL;
4176 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004177 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304178 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004179
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004180 return NULL;
4181 }
4182
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304183 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004184 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4185 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004187 /* Adapter successfully added. Increment the vdev count */
4188 hdd_ctx->current_intf_count++;
4189
Jeff Johnson5880d792016-08-15 13:32:30 -07004190 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004191 hdd_ctx->current_intf_count);
4192
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004193 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004194 }
4195
Rajeev Kumardca5f812016-02-04 17:28:06 -08004196 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004197 hdd_err("Interface %s wow debug_fs init failed",
4198 netdev_name(adapter->dev));
4199
4200 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4201 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004202
4203 return adapter;
4204
Yue Ma9e89e832017-11-14 11:40:23 -08004205err_deinit_adapter_runtime_pm:
4206 /*
4207 * For certain error cases that hdd_alloc_station_adapter()
4208 * is used to allocate the adapter.
4209 */
4210 hdd_adapter_runtime_suspend_deinit(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004211err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004212 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304213 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004214
4215 return NULL;
4216}
4217
Jeff Johnson9d295242017-08-29 14:39:48 -07004218QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004219 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220{
4221 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304222 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004223
4224 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304225 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004226 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004227 status);
4228 return status;
4229 }
4230
Jeff Johnson57eb2732017-10-02 11:40:20 -07004231 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304233 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004234 break;
4235
4236 pCurrent = pNext;
4237 }
4238 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304239 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004240 /*
4241 * Here we are stopping global bus_bw timer & work per adapter.
4242 *
4243 * The reason is to fix one race condition between
4244 * bus bandwidth work and cleaning up an adapter.
4245 * Under some conditions, it is possible for the bus bandwidth
4246 * work to access a particularly destroyed adapter, leading to
4247 * use-after-free.
4248 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004249 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004250 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004251 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004252
4253 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004254 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4255 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004256 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004257 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304258 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259 adapterNode = NULL;
4260
Dustin Brown5ec6b552017-03-31 12:11:40 -07004261 /* conditionally restart the bw timer */
4262 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4263
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264 /* Adapter removed. Decrement vdev count */
4265 if (hdd_ctx->current_intf_count != 0)
4266 hdd_ctx->current_intf_count--;
4267
4268 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304269 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004270 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304271
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304272 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004273}
4274
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004275/**
4276 * hdd_close_all_adapters - Close all open adapters
4277 * @hdd_ctx: Hdd context
4278 * rtnl_held: True if RTNL lock held
4279 *
4280 * Close all open adapters.
4281 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304282 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004283 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004284QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004285{
4286 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304287 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288
4289 ENTER();
4290
4291 do {
4292 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304293 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304294 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004295 pHddAdapterNode->adapter->mac_addr.bytes);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004296 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004297 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304298 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304299 /* Adapter removed. Decrement vdev count */
4300 if (hdd_ctx->current_intf_count != 0)
4301 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004302 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304303 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304
4305 EXIT();
4306
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304307 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308}
4309
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004310void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004311{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304312 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004313 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004314
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004315 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004316 case QDF_STA_MODE:
4317 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004319 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004320 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004321 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322 break;
4323 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004324 case QDF_SAP_MODE:
4325 case QDF_P2P_GO_MODE:
4326 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004327 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004328 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004329 break;
4330 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004331 case QDF_FTM_MODE:
4332 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004333 default:
4334 /*
4335 * wlan_hdd_reset_prob_rspies should not have been called
4336 * for these kind of devices
4337 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004338 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004339 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 return;
4341 }
4342
Anurag Chouhanc5548422016-02-24 18:33:27 +05304343 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004344 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004345 updateIE.ieBufferlength = 0;
4346 updateIE.pAdditionIEBuffer = NULL;
4347 updateIE.append = true;
4348 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004349 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304351 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004352 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353 }
4354}
4355
Jeff Johnson9d295242017-08-29 14:39:48 -07004356QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004357 const bool bCloseSession)
4358{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304359 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004360 struct hdd_wext_state *pWextState =
4361 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004362 union iwreq_data wrqu;
4363 tSirUpdateIE updateIE;
4364 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304365 tsap_Config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004366
4367 ENTER();
4368
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004369 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304370 wlan_hdd_netif_queue_control(adapter,
4371 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4372 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004373 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004374 case QDF_STA_MODE:
4375 case QDF_P2P_CLIENT_MODE:
4376 case QDF_IBSS_MODE:
4377 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004378 case QDF_NDI_MODE:
4379 if ((QDF_NDI_MODE == adapter->device_mode) ||
4380 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4382 hdd_is_connecting(
4383 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004384 INIT_COMPLETION(adapter->disconnect_comp_var);
4385 /*
4386 * For NDI do not use pWextState from sta_ctx, if needed
4387 * extract from ndi_ctx.
4388 */
4389 if (QDF_NDI_MODE == adapter->device_mode)
4390 qdf_ret_status = sme_roam_disconnect(
4391 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004392 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004393 eCSR_DISCONNECT_REASON_NDI_DELETE);
4394 else if (pWextState->roamProfile.BSSType ==
4395 eCSR_BSS_TYPE_START_IBSS)
4396 qdf_ret_status = sme_roam_disconnect(
4397 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004398 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004399 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004400 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004401 qdf_ret_status =
4402 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004403 hdd_debug("Send disconnected event to userspace");
4404 wlan_hdd_cfg80211_indicate_disconnect(
4405 adapter->dev, true,
4406 WLAN_REASON_UNSPECIFIED);
4407 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004408 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004409 qdf_ret_status = sme_roam_disconnect(
4410 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004411 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004412 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004413 /* success implies disconnect command got
4414 * queued up successfully
4415 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004416 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4417 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004418 rc = wait_for_completion_timeout(
4419 &adapter->disconnect_comp_var,
4420 msecs_to_jiffies
4421 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004422 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004423 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004425 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4426 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004427 memset(&wrqu, '\0', sizeof(wrqu));
4428 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4429 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4430 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4431 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304432 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004433 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004434
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304435 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304436 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004437
4438#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004439 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004440#endif
4441
4442 hdd_deregister_tx_flow_control(adapter);
4443
4444#ifdef WLAN_NS_OFFLOAD
4445#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004446 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004447#endif
4448#endif
4449
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304450 if (adapter->device_mode == QDF_STA_MODE)
4451 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4452 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004453 /*
4454 * It is possible that the caller of this function does not
4455 * wish to close the session
4456 */
Krunal Soni985b8132017-02-10 18:49:08 -08004457 if (true == bCloseSession) {
4458 if (0 != wlan_hdd_try_disconnect(adapter)) {
4459 hdd_err("Error: Can't disconnect adapter");
4460 return QDF_STATUS_E_FAILURE;
4461 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004462 hdd_debug("Destroying adapter: %d",
4463 adapter->session_id);
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004464 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004465 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466 break;
4467
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004468 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304469 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304470 sap_config = &adapter->session.ap.sap_config;
4471 if (sap_config)
4472 wlansap_reset_sap_config_add_ie(sap_config,
4473 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05304474 hdd_ipa_flush(hdd_ctx);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004475
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004476 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004477 if (QDF_SAP_MODE == adapter->device_mode) {
4478 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4479 cds_flush_delayed_work(
4480 &adapter->acs_pending_work);
4481 clear_bit(ACS_PENDING, &adapter->event_flags);
4482 }
4483 }
Krunal Soni22208392017-09-29 18:10:34 -07004484 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004485
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004487 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004488 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004489 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4490
4491 hdd_deregister_tx_flow_control(adapter);
4492
Kapil Guptac1224bf2017-06-22 21:22:40 +05304493 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004494 mutex_lock(&hdd_ctx->sap_lock);
4495 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304496 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304497 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004498
4499 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 status = wlansap_stop_bss(
4501 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004502
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304503 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004504 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004505 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304506 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304507 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304508 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304509 qdf_wait_for_event_completion(
4510 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004511 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004512
Anurag Chouhance0dc992016-02-16 18:18:03 +05304513 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004514 hdd_err("failure waiting for wlansap_stop_bss %d",
4515 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004516 }
4517 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004518 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004519 }
4520 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004521 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4522 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004523 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004524
Anurag Chouhanc5548422016-02-24 18:33:27 +05304525 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004526 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004527 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004528 updateIE.ieBufferlength = 0;
4529 updateIE.pAdditionIEBuffer = NULL;
4530 updateIE.append = false;
4531 updateIE.notify = false;
4532 /* Probe bcn reset */
4533 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4534 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304535 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004536 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537 }
4538 /* Assoc resp reset */
4539 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4540 &updateIE,
4541 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304542 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004543 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004544 }
4545 /* Reset WNI_CFG_PROBE_RSP Flags */
4546 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004547 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004548 qdf_mem_free(adapter->session.ap.beacon);
4549 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304550 /*
4551 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4552 */
4553 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4554 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4555
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304556#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004557 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304558#endif
4559
4560#ifdef WLAN_NS_OFFLOAD
4561#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004562 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304563#endif
4564#endif
Krunal Sonib51eec72017-11-20 21:53:01 -08004565 if (true == bCloseSession) {
4566 hdd_debug("Destroying adapter: %d",
4567 adapter->session_id);
4568 hdd_vdev_destroy(adapter);
4569 }
4570 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004572 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004573 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004574 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004575 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004576 break;
4577 default:
4578 break;
4579 }
4580
4581 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304582 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004583}
4584
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304585/**
4586 * hdd_deinit_all_adapters - deinit all adapters
4587 * @hdd_ctx: HDD context
4588 * @rtnl_held: True if RTNL lock held
4589 *
4590 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004591void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304592{
4593 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4594 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004595 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304596
4597 ENTER();
4598
4599 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4600
4601 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004602 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304603 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4604 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4605 adapter_node = next;
4606 }
4607
4608 EXIT();
4609}
4610
Dustin Brown27cd9942017-09-27 16:11:44 -07004611QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4612 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004613{
4614 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304615 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004616 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004617
4618 ENTER();
4619
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304620 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4621
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004622 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4623
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304624 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004625 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004626 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004627 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4628 adapterNode = pNext;
4629 }
4630
4631 EXIT();
4632
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304633 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004634}
4635
Paul Zhang84fa9382017-11-10 21:18:21 +08004636static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4637 struct hdd_adapter *adapter)
4638{
4639 switch (adapter->device_mode) {
4640 case QDF_STA_MODE:
4641 case QDF_P2P_CLIENT_MODE:
4642 case QDF_IBSS_MODE:
4643 case QDF_P2P_DEVICE_MODE:
4644 case QDF_NDI_MODE:
4645 wlan_hdd_scan_abort(adapter);
4646 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4647 if (adapter->device_mode == QDF_STA_MODE)
4648 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4649 adapter->dev);
4650 break;
4651 case QDF_P2P_GO_MODE:
4652 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4653 break;
4654 case QDF_SAP_MODE:
4655 wlan_hdd_undo_acs(adapter);
4656 break;
4657 default:
4658 break;
4659 }
4660}
4661
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004662QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004663{
4664 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304665 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004666 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004667 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004668 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004669
4670 ENTER();
4671
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304672 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4673
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004674 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4675
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304676 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004677 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004678 hdd_notice("Disabling queues for adapter type: %d",
4679 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304680
4681 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004682 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304683 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004684 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304685
Arun Khandavallicc544b32017-01-30 19:52:16 +05304686 if (hdd_ctx->config->sap_internal_restart &&
4687 adapter->device_mode == QDF_SAP_MODE) {
4688 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304689 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304690 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004691 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08004692 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004693 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004694 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4695 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304696 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304697 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004698 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004699 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004700
Paul Zhang84fa9382017-11-10 21:18:21 +08004701 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07004702 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004703
4704 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004705 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004706 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004707 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4708 hdd_wmm_adapter_close(adapter);
4709 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4710 }
4711
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304712 if (adapter->device_mode == QDF_STA_MODE)
4713 hdd_clear_fils_connection_info(adapter);
4714
Wu Gao3545e642017-07-14 19:24:41 +08004715 if (adapter->device_mode == QDF_SAP_MODE) {
4716 /*
4717 * If adapter is SAP, set session ID to invalid
4718 * since SAP session will be cleanup during SSR.
4719 */
Wu Gao36717432016-11-21 15:09:48 +08004720 wlansap_set_invalid_session(
4721 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4722
Wu Gao3545e642017-07-14 19:24:41 +08004723 wlansap_cleanup_cac_timer(
4724 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4725 }
4726
Yue Mad5b4b9f2017-05-26 16:23:40 -07004727 /* Delete peers if any for STA and P2P client modes */
4728 if (adapter->device_mode == QDF_STA_MODE ||
4729 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004730 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004731 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004732 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004733
4734 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4735 peerMacAddr.bytes);
4736 }
4737
Yue Maf9782842017-05-08 12:49:49 -07004738 /* Destroy vdev which will be recreated during reinit. */
4739 hdd_vdev_destroy(adapter);
4740
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004741 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4742 adapterNode = pNext;
4743 }
4744
4745 EXIT();
4746
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304747 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004748}
4749
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004750bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304751{
4752 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4753 QDF_STATUS status;
4754 bool close_modules = true;
4755
Arun Khandavalliba479c42017-07-26 21:29:40 +05304756 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4757 hdd_info("FTM mode, don't close the module");
4758 return false;
4759 }
4760
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304761 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4762 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4763 if (test_bit(DEVICE_IFACE_OPENED,
Yeshwanth Sriram Guntuka4ce0a1b2017-10-17 17:55:45 +05304764 &adapter_node->adapter->event_flags) ||
4765 test_bit(SME_SESSION_OPENED,
4766 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004767 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304768 close_modules = false;
4769 break;
4770 }
4771 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4772 adapter_node = next;
4773 }
4774
4775 return close_modules;
4776}
4777
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304778bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304779{
4780 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4781 return true;
4782 else
4783 return false;
4784}
4785
Anurag Chouhanc4092922016-09-08 15:56:11 +05304786#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004787 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304788struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4789 struct ieee80211_channel *channel,
4790 const u8 *bssid, const u8 *ssid,
4791 size_t ssid_len)
4792{
4793 return cfg80211_get_bss(wiphy, channel, bssid,
4794 ssid, ssid_len,
4795 WLAN_CAPABILITY_ESS,
4796 WLAN_CAPABILITY_ESS);
4797}
4798#else
4799struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4800 struct ieee80211_channel *channel,
4801 const u8 *bssid, const u8 *ssid,
4802 size_t ssid_len)
4803{
4804 return cfg80211_get_bss(wiphy, channel, bssid,
4805 ssid, ssid_len,
4806 IEEE80211_BSS_TYPE_ESS,
4807 IEEE80211_PRIVACY_ANY);
4808}
4809#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304810
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304811#if defined CFG80211_CONNECT_BSS || \
4812 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304813#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304814 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304815/**
4816 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4817 * @timeout_reason: reason for connect timeout
4818 *
4819 * This function is used to convert host timeout
4820 * reason enum to kernel specific enum.
4821 *
4822 * Return: nl timeout enum
4823 */
4824static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4825 tSirResultCodes timeout_reason)
4826{
4827 switch (timeout_reason) {
4828 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4829 return NL80211_TIMEOUT_SCAN;
4830 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4831 return NL80211_TIMEOUT_AUTH;
4832 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4833 return NL80211_TIMEOUT_ASSOC;
4834 default:
4835 return NL80211_TIMEOUT_UNSPECIFIED;
4836 }
4837}
4838
4839/**
4840 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4841 * @dev: network device
4842 * @bssid: bssid to which we want to associate
4843 * @timeout_reason: reason for connect timeout
4844 *
4845 * This API is used to send connection timeout reason to supplicant
4846 *
4847 * Return: void
4848 */
4849static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4850 const u8 *bssid,
4851 tSirResultCodes timeout_reason)
4852{
4853 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004854
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304855 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4856
4857 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4858 nl_timeout_reason);
4859}
4860
4861/**
4862 * __hdd_connect_bss() - API to send connection status to supplicant
4863 * @dev: network device
4864 * @bssid: bssid to which we want to associate
4865 * @req_ie: Request Information Element
4866 * @req_ie_len: len of the req IE
4867 * @resp_ie: Response IE
4868 * @resp_ie_len: len of ht response IE
4869 * @status: status
4870 * @gfp: Kernel Flag
4871 * @timeout_reason: reason for connect timeout
4872 *
4873 * Return: void
4874 */
4875static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4876 struct cfg80211_bss *bss, const u8 *req_ie,
4877 size_t req_ie_len, const u8 *resp_ie,
4878 size_t resp_ie_len, int status, gfp_t gfp,
4879 tSirResultCodes timeout_reason)
4880{
4881 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004882
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304883 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4884
4885 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4886 resp_ie, resp_ie_len, status, gfp,
4887 nl_timeout_reason);
4888}
4889#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304890#if defined CFG80211_CONNECT_TIMEOUT || \
4891 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304892static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4893 const u8 *bssid,
4894 tSirResultCodes timeout_reason)
4895{
4896 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4897}
4898#endif
4899
4900static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4901 struct cfg80211_bss *bss, const u8 *req_ie,
4902 size_t req_ie_len, const u8 *resp_ie,
4903 size_t resp_ie_len, int status, gfp_t gfp,
4904 tSirResultCodes timeout_reason)
4905{
4906 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4907 resp_ie, resp_ie_len, status, gfp);
4908}
4909#endif
4910
Abhishek Singha84d3952016-09-13 13:45:05 +05304911/**
4912 * hdd_connect_bss() - API to send connection status to supplicant
4913 * @dev: network device
4914 * @bssid: bssid to which we want to associate
4915 * @req_ie: Request Information Element
4916 * @req_ie_len: len of the req IE
4917 * @resp_ie: Response IE
4918 * @resp_ie_len: len of ht response IE
4919 * @status: status
4920 * @gfp: Kernel Flag
4921 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304922 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304923 *
4924 * The API is a wrapper to send connection status to supplicant
4925 *
4926 * Return: Void
4927 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304928#if defined CFG80211_CONNECT_TIMEOUT || \
4929 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05304930static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4931 struct cfg80211_bss *bss, const u8 *req_ie,
4932 size_t req_ie_len, const u8 *resp_ie,
4933 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304934 bool connect_timeout,
4935 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304936{
4937 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304938 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304939 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304940 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4941 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304942}
4943#else
4944static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4945 struct cfg80211_bss *bss, const u8 *req_ie,
4946 size_t req_ie_len, const u8 *resp_ie,
4947 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304948 bool connect_timeout,
4949 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304950{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304951 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4952 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304953}
4954#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304955
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304956#if defined(WLAN_FEATURE_FILS_SK)
4957#if defined(CFG80211_CONNECT_DONE) || \
4958 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
4959#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
4960 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304961/**
4962 * hdd_populate_fils_params() - Populate FILS keys to connect response
4963 * @fils_params: connect response to supplicant
4964 * @fils_kek: FILS kek
4965 * @fils_kek_len: FILS kek length
4966 * @pmk: FILS PMK
4967 * @pmk_len: FILS PMK length
4968 * @pmkid: PMKID
4969 * @fils_seq_num: FILS Seq number
4970 *
4971 * Return: None
4972 */
4973static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4974 *fils_params, const uint8_t *fils_kek,
4975 size_t fils_kek_len, const uint8_t *pmk,
4976 size_t pmk_len, const uint8_t *pmkid,
4977 uint16_t fils_seq_num)
4978{
4979 /* Increament seq number to be used for next FILS */
4980 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4981 fils_params->update_erp_next_seq_num = true;
4982 fils_params->fils_kek = fils_kek;
4983 fils_params->fils_kek_len = fils_kek_len;
4984 fils_params->pmk = pmk;
4985 fils_params->pmk_len = pmk_len;
4986 fils_params->pmkid = pmkid;
4987}
4988#else
4989static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4990 *fils_params, const uint8_t
4991 *fils_kek, size_t fils_kek_len,
4992 const uint8_t *pmk, size_t pmk_len,
4993 const uint8_t *pmkid,
4994 uint16_t fils_seq_num)
4995{ }
4996#endif
4997
Jeff Johnson172237b2017-11-07 15:32:59 -08004998void hdd_update_hlp_info(struct net_device *dev,
4999 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305000{
5001 struct sk_buff *skb;
5002 uint16_t skb_len;
5003 struct llc_snap_hdr_t *llc_hdr;
5004 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305005 uint8_t *hlp_data;
5006 uint16_t hlp_data_len;
5007 struct fils_join_rsp_params *roam_fils_params
5008 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305009 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5010
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305011 if (!roam_fils_params) {
5012 hdd_err("FILS Roam Param NULL");
5013 return;
5014 }
5015
5016 if (!roam_fils_params->hlp_data_len || !roam_fils_params->hlp_data) {
5017 hdd_err("FILS HLP Data NULL, len %d",
5018 roam_fils_params->hlp_data_len);
5019 return;
5020 }
5021
5022 hlp_data = roam_fils_params->hlp_data;
5023 hlp_data_len = roam_fils_params->hlp_data_len;
5024
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305025 /* Calculate skb length */
5026 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5027 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5028 if (skb == NULL) {
5029 hdd_err("HLP packet nbuf alloc fails");
5030 return;
5031 }
5032
5033 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5034 QDF_MAC_ADDR_SIZE);
5035 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5036 QDF_MAC_ADDR_SIZE);
5037
5038 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5039 if (IS_SNAP(llc_hdr)) {
5040 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5041 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5042 }
5043
5044 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5045
5046 /*
5047 * This HLP packet is formed from HLP info encapsulated
5048 * in assoc response frame which is AEAD encrypted.
5049 * Hence, this checksum validation can be set unnecessary.
5050 * i.e. network layer need not worry about checksum.
5051 */
5052 skb->ip_summed = CHECKSUM_UNNECESSARY;
5053
5054 status = hdd_rx_packet_cbk(padapter, skb);
5055 if (QDF_IS_STATUS_ERROR(status)) {
5056 hdd_err("Sending HLP packet fails");
5057 return;
5058 }
5059 hdd_debug("send HLP packet to netif successfully");
5060}
5061
5062/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305063 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5064 * @dev: network device
5065 * @bssid: bssid to which we want to associate
5066 * @bss: cfg80211 bss info
5067 * @roam_info: information about connected bss
5068 * @req_ie: Request Information Element
5069 * @req_ie_len: len of the req IE
5070 * @resp_ie: Response IE
5071 * @resp_ie_len: len of ht response IE
5072 * @status: status
5073 * @gfp: allocation flags
5074 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5075 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305076 *
5077 * This API is used as wrapper to send FILS key/sequence number
5078 * params etc. to supplicant in case of FILS connection
5079 *
5080 * Return: None
5081 */
5082static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005083 struct cfg80211_bss *bss,
5084 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305085 const u8 *req_ie, size_t req_ie_len,
5086 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005087 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305088 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305089{
5090 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305091 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5092 struct fils_join_rsp_params *roam_fils_params =
5093 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005094
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305095 qdf_mem_zero(&fils_params, sizeof(fils_params));
5096
5097 if (!roam_fils_params) {
5098 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5099 } else {
5100 fils_params.status = status;
5101 fils_params.bssid = bssid;
5102 fils_params.timeout_reason = timeout_reason;
5103 fils_params.req_ie = req_ie;
5104 fils_params.req_ie_len = req_ie_len;
5105 fils_params.resp_ie = resp_ie;
5106 fils_params.resp_ie_len = resp_ie_len;
5107 fils_params.bss = bss;
5108 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5109 roam_fils_params->kek_len,
5110 roam_fils_params->fils_pmk,
5111 roam_fils_params->fils_pmk_len,
5112 roam_fils_params->fils_pmkid,
5113 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305114 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305115 }
5116 hdd_debug("FILS indicate connect status %d seq no %d",
5117 fils_params.status,
5118 fils_params.fils_erp_next_seq_num);
5119
5120 cfg80211_connect_done(dev, &fils_params, gfp);
5121
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305122 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305123 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305124
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305125 /* Clear all the FILS key info */
5126 if (roam_fils_params && roam_fils_params->fils_pmk)
5127 qdf_mem_free(roam_fils_params->fils_pmk);
5128 if (roam_fils_params)
5129 qdf_mem_free(roam_fils_params);
5130 roam_info->fils_join_rsp = NULL;
5131}
5132#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005133static inline void
5134hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005135 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005136 const u8 *req_ie, size_t req_ie_len,
5137 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5138 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305139 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305140{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305141#endif
5142#endif
5143
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305144#if defined(WLAN_FEATURE_FILS_SK) && \
5145 (defined(CFG80211_CONNECT_DONE) || \
5146 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305147/**
5148 * hdd_fils_update_connect_results() - API to send fils connection status to
5149 * supplicant.
5150 * @dev: network device
5151 * @bssid: bssid to which we want to associate
5152 * @bss: cfg80211 bss info
5153 * @roam_info: information about connected bss
5154 * @req_ie: Request Information Element
5155 * @req_ie_len: len of the req IE
5156 * @resp_ie: Response IE
5157 * @resp_ie_len: len of ht response IE
5158 * @status: status
5159 * @gfp: allocation flags
5160 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5161 * @timeout_reason: reason for connect timeout
5162 *
5163 * The API is a wrapper to send connection status to supplicant
5164 *
5165 * Return: 0 if success else failure
5166 */
5167static int hdd_fils_update_connect_results(struct net_device *dev,
5168 const u8 *bssid,
5169 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005170 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305171 size_t req_ie_len, const u8 *resp_ie,
5172 size_t resp_ie_len, u16 status, gfp_t gfp,
5173 bool connect_timeout,
5174 tSirResultCodes timeout_reason)
5175{
5176 ENTER();
5177 if (!roam_info || !roam_info->is_fils_connection)
5178 return -EINVAL;
5179
5180 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5181 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305182 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305183 return 0;
5184}
5185#else
5186static inline int hdd_fils_update_connect_results(struct net_device *dev,
5187 const u8 *bssid,
5188 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005189 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305190 size_t req_ie_len, const u8 *resp_ie,
5191 size_t resp_ie_len, u16 status, gfp_t gfp,
5192 bool connect_timeout,
5193 tSirResultCodes timeout_reason)
5194{
5195 return -EINVAL;
5196}
5197#endif
5198
Anurag Chouhanc4092922016-09-08 15:56:11 +05305199/**
5200 * hdd_connect_result() - API to send connection status to supplicant
5201 * @dev: network device
5202 * @bssid: bssid to which we want to associate
5203 * @roam_info: information about connected bss
5204 * @req_ie: Request Information Element
5205 * @req_ie_len: len of the req IE
5206 * @resp_ie: Response IE
5207 * @resp_ie_len: len of ht response IE
5208 * @status: status
5209 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305210 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305211 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305212 *
5213 * The API is a wrapper to send connection status to supplicant
5214 * and allow runtime suspend
5215 *
5216 * Return: Void
5217 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305218void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005219 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305220 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305221 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305222 bool connect_timeout,
5223 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305224{
Jeff Johnson9d295242017-08-29 14:39:48 -07005225 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305226 struct cfg80211_bss *bss = NULL;
5227
5228 if (WLAN_STATUS_SUCCESS == status) {
5229 struct ieee80211_channel *chan;
5230 int freq;
5231 int chan_no = roam_info->pBssDesc->channelId;
5232
5233 if (chan_no <= 14)
5234 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005235 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305236 else
5237 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005238 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305239
5240 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5241 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5242 roam_info->u.pConnectedProfile->SSID.ssId,
5243 roam_info->u.pConnectedProfile->SSID.length);
5244 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305245
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305246 if (hdd_fils_update_connect_results(dev, bssid, bss,
5247 roam_info, req_ie, req_ie_len, resp_ie,
5248 resp_ie_len, status, gfp, connect_timeout,
5249 timeout_reason) != 0) {
5250 hdd_connect_bss(dev, bssid, bss, req_ie,
5251 req_ie_len, resp_ie, resp_ie_len,
5252 status, gfp, connect_timeout, timeout_reason);
5253 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305254
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005255 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005256 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305257}
5258#else
5259void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005260 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305261 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305262 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305263 bool connect_timeout,
5264 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305265{
Jeff Johnson9d295242017-08-29 14:39:48 -07005266 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305267
Anurag Chouhanc4092922016-09-08 15:56:11 +05305268 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5269 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005270
5271 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005272 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305273}
5274#endif
5275
5276
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005277QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005278{
5279 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305280 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005281 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005282#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305283 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284#endif
5285 eConnectionState connState;
5286
5287 ENTER();
5288
5289 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305290 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005291 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005292
Arun Khandavallifae92942016-08-01 13:31:08 +05305293 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305294 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305295
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005296 hdd_wmm_init(adapter);
5297
5298 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005299 case QDF_STA_MODE:
5300 case QDF_P2P_CLIENT_MODE:
5301 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005302
5303 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5304 ->conn_info.connState;
5305
Krunal Sonib51eec72017-11-20 21:53:01 -08005306 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005307 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005308 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005309
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005310 /* Indicate disconnect event to supplicant
5311 * if associated previously
5312 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005313 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005314 eConnectionState_IbssConnected == connState ||
5315 eConnectionState_NotConnected == connState ||
5316 eConnectionState_IbssDisconnected == connState ||
5317 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005318 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005319
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005320 memset(&wrqu, '\0', sizeof(wrqu));
5321 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5322 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5323 wireless_send_event(adapter->dev, SIOCGIWAP,
5324 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005325 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005326 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005327
5328 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305329 wlan_hdd_cfg80211_indicate_disconnect(
5330 adapter->dev, false,
5331 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005332 } else if (eConnectionState_Connecting == connState) {
5333 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005334 * Indicate connect failure to supplicant if we
5335 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005336 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305337 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305338 NULL, 0, NULL, 0,
5339 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005340 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005341 }
5342
5343 hdd_register_tx_flow_control(adapter,
5344 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005345 hdd_tx_resume_cb,
5346 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005347
5348 break;
5349
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005350 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005351 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005352 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305353
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005354 break;
5355
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005356 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005357#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005358 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005359 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5360#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005361 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005362 /* event supplicant to restart */
5363 cfg80211_del_sta(adapter->dev,
5364 (const u8 *)&bcastMac.bytes[0],
5365 GFP_KERNEL);
5366#endif
5367 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305368 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005369 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305370 hdd_set_mon_rx_cb(adapter->dev);
5371 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5372 adapter->mon_bandwidth);
5373 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005374 default:
5375 break;
5376 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005377 /*
5378 * Action frame registered in one adapter which will
5379 * applicable to all interfaces
5380 */
5381 wlan_hdd_cfg80211_register_frames(adapter);
5382
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305383get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005384 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5385 adapterNode = pNext;
5386 }
5387
5388 EXIT();
5389
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305390 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005391}
5392
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005393QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005394 hdd_adapter_list_node_t **padapterNode)
5395{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305396 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005397
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005398 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005399 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305400 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005401 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005402 return status;
5403}
5404
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005405QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005406 hdd_adapter_list_node_t *adapterNode,
5407 hdd_adapter_list_node_t **pNextAdapterNode)
5408{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305409 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005410
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005411 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005412 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305413 (qdf_list_node_t *) adapterNode,
5414 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005415
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005416 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005417 return status;
5418}
5419
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005420QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005421 hdd_adapter_list_node_t *adapterNode)
5422{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305423 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005424
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005425 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005426 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005427 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005428 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005429 return status;
5430}
5431
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005432QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005433 hdd_adapter_list_node_t **padapterNode)
5434{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305435 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005436
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005437 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005438 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305439 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005440 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005441 return status;
5442}
5443
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005444QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005445 hdd_adapter_list_node_t *adapterNode)
5446{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305447 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005448
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005449 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005450 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305451 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005452 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005453 return status;
5454}
5455
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005456QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005457 hdd_adapter_list_node_t *adapterNode)
5458{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305459 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005460
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005461 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005462 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305463 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005464 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005465 return status;
5466}
5467
Jeff Johnson9d295242017-08-29 14:39:48 -07005468struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005469 tSirMacAddr macAddr)
5470{
5471 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005472 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305473 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005474
5475 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5476
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305477 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005478 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005479
5480 if (adapter
Jeff Johnson1e851a12017-10-28 14:36:12 -07005481 && !qdf_mem_cmp(adapter->mac_addr.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005482 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005483 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005484
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005485 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5486 adapterNode = pNext;
5487 }
5488
5489 return NULL;
5490
5491}
5492
Jeff Johnson9d295242017-08-29 14:39:48 -07005493struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005494 uint32_t vdev_id)
5495{
5496 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005497 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305498 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005499
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305500 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005501
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305502 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005503 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005504
Jeff Johnson1b780e42017-10-31 14:11:45 -07005505 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005506 return adapter;
5507
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305508 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005509 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5510 adapterNode = pNext;
5511 }
5512
Jeff Johnson5880d792016-08-15 13:32:30 -07005513 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005514
5515 return NULL;
5516}
5517
Abhishek Singh7996eb72015-12-30 17:24:02 +05305518/**
5519 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5520 * the sessionid
5521 * @hdd_ctx: hdd context.
5522 * @sme_session_id: sme session is for the adapter to get.
5523 *
5524 * This function is used to get the adapter with provided session id
5525 *
5526 * Return: adapter pointer if found
5527 *
5528 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005529struct hdd_adapter *
5530hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5531 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305532{
5533 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005534 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305535 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305536
5537
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305538 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305539
5540 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305541 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005542 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305543
5544 if (adapter &&
Jeff Johnson1b780e42017-10-31 14:11:45 -07005545 adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305546 return adapter;
5547
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305548 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305549 hdd_get_next_adapter(hdd_ctx,
5550 adapter_node, &next);
5551 adapter_node = next;
5552 }
5553 return NULL;
5554}
5555
Jeff Johnson9d295242017-08-29 14:39:48 -07005556struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005557 const char *iface_name)
5558{
5559 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005560 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005561 QDF_STATUS qdf_status;
5562
5563 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5564
5565 while ((NULL != adapter_node) &&
5566 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005567 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005568
5569 if (adapter &&
5570 !qdf_str_cmp(adapter->dev->name, iface_name))
5571 return adapter;
5572
5573 qdf_status =
5574 hdd_get_next_adapter(hdd_ctx,
5575 adapter_node, &next);
5576 adapter_node = next;
5577 }
5578 return NULL;
5579}
5580
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005581/**
5582 * hdd_get_adapter() - to get adapter matching the mode
5583 * @hdd_ctx: hdd context
5584 * @mode: adapter mode
5585 *
5586 * This routine will return the pointer to adapter matching
5587 * with the passed mode.
5588 *
5589 * Return: pointer to adapter or null
5590 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005591struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005592 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005593{
5594 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005595 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305596 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005597
5598 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5599
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305600 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005601 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005602
5603 if (adapter && (mode == adapter->device_mode))
5604 return adapter;
5605
5606 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5607 adapterNode = pNext;
5608 }
5609
5610 return NULL;
5611
5612}
5613
5614/**
5615 * hdd_get_operating_channel() - return operating channel of the device mode
5616 * @hdd_ctx: Pointer to the HDD context.
5617 * @mode: Device mode for which operating channel is required.
5618 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005619 * QDF_STA_MODE,
5620 * QDF_P2P_CLIENT_MODE,
5621 * QDF_SAP_MODE,
5622 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005623 *
5624 * This API returns the operating channel of the requested device mode
5625 *
5626 * Return: channel number. "0" id the requested device is not found OR it is
5627 * not connected.
5628 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005629uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005630 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005631{
5632 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305633 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005634 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005635 uint8_t operatingChannel = 0;
5636
5637 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5638
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305639 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005640 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005641
5642 if (mode == adapter->device_mode) {
5643 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005644 case QDF_STA_MODE:
5645 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005646 if (hdd_conn_is_connected
5647 (WLAN_HDD_GET_STATION_CTX_PTR
5648 (adapter))) {
5649 operatingChannel =
5650 (WLAN_HDD_GET_STATION_CTX_PTR
5651 (adapter))->conn_info.
5652 operationChannel;
5653 }
5654 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005655 case QDF_SAP_MODE:
5656 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005657 /* softap connection info */
5658 if (test_bit
5659 (SOFTAP_BSS_STARTED,
5660 &adapter->event_flags))
5661 operatingChannel =
5662 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005663 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005664 break;
5665 default:
5666 break;
5667 }
5668
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005669 /* Found the device of interest. break the loop */
5670 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671 }
5672
5673 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5674 adapterNode = pNext;
5675 }
5676 return operatingChannel;
5677}
5678
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005679static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005680 hdd_ctx)
5681{
5682 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305683 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005684 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005685
5686 ENTER();
5687
5688 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5689
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305690 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005691 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005692 if ((adapter->device_mode == QDF_STA_MODE) ||
5693 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5694 (adapter->device_mode == QDF_IBSS_MODE) ||
5695 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5696 (adapter->device_mode == QDF_SAP_MODE) ||
5697 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005698 wlan_hdd_cfg80211_deregister_frames(adapter);
5699 hdd_unregister_wext(adapter->dev);
5700 }
5701 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5702 adapterNode = pNext;
5703 }
5704
5705 EXIT();
5706
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305707 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005708}
5709
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005710QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005711{
5712 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305713 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005714 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715
5716 ENTER();
5717
5718 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5719
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305720 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005721 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005722 if ((adapter->device_mode == QDF_STA_MODE) ||
5723 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5724 (adapter->device_mode == QDF_IBSS_MODE) ||
5725 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5726 (adapter->device_mode == QDF_SAP_MODE) ||
5727 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005728 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005729 adapter->session_id, INVALID_SCAN_ID,
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005730 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005731 }
5732 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5733 adapterNode = pNext;
5734 }
5735
5736 EXIT();
5737
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305738 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005739}
5740
Dustin Brownf27bce82016-11-03 12:52:27 -07005741/**
5742 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5743 * adapters
5744 * @hdd_ctx: The HDD context containing the adapters to operate on
5745 *
5746 * return: QDF_STATUS_SUCCESS
5747 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005748static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005749{
5750 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5751 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005752 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005753 int err;
5754
5755 ENTER();
5756
5757 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5758
5759 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005760 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005761 if ((adapter->device_mode == QDF_STA_MODE) ||
5762 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5763 (adapter->device_mode == QDF_IBSS_MODE) ||
5764 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5765 (adapter->device_mode == QDF_SAP_MODE) ||
5766 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5767 err = wlan_hdd_sched_scan_stop(adapter->dev);
5768 if (err)
5769 hdd_err("Unable to stop scheduled scan");
5770 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005771 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5772 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005773 adapter_node = next_node;
5774 }
5775
5776 EXIT();
5777
5778 return QDF_STATUS_SUCCESS;
5779}
5780
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005781#ifdef WLAN_NS_OFFLOAD
5782/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005783 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005784 * @hdd_ctx: Pointer to hdd context
5785 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005786 * Unregister for IPv6 address change notifications.
5787 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005788 * Return: None
5789 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005790static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005791{
5792 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005793}
5794
5795/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005796 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005797 * @hdd_ctx: Pointer to hdd context
5798 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005799 * Register for IPv6 address change notifications.
5800 *
5801 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005802 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005803static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005804{
5805 int ret;
5806
5807 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5808 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005809 if (ret) {
5810 hdd_err("Failed to register IPv6 notifier: %d", ret);
5811 goto out;
5812 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005813
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005814 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005815out:
5816 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005817}
5818#else
5819/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005820 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005821 * @hdd_ctx: Pointer to hdd context
5822 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005823 * Unregister for IPv6 address change notifications.
5824 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005825 * Return: None
5826 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005827static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005828{
5829}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005830
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005831/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005832 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005833 * @hdd_ctx: Pointer to hdd context
5834 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005835 * Register for IPv6 address change notifications.
5836 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005837 * Return: None
5838 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005839static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005840{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005841 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005842}
5843#endif
5844
5845/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005846 * hdd_register_notifiers - Register netdev notifiers.
5847 * @hdd_ctx: HDD context
5848 *
5849 * Register netdev notifiers like IPv4 and IPv6.
5850 *
5851 * Return: 0 on success and errno on failure
5852 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005853static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005854{
5855 int ret;
5856
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005857 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5858 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305859 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005860
5861 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5862 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5863 if (ret) {
5864 hdd_err("Failed to register IPv4 notifier: %d", ret);
5865 goto unregister_ip6_notifier;
5866 }
5867
5868 return 0;
5869
5870unregister_ip6_notifier:
5871 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005872out:
5873 return ret;
5874
5875}
5876
5877/**
5878 * hdd_unregister_notifiers - Unregister netdev notifiers.
5879 * @hdd_ctx: HDD context
5880 *
5881 * Unregister netdev notifiers like IPv4 and IPv6.
5882 *
5883 * Return: None.
5884 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005885void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005886{
5887 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5888
5889 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005890}
5891
5892/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005893 * hdd_exit_netlink_services - Exit netlink services
5894 * @hdd_ctx: HDD context
5895 *
5896 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5897 * nl service.
5898 *
5899 * Return: None.
5900 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005901static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005902{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005903 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005904 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005905 ptt_sock_deactivate_svc();
5906
5907 nl_srv_exit();
5908}
5909
5910/**
5911 * hdd_init_netlink_services- Init netlink services
5912 * @hdd_ctx: HDD context
5913 *
5914 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5915 * nl service.
5916 *
5917 * Return: 0 on success and errno on failure.
5918 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005919static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005920{
5921 int ret;
5922
Ryan Hsuceddceb2016-04-28 10:20:14 -07005923 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005924 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005925 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005926 goto out;
5927 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005928 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005929
Naveen Rawat910726a2017-03-06 11:42:51 -08005930 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005931 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005932 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005933 goto err_nl_srv;
5934 }
5935
5936 ret = ptt_sock_activate_svc();
5937 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005938 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005939 goto err_nl_srv;
5940 }
5941
5942 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005943 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005944 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005945
5946 ret = cnss_diag_activate_service();
5947 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005948 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005949 goto err_close_cesium;
5950 }
5951
5952 return 0;
5953
5954err_close_cesium:
5955 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005956 ptt_sock_deactivate_svc();
5957err_nl_srv:
5958 nl_srv_exit();
5959out:
5960 return ret;
5961}
5962
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005963/**
5964 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5965 * @hdd_ctx: HDD context.
5966 *
5967 * Destroy RX wakelock.
5968 *
5969 * Return: None.
5970 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005971static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005972{
5973 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5974}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005975
5976/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005977 * hdd_rx_wake_lock_create() - Create RX wakelock
5978 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005979 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005980 * Create RX wakelock.
5981 *
5982 * Return: None.
5983 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005984static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005985{
5986 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5987}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005988
5989/**
Houston Hoffman160db392016-10-10 17:37:51 -07005990 * hdd_context_deinit() - Deinitialize HDD context
5991 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005992 *
Houston Hoffman160db392016-10-10 17:37:51 -07005993 * Deinitialize HDD context along with all the feature specific contexts but
5994 * do not free hdd context itself. Caller of this API is supposed to free
5995 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005996 *
Houston Hoffman160db392016-10-10 17:37:51 -07005997 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005998 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005999static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006000{
Houston Hoffman160db392016-10-10 17:37:51 -07006001 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006002
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006003 hdd_sap_context_destroy(hdd_ctx);
6004
6005 hdd_rx_wake_lock_destroy(hdd_ctx);
6006
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006007 hdd_scan_context_destroy(hdd_ctx);
6008
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006009 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006010
Houston Hoffman160db392016-10-10 17:37:51 -07006011 return 0;
6012}
6013
6014/**
6015 * hdd_context_destroy() - Destroy HDD context
6016 * @hdd_ctx: HDD context to be destroyed.
6017 *
6018 * Free config and HDD context as well as destroy all the resources.
6019 *
6020 * Return: None
6021 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006022static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006023{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006024 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306025
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306026 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6027
Houston Hoffman160db392016-10-10 17:37:51 -07006028 hdd_context_deinit(hdd_ctx);
6029
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306030 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006031 hdd_ctx->config = NULL;
6032
6033 wiphy_free(hdd_ctx->wiphy);
6034}
6035
6036/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306037 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6038 *
6039 * This function is used to destroy bug report lock
6040 *
6041 * Return: None
6042 */
6043static void wlan_destroy_bug_report_lock(void)
6044{
6045 p_cds_contextType p_cds_context;
6046
6047 p_cds_context = cds_get_global_context();
6048 if (!p_cds_context) {
6049 hdd_err("cds context is NULL");
6050 return;
6051 }
6052
6053 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6054}
6055
6056/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006057 * hdd_wlan_exit() - HDD WLAN exit function
6058 * @hdd_ctx: Pointer to the HDD Context
6059 *
6060 * This is the driver exit point (invoked during rmmod)
6061 *
6062 * Return: None
6063 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006064static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006065{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006066 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306067 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006068
6069 ENTER();
6070
Dustin Brown6f427922017-09-19 12:19:00 -07006071 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306072
6073 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006074
Prashanth Bhattaab004382016-10-11 16:08:11 -07006075 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006076
6077#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306078 if (QDF_TIMER_STATE_RUNNING ==
6079 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6080 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006081 }
6082
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306083 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306084 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006085 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006086 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006087 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6088 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6089 hdd_ctx->last_acs_channel_list = NULL;
6090 hdd_ctx->num_of_channels = 0;
6091 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006092#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006093
Arun Khandavallifae92942016-08-01 13:31:08 +05306094 mutex_lock(&hdd_ctx->iface_change_lock);
6095 driver_status = hdd_ctx->driver_status;
6096 mutex_unlock(&hdd_ctx->iface_change_lock);
6097
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006098 /*
6099 * Powersave Offload Case
6100 * Disable Idle Power Save Mode
6101 */
6102 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006103 /* clear the scan queue in all the scenarios */
6104 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006105
Arun Khandavallifae92942016-08-01 13:31:08 +05306106 if (driver_status != DRIVER_MODULES_CLOSED) {
6107 hdd_unregister_wext_all_adapters(hdd_ctx);
6108 /*
6109 * Cancel any outstanding scan requests. We are about to close
6110 * all of our adapters, but an adapter structure is what SME
6111 * passes back to our callback function. Hence if there
6112 * are any outstanding scan requests then there is a
6113 * race condition between when the adapter is closed and
6114 * when the callback is invoked. We try to resolve that
6115 * race condition here by canceling any outstanding scans
6116 * before we close the adapters.
6117 * Note that the scans may be cancelled in an asynchronous
6118 * manner, so ideally there needs to be some kind of
6119 * synchronization. Rather than introduce a new
6120 * synchronization here, we will utilize the fact that we are
6121 * about to Request Full Power, and since that is synchronized,
6122 * the expectation is that by the time Request Full Power has
6123 * completed, all scans will be cancelled
6124 */
6125 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006126 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006127 hdd_stop_all_adapters(hdd_ctx, true);
bings29c99862017-11-01 13:54:13 +08006128 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006129 }
6130
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306131 unregister_netdevice_notifier(&hdd_netdev_notifier);
6132
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006133 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306134
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306135 qdf_nbuf_deinit_replenish_timer();
6136
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306137 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6138 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6139 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6140
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006141 /*
6142 * Close CDS
6143 * This frees pMac(HAL) context. There should not be any call
6144 * that requires pMac access after this.
6145 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006146
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006147 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006148 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006149
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006150 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006151
6152 hdd_ipa_cleanup(hdd_ctx);
6153
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306154 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306155 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306156 /*
6157 * If there is re_init failure wiphy would have already de-registered
6158 * check the wiphy status before un-registering again
6159 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306160 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306161 wiphy_unregister(wiphy);
6162 wlan_hdd_cfg80211_deinit(wiphy);
6163 hdd_lpass_notify_stop(hdd_ctx);
6164 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006165
Arun Khandavallifae92942016-08-01 13:31:08 +05306166 hdd_exit_netlink_services(hdd_ctx);
6167 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306168#ifdef FEATURE_WLAN_CH_AVOID
6169 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6170#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306171
6172 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6173 if (driver_status)
6174 hdd_err("Pdev delete failed");
6175
6176 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6177 if (driver_status)
6178 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006179
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006180 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006181}
6182
6183void __hdd_wlan_exit(void)
6184{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006185 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006186
6187 ENTER();
6188
Anurag Chouhan6d760662016-02-20 16:05:43 +05306189 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006190 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006191 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006192 EXIT();
6193 return;
6194 }
6195
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006196 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306197 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006198
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006199 /* Do all the cleanup before deregistering the driver */
6200 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202 EXIT();
6203}
6204
6205#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006206/**
6207 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006208 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006209 *
6210 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6211 * Then new ACS request will do a fresh scan without reusing the cached
6212 * scan information.
6213 *
6214 * Return: void
6215 */
Tang Yingying523322d2017-01-17 23:28:43 +08006216static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006217{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006218 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006219
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006220 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006221 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006222 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6223 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6224 hdd_ctx->last_acs_channel_list = NULL;
6225 hdd_ctx->num_of_channels = 0;
6226 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006227
6228 if (!hdd_ctx->hHal)
6229 return;
6230 sme_scan_flush_result(hdd_ctx->hHal);
6231}
6232#endif
6233
6234#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006235int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6236 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006237{
6238 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306239 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006240 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241
6242 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6243
6244 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306245 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006246 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306247
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006248 if (!hdd_ctx->hHal)
6249 return -EINVAL;
6250
Jeff Johnsone7672e72017-10-21 15:10:04 -07006251 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006252 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306253 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006254 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006255 return -EINVAL;
6256 }
6257
6258 return 0;
6259}
6260#endif
6261
6262/**
6263 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6264 * @state: state
6265 *
6266 * This function notifies FW with modem power status
6267 *
6268 * Return: 0 if successful, error number otherwise
6269 */
6270int hdd_wlan_notify_modem_power_state(int state)
6271{
6272 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306273 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006274 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006275
Anurag Chouhan6d760662016-02-20 16:05:43 +05306276 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306278 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006279 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306280
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006281 if (!hdd_ctx->hHal)
6282 return -EINVAL;
6283
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306284 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6285 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006286 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006287 state);
6288 return -EINVAL;
6289 }
6290 return 0;
6291}
6292
6293/**
6294 *
6295 * hdd_post_cds_enable_config() - HDD post cds start config helper
6296 * @adapter - Pointer to the HDD
6297 *
6298 * Return: None
6299 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006300QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306302 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006303
6304 /*
6305 * Send ready indication to the HDD. This will kick off the MAC
6306 * into a 'running' state and should kick off an initial scan.
6307 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306308 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6309 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006310 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6311 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306312 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006313 }
6314
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306315 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006316}
6317
6318/* wake lock APIs for HDD */
6319void hdd_prevent_suspend(uint32_t reason)
6320{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306321 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006322}
6323
6324void hdd_allow_suspend(uint32_t reason)
6325{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306326 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006327}
6328
6329void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6330{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306331 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6332 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006333}
6334
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006335/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006336QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006337{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006338
Amar Singhal6f8592b2017-04-26 14:31:58 -07006339 return sme_init_chan_list(hdd_ctx->hHal,
6340 hdd_ctx->reg.alpha2,
6341 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006342}
6343
6344/**
6345 * hdd_is_5g_supported() - check if hardware supports 5GHz
6346 * @hdd_ctx: Pointer to the hdd context
6347 *
6348 * HDD function to know if hardware supports 5GHz
6349 *
6350 * Return: true if hardware supports 5GHz
6351 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006352bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006353{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006354 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006355 return true;
6356
Amar Singhal58b45ef2017-08-01 13:43:54 -07006357 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006358 return true;
6359 else
6360 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006361}
6362
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006363static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006364{
6365 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006366 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006367
6368 wiphy = hdd_ctx->wiphy;
6369
6370 /*
6371 * The channel information in
6372 * wiphy needs to be initialized before wiphy registration
6373 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006374 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6375 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006376 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006377 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378 }
6379
6380#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6381 wiphy->wowlan = &wowlan_support_reg_init;
6382#else
6383 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6384 WIPHY_WOWLAN_MAGIC_PKT |
6385 WIPHY_WOWLAN_DISCONNECT |
6386 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6387 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6388 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6389 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6390 WIPHY_WOWLAN_RFKILL_RELEASE;
6391
6392 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6393 WOW_MAX_FILTERS_PER_LIST);
6394 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6395 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6396#endif
6397
6398 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006399 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306400 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006401 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306402 return ret_val;
6403 }
6404
Amar Singhal5cccafe2017-02-15 12:42:58 -08006405 if (!hdd_ctx->reg_offload)
6406 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006407
Amar Singhale4f28ee2015-10-21 14:36:56 -07006408 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006409}
6410
Ravi Joshie2331e82015-07-01 18:18:54 -07006411/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006412 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006413 * @hdd_ctx - handle to hdd context
6414 * @tx_packets - transmit packet count
6415 * @rx_packets - receive packet count
6416 *
6417 * The function controls the bus bandwidth and dynamic control of
6418 * tcp delayed ack configuration
6419 *
6420 * Returns: None
6421 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006422#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006423static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006424 const uint64_t tx_packets,
6425 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006426{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006427 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006428 uint64_t temp_rx = 0;
6429 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006430 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006431 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006432 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006433 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006434 uint16_t index = 0;
6435 bool vote_level_change = false;
6436 bool rx_level_change = false;
6437 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006438
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006439 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006440 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006441 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006442 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006443 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006444 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006445 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006446 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006447
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006448 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006449 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6450 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006451 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006452 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006453 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306454 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306455 if (hdd_ctx->hbw_requested) {
6456 pld_remove_pm_qos(hdd_ctx->parent_dev);
6457 hdd_ctx->hbw_requested = false;
6458 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306459 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006460 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006461 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306462 if (!hdd_ctx->hbw_requested) {
6463 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6464 hdd_ctx->hbw_requested = true;
6465 }
6466
Nirav Shah3bbfa512016-05-12 16:43:49 +05306467 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006468 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006469 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006470 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006471 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006472
Mohit Khannaf8f96822017-05-17 17:11:59 -07006473 qdf_dp_trace_throttle_live_mode(
6474 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6475
Mohit Khannae71e2262015-11-10 09:37:24 -08006476 /* fine-tuning parameters for RX Flows */
6477 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6478
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006479 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006480
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306481 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6482 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6483 else
6484 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6485
Ravi Joshifed83572016-10-07 16:20:37 -07006486 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6487 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6488 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6489 next_rx_level = WLAN_SVC_TP_HIGH;
6490 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006491 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006492 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006493 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006494 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006495
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006496 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006497 struct wlan_rx_tp_data rx_tp_data = {0};
6498
Ravi Joshie2331e82015-07-01 18:18:54 -07006499 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006500 next_rx_level, temp_rx);
6501 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006502 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006503 /* Send throughput indication only if it is enabled.
6504 * Disabling tcp_del_ack will revert the tcp stack behavior
6505 * to default delayed ack. Note that this will disable the
6506 * dynamic delayed ack mechanism across the system
6507 */
6508 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006509 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6510
6511 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6512 rx_tp_data.level = next_rx_level;
6513 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6514 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6515 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006516 }
6517
Mohit Khannae71e2262015-11-10 09:37:24 -08006518 /* fine-tuning parameters for TX Flows */
6519 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6520 hdd_ctx->prev_tx = tx_packets;
6521 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6522 next_tx_level = WLAN_SVC_TP_HIGH;
6523 else
6524 next_tx_level = WLAN_SVC_TP_LOW;
6525
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006526 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006527 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6528 next_tx_level, temp_tx);
6529 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006530 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306531 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6532 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006533 &next_tx_level,
6534 sizeof(next_tx_level));
6535 }
6536
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006537 index = hdd_ctx->hdd_txrx_hist_idx;
6538
6539 if (vote_level_change || tx_level_change || rx_level_change) {
6540 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6541 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6542 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6543 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6544 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6545 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6546 hdd_ctx->hdd_txrx_hist_idx++;
6547 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6548 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006549}
6550
6551#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306552static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006553{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006554 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306555 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006556 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306557 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306558 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6559 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006560 uint64_t total_tx = 0, total_rx = 0;
6561 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306562 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306563 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006564 bool connected = false;
6565 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6566
Prashanth Bhattaab004382016-10-11 16:08:11 -07006567 if (wlan_hdd_validate_context(hdd_ctx))
6568 return;
6569
Jeff Johnson214671b2017-10-30 19:45:23 -07006570 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006571 goto restart_timer;
6572
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006573 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306574 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006575 status =
6576 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6577
Jeff Johnson57eb2732017-10-02 11:40:20 -07006578 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006579 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006580 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306581 /*
6582 * Validate magic so we don't end up accessing
6583 * an invalid adapter.
6584 */
6585 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6586 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006587
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006588 if ((adapter->device_mode == QDF_STA_MODE ||
6589 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006590 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6591 != eConnectionState_Associated) {
6592
6593 continue;
6594 }
6595
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006596 if ((adapter->device_mode == QDF_SAP_MODE ||
6597 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006598 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599
6600 continue;
6601 }
6602
6603 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6604 adapter->prev_tx_packets);
6605 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6606 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306607
6608 if (adapter->device_mode == QDF_SAP_MODE ||
6609 adapter->device_mode == QDF_P2P_GO_MODE ||
6610 adapter->device_mode == QDF_IBSS_MODE) {
6611
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006612 ret = cdp_get_intra_bss_fwd_pkts_count(
6613 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006614 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306615 &fwd_tx_packets, &fwd_rx_packets);
6616 if (ret == A_OK) {
6617 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6618 fwd_tx_packets,
6619 adapter->prev_fwd_tx_packets);
6620 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6621 fwd_tx_packets,
6622 adapter->prev_fwd_rx_packets);
6623 }
6624 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006625
6626 total_rx += adapter->stats.rx_packets;
6627 total_tx += adapter->stats.tx_packets;
6628
6629 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6630 adapter->prev_tx_packets = adapter->stats.tx_packets;
6631 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306632 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6633 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006634 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6635 connected = true;
6636 }
6637
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306638 /* add intra bss forwarded tx and rx packets */
6639 tx_packets += fwd_tx_packets_diff;
6640 rx_packets += fwd_rx_packets_diff;
6641
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006642 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6643 tx_packets += (uint64_t)ipa_tx_packets;
6644 rx_packets += (uint64_t)ipa_rx_packets;
6645
Yun Park2aa880c2017-08-22 10:58:10 -07006646 if (adapter) {
6647 adapter->stats.tx_packets += ipa_tx_packets;
6648 adapter->stats.rx_packets += ipa_rx_packets;
6649 }
6650
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006651 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006652 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006653 return;
6654 }
6655
Yuanyuan Liu13738502016-04-06 17:41:37 -07006656 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006657
6658 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6659 hdd_ipa_uc_stat_request(adapter, 2);
6660
Jingxiang Gec64e1932017-08-22 14:38:59 +08006661restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006662 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006663 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006664 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306665 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006666 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006667 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006668}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006669
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306670/**
6671 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6672 * @arg: Argument of timer function
6673 *
6674 * Schedule a workqueue in this function where all the processing is done.
6675 *
6676 * Return: None.
6677 */
6678static void __hdd_bus_bw_cbk(void *arg)
6679{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006680 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306681
6682 if (wlan_hdd_validate_context(hdd_ctx))
6683 return;
6684
6685 schedule_work(&hdd_ctx->bus_bw_work);
6686}
6687
6688/**
6689 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6690 * @arg: Argument of timer function
6691 *
6692 * Return: None.
6693 */
6694static void hdd_bus_bw_cbk(void *arg)
6695{
6696 cds_ssr_protect(__func__);
6697 __hdd_bus_bw_cbk(arg);
6698 cds_ssr_unprotect(__func__);
6699}
6700
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006701int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006702{
6703 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306704 INIT_WORK(&hdd_ctx->bus_bw_work,
6705 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006706 hdd_ctx->bus_bw_timer_running = false;
6707 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306708 qdf_timer_init(NULL,
6709 &hdd_ctx->bus_bw_timer,
6710 hdd_bus_bw_cbk, (void *)hdd_ctx,
6711 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006712
6713 return 0;
6714}
6715
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006716void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006717{
Dustin Brownfce08d12017-01-17 16:29:38 -08006718 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006719 hdd_reset_tcp_delack(hdd_ctx);
6720
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006721 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306722 cancel_work_sync(&hdd_ctx->bus_bw_work);
6723 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006724 hdd_ctx->bus_bw_timer_running = false;
6725 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006726}
Lin Baic5c06882017-09-21 13:58:43 +08006727
6728void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6729{
6730 if (hdd_ctx)
6731 cancel_work_sync(&hdd_ctx->bus_bw_work);
6732}
jiadcdaf9bd2017-10-26 12:20:21 +08006733
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006734#endif
6735
6736/**
Nirav Shahed34b212016-04-25 10:59:16 +05306737 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6738 * @hdd_ctx: hdd context
6739 *
6740 * Return: 0 for success or error code
6741 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006742static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306743{
6744 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6745 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6746 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006747 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306748 return -ENOMEM;
6749 }
6750 return 0;
6751}
6752
6753/**
6754 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6755 * @hdd_ctx: hdd context
6756 *
6757 * Return: none
6758 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006759void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306760{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306761 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6762 return;
6763
6764 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6765 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306766}
6767
Nirav Shahda008342016-05-17 18:50:40 +05306768static uint8_t *convert_level_to_string(uint32_t level)
6769{
6770 switch (level) {
6771 /* initialize the wlan sub system */
6772 case WLAN_SVC_TP_NONE:
6773 return "NONE";
6774 case WLAN_SVC_TP_LOW:
6775 return "LOW";
6776 case WLAN_SVC_TP_MEDIUM:
6777 return "MED";
6778 case WLAN_SVC_TP_HIGH:
6779 return "HIGH";
6780 default:
6781 return "INVAL";
6782 }
6783}
6784
Nirav Shahed34b212016-04-25 10:59:16 +05306785
6786/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006787 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6788 * @hdd_ctx: hdd context
6789 *
6790 * Return: none
6791 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006792void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006793{
6794 int i;
6795
6796#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006797 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306798 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006799 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800 hdd_ctx->config->busBandwidthHighThreshold,
6801 hdd_ctx->config->busBandwidthMediumThreshold,
6802 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006803 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306804 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006805 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006806 hdd_ctx->config->tcpDelackThresholdHigh,
6807 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006808 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306809 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006810#endif
6811
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006812 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306813 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6814
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006815 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006816
6817 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006818 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006819 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006820 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006821 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6822 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006823 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006824 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6825 convert_level_to_string(
6826 hdd_ctx->hdd_txrx_hist[i].
6827 next_vote_level),
6828 convert_level_to_string(
6829 hdd_ctx->hdd_txrx_hist[i].
6830 next_rx_level),
6831 convert_level_to_string(
6832 hdd_ctx->hdd_txrx_hist[i].
6833 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006834 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006835}
6836
6837/**
6838 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6839 * @hdd_ctx: hdd context
6840 *
6841 * Return: none
6842 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006843void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006844{
6845 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306846 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6847 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006848}
6849
6850/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006851 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006852 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006853 *
6854 * Return: none
6855 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006856void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006857{
6858
Jeff Johnson9d295242017-08-29 14:39:48 -07006859 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006860 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306861 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306863 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006864
6865 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306866 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006867 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006868
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006869 hdd_debug("Netif queue operation statistics:");
6870 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07006871 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006872 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306873 curr_time = qdf_system_ticks();
6874 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306875 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306876 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306877 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306878 unpause = adapter->total_unpause_time;
6879 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306880 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306881 pause = adapter->total_pause_time;
6882 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006883 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306884 qdf_system_ticks_to_msecs(total),
6885 qdf_system_ticks_to_msecs(pause),
6886 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006887 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888
Nirav Shahda008342016-05-17 18:50:40 +05306889 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6890 qdf_time_t pause_delta = 0;
6891
6892 if (adapter->pause_map & (1 << i))
6893 pause_delta = delta;
6894
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006895 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006896 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006897 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006898 hdd_reason_type_to_string(i),
6899 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306900 adapter->queue_oper_stats[i].unpause_count,
6901 qdf_system_ticks_to_msecs(
6902 adapter->queue_oper_stats[i].total_pause_time +
6903 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006904 }
6905
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006906 hdd_debug("Netif queue operation history:");
6907 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306908 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6909
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006910 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006911
6912 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006913 /* using hdd_log to avoid printing function name */
6914 if (adapter->queue_oper_history[i].time == 0)
6915 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006916 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006917 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306918 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006919 adapter->queue_oper_history[i].time),
6920 hdd_action_type_to_string(
6921 adapter->queue_oper_history[i].netif_action),
6922 hdd_reason_type_to_string(
6923 adapter->queue_oper_history[i].netif_reason),
6924 adapter->queue_oper_history[i].pause_map);
6925 }
6926
6927 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6928 adapter_node = next;
6929 }
6930
6931
6932}
6933
6934/**
6935 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6936 * @hdd_ctx: hdd context
6937 *
6938 * Return: none
6939 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006940void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006941{
Jeff Johnson9d295242017-08-29 14:39:48 -07006942 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006943 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306944 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006945
6946 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306947 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006948 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006949
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306950 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306952 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006953 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306954 adapter->history_index = 0;
6955 adapter->start_time = adapter->last_time = qdf_system_ticks();
6956 adapter->total_pause_time = 0;
6957 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006958 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6959 adapter_node = next;
6960 }
6961}
6962
6963/**
6964 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6965 * @halHandle: Hal handle
6966 * @pContext: Pointer to the context
6967 * @sessionId: Session ID
6968 * @scanId: Scan ID
6969 * @status: Status
6970 *
6971 * This is the callback to be executed when 11d scan is completed to flush out
6972 * the scan results
6973 *
6974 * 11d scan is done during driver load and is a passive scan on all
6975 * channels supported by the device, 11d scans may find some APs on
6976 * frequencies which are forbidden to be used in the regulatory domain
6977 * the device is operating in. If these APs are notified to the supplicant
6978 * it may try to connect to these APs, thus flush out all the scan results
6979 * which are present in SME after 11d scan is done.
6980 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306981 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006982 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306983static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006984 uint8_t sessionId, uint32_t scanId,
6985 eCsrScanStatus status)
6986{
6987 ENTER();
6988
6989 sme_scan_flush_result(halHandle);
6990
6991 EXIT();
6992
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306993 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006994}
6995
6996#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6997/**
6998 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6999 * @hdd_ctx: hdd global context
7000 *
7001 * Return: none
7002 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007003static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007004{
7005 uint8_t i;
7006
7007 mutex_init(&hdd_ctx->op_ctx.op_lock);
7008 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7009 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7010 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7011 }
7012}
7013#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007014static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007015{
7016}
7017#endif
7018
Yingying Tang95409972016-10-20 15:16:15 +08007019#ifdef WLAN_FEATURE_WOW_PULSE
7020/**
7021 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007022 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007023 * @enable: enable or disable this behaviour
7024 *
7025 * Return: int
7026 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007027static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007028{
7029 struct hdd_config *pcfg_ini = phddctx->config;
7030 struct wow_pulse_mode wow_pulse_set_info;
7031 QDF_STATUS status;
7032
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007033 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007034
7035 if (false == phddctx->config->wow_pulse_support)
7036 return 0;
7037
7038 /* prepare the request to send to SME */
7039 if (enable == true) {
7040 wow_pulse_set_info.wow_pulse_enable = true;
7041 wow_pulse_set_info.wow_pulse_pin =
7042 pcfg_ini->wow_pulse_pin;
7043 wow_pulse_set_info.wow_pulse_interval_low =
7044 pcfg_ini->wow_pulse_interval_low;
7045 wow_pulse_set_info.wow_pulse_interval_high =
7046 pcfg_ini->wow_pulse_interval_high;
7047 } else {
7048 wow_pulse_set_info.wow_pulse_enable = false;
7049 wow_pulse_set_info.wow_pulse_pin = 0;
7050 wow_pulse_set_info.wow_pulse_interval_low = 0;
7051 wow_pulse_set_info.wow_pulse_interval_high = 0;
7052 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007053 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007054 wow_pulse_set_info.wow_pulse_enable,
7055 wow_pulse_set_info.wow_pulse_pin,
7056 wow_pulse_set_info.wow_pulse_interval_low,
7057 wow_pulse_set_info.wow_pulse_interval_high);
7058
7059 status = sme_set_wow_pulse(&wow_pulse_set_info);
7060 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007061 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007062 return -EIO;
7063 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007064 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007065 return 0;
7066}
7067#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007068static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007069{
7070 return 0;
7071}
7072#endif
7073
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007074#ifdef WLAN_FEATURE_FASTPATH
7075/**
7076 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7077 * @hdd_cfg: hdd config
7078 * @context: lower layer context
7079 *
7080 * Return: none
7081 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307082void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007083 void *context)
7084{
7085 if (hdd_cfg->fastpath_enable)
7086 hif_enable_fastpath(context);
7087}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007088#endif
7089
Yuanyuan Liu13738502016-04-06 17:41:37 -07007090#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007091/**
7092 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007093 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007094 * @level: thermal level
7095 *
7096 * Change IPA data path to SW path when the thermal throttle level greater
7097 * than 0, and restore the original data path when throttle level is 0
7098 *
7099 * Return: none
7100 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007101static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007102{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007103 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007105 /* Change IPA to SW path when throttle level greater than 0 */
7106 if (level > THROTTLE_LEVEL_0)
7107 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7108 else
7109 /* restore original concurrency mode */
7110 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7111}
7112
7113/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307114 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7115 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307116 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007117 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307118 * Get a safe channel to restart SAP. PCL already takes into account the
7119 * unsafe channels. So, the PCL is validated with the ACS range to provide
7120 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007121 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307122 * Return: Channel number to restart SAP in case of success. In case of any
7123 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007124 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307125static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007126 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007127{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307128 struct sir_pcl_list pcl;
7129 QDF_STATUS status;
7130 uint32_t i, j;
7131 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007132 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307133 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007134
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307135 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7136 if (!hdd_ctx) {
7137 hdd_err("invalid HDD context");
7138 return INVALID_CHANNEL_ID;
7139 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007140
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307141 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7142 if (!hal_handle) {
7143 hdd_err("invalid HAL handle");
7144 return INVALID_CHANNEL_ID;
7145 }
7146
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007147 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7148 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007149 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7150 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307151 if (QDF_IS_STATUS_ERROR(status)) {
7152 hdd_err("Get PCL failed");
7153 return INVALID_CHANNEL_ID;
7154 }
7155
Frank Liudc2cefb2017-06-21 15:38:18 +08007156 /*
7157 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7158 * channel is unsafe channel, the pcl may be empty, instead of return,
7159 * try to choose a safe channel from acs range.
7160 */
7161 if (!pcl.pcl_len)
7162 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307163
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007164 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007165 adapter->session.ap.sap_config.acs_cfg.start_ch,
7166 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307167
7168 /* PCL already takes unsafe channel into account */
7169 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007170 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307171 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007172 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307173 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007174 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007175 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307176 return pcl.pcl_list[i];
7177 }
7178 }
7179
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007180 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307181
7182 /* Try for safe channel from all valid channel */
7183 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007184 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307185 &pcl.pcl_len);
7186 if (QDF_IS_STATUS_ERROR(status)) {
7187 hdd_err("error in getting valid channel list");
7188 return INVALID_CHANNEL_ID;
7189 }
7190
7191 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007192 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307193 found = false;
7194 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007195 if (pcl.pcl_list[i] ==
7196 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007197 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307198 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007199 break;
7200 }
7201 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307202
7203 if (found)
7204 continue;
7205
7206 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007207 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307208 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007209 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007210 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307211 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007212 }
7213 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307214
7215 return INVALID_CHANNEL_ID;
7216}
7217
7218/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007219 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307220 * @adapter: AP adapter
7221 * @channel: Channel
7222 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007223 * Moves the SAP interface by invoking the function which
7224 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307225 *
7226 * Return: None
7227 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007228void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307229{
Jeff Johnson87251032017-08-29 13:31:11 -07007230 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307231 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007232 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307233
7234 if (!adapter) {
7235 hdd_err("invalid adapter");
7236 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007237 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307238
7239 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7240
7241 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7242 if (!hal_handle) {
7243 hdd_err("invalid HAL handle");
7244 return;
7245 }
7246
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007247 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7248
Jeff Johnson91df29d2017-10-27 19:29:50 -07007249 hdd_ap_ctx->sap_config.channel = channel;
7250 hdd_ap_ctx->sap_config.ch_params.ch_width =
7251 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307252
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007253 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007254 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307255
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007256 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007257 hdd_ap_ctx->sap_config.channel,
7258 hdd_ap_ctx->sap_config.sec_ch,
7259 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307260
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007261 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007262 adapter->session_id, channel,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007263 hdd_ap_ctx->sap_config.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007264}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307265
Jeff Johnson9d295242017-08-29 14:39:48 -07007266int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307267{
7268 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307269 int status;
7270 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307271
7272 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7273
7274 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007275 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307276 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007277 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307278 }
7279 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007280 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307281 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307282 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007283 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307284 WLAN_VENDOR_ACS_WAIT_TIME);
7285 if (qdf_status != QDF_STATUS_SUCCESS) {
7286 hdd_err("failed to start external acs timer");
7287 return -ENOSPC;
7288 }
7289 /* Update config to application */
7290 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307291 hdd_notice("Updated ACS config to nl with reason %d", reason);
7292
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307293 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307294}
7295
Agrawal Ashish467dde42016-09-08 18:44:22 +05307296/**
7297 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7298 * @hdd_ctx: hdd context pointer
7299 *
7300 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7301 * and if ACS is enabled, driver will ask userspace to restart the
7302 * sap. User space on LTE coex indication restart driver.
7303 *
7304 * Return - none
7305 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007306void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307307{
7308 QDF_STATUS status;
7309 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007310 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307311 uint32_t i;
7312 bool found = false;
7313 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007314
Agrawal Ashish467dde42016-09-08 18:44:22 +05307315 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7316 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007317 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307318
7319 if (!adapter_temp) {
7320 hdd_err("adapter is NULL, moving to next one");
7321 goto next_adapater;
7322 }
7323
7324 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
Jeff Johnsonb9424862017-10-30 08:49:35 -07007325 (adapter_temp->session.ap.sap_config.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007326 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307327 adapter_temp->device_mode,
Jeff Johnsonb9424862017-10-30 08:49:35 -07007328 adapter_temp->session.ap.sap_config.
Agrawal Ashish467dde42016-09-08 18:44:22 +05307329 acs_cfg.acs_mode);
7330 goto next_adapater;
7331 }
7332
7333 found = false;
7334 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007335 if (adapter_temp->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307336 hdd_ctxt->unsafe_channel_list[i]) {
7337 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007338 hdd_debug("operating ch:%d is unsafe",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007339 adapter_temp->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307340 break;
7341 }
7342 }
7343
7344 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007345 hdd_debug("ch:%d is safe. no need to change channel",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007346 adapter_temp->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307347 goto next_adapater;
7348 }
7349
Kapil Gupta8878ad92017-02-13 11:56:04 +05307350 if (hdd_ctxt->config->vendor_acs_support &&
7351 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7352 hdd_update_acs_timer_reason(adapter_temp,
7353 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7354 goto next_adapater;
7355 } else
7356 restart_chan =
7357 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307358 adapter_temp);
7359 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007360 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307361 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007362 /*
7363 * SAP restart due to unsafe channel. While
7364 * restarting the SAP, make sure to clear
7365 * acs_channel, channel to reset to
7366 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307367 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007368 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307369 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007370 adapter_temp->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307371 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007372 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307373 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7374 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007375 hdd_debug("driver to start sap: %d",
7376 hdd_ctxt->config->sap_internal_restart);
7377 if (hdd_ctxt->config->sap_internal_restart)
7378 hdd_switch_sap_channel(adapter_temp, restart_chan);
7379 else
7380 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307381 }
7382
7383next_adapater:
7384 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7385 adapter_node = next;
7386 }
7387}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307388
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007389/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007390 * hdd_init_channel_avoidance() - Initialize channel avoidance
7391 * @hdd_ctx: HDD global context
7392 *
7393 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007394 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007395 * down to the lower layers. Then subscribe to subsequent channel
7396 * avoidance events.
7397 *
7398 * Return: None
7399 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007400static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007401{
7402 uint16_t unsafe_channel_count;
7403 int index;
7404
Yuanyuan Liu13738502016-04-06 17:41:37 -07007405 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7406 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007407 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007408 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007409
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007410 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007411 hdd_ctx->unsafe_channel_count);
7412
Anurag Chouhan6d760662016-02-20 16:05:43 +05307413 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007414 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007415
7416 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007417 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007418 hdd_ctx->unsafe_channel_list[index]);
7419
7420 }
7421
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007422}
Dustin Brown676a2322017-08-15 13:16:13 -07007423
Jeff Johnson9d295242017-08-29 14:39:48 -07007424static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007425 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007426{
7427 uint8_t restart_chan;
7428
7429 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7430 if (!restart_chan) {
7431 hdd_alert("fail to restart SAP");
7432 return;
7433 }
7434
7435 /* SAP restart due to unsafe channel. While restarting
7436 * the SAP, make sure to clear acs_channel, channel to
7437 * reset to 0. Otherwise these settings will override
7438 * the ACS while restart.
7439 */
7440 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007441 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007442
7443 hdd_debug("sending coex indication");
7444
7445 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7446 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7447 hdd_switch_sap_channel(adapter, restart_chan);
7448}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007449
7450int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7451 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7452{
7453 uint32_t size;
7454 uint16_t *unsafe_list;
7455 uint16_t chan_count;
7456
7457 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7458 return -EINVAL;
7459
7460 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7461 NUM_CHANNELS);
7462 if (chan_count) {
7463 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7464 unsafe_list = qdf_mem_malloc(size);
7465 if (!unsafe_list) {
7466 hdd_err("No memory for unsafe chan list size%d",
7467 size);
7468 return -ENOMEM;
7469 }
7470 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7471 } else {
7472 unsafe_list = NULL;
7473 }
7474
7475 *local_unsafe_list = unsafe_list;
7476 *local_unsafe_list_count = chan_count;
7477
7478 return 0;
7479}
7480
7481bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7482 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7483{
7484 int i, j;
7485
7486 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7487 return true;
7488 if (local_unsafe_list_count == 0)
7489 return false;
7490 for (i = 0; i < local_unsafe_list_count; i++) {
7491 for (j = 0; j < local_unsafe_list_count; j++)
7492 if (local_unsafe_list[i] ==
7493 hdd_ctx->unsafe_channel_list[j])
7494 break;
7495 if (j >= local_unsafe_list_count)
7496 break;
7497 }
7498 if (i >= local_unsafe_list_count) {
7499 hdd_info("unsafe chan list same");
7500 return false;
7501 }
7502
7503 return true;
7504}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007505#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007506static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007507{
7508}
Dustin Brown676a2322017-08-15 13:16:13 -07007509
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007510static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007511{
7512}
Dustin Brown676a2322017-08-15 13:16:13 -07007513
Jeff Johnson9d295242017-08-29 14:39:48 -07007514static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007515 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007516{
7517 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7518}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007519#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007520
7521/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007522 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7523 * user space
7524 * @frame_ind: Management frame data to be informed.
7525 *
7526 * This function is used to indicate management frame to
7527 * user space
7528 *
7529 * Return: None
7530 *
7531 */
7532void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7533{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007534 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007535 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007536 int i;
7537
Rajeev Kumard004abc2016-02-17 12:09:56 -08007538 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007539 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007540
7541 if (0 != wlan_hdd_validate_context(hdd_ctx))
7542 return;
7543
7544 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7545 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7546 adapter =
7547 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7548 if (adapter)
7549 break;
7550 }
7551 } else {
7552 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7553 frame_ind->sessionId);
7554 }
7555
7556 if ((NULL != adapter) &&
7557 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7558 __hdd_indicate_mgmt_frame(adapter,
7559 frame_ind->frame_len,
7560 frame_ind->frameBuf,
7561 frame_ind->frameType,
7562 frame_ind->rxChan,
7563 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007564}
7565
Kapil Gupta8878ad92017-02-13 11:56:04 +05307566void hdd_acs_response_timeout_handler(void *context)
7567{
7568 struct hdd_external_acs_timer_context *timer_context =
7569 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007570 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007571 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307572 uint8_t reason;
7573
7574 ENTER();
7575 if (!timer_context) {
7576 hdd_err("invlaid timer context");
7577 return;
7578 }
7579 adapter = timer_context->adapter;
7580 reason = timer_context->reason;
7581
7582
7583 if ((!adapter) ||
7584 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7585 hdd_err("invalid adapter or adapter has invalid magic");
7586 return;
7587 }
7588 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7589 if (wlan_hdd_validate_context(hdd_ctx))
7590 return;
7591
7592 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7593 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7594 else
7595 return;
7596
7597 hdd_err("ACS timeout happened for %s reason %d",
7598 adapter->dev->name, reason);
7599 switch (reason) {
7600 /* SAP init case */
7601 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7602 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7603 false);
7604 wlan_hdd_cfg80211_start_acs(adapter);
7605 break;
7606 /* DFS detected on current channel */
7607 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7608 wlan_sap_update_next_channel(
7609 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7610 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007611 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307612 break;
7613 /* LTE coex event on current channel */
7614 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7615 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7616 break;
7617 default:
7618 hdd_info("invalid reason for timer invoke");
7619
7620 }
7621}
7622
Rajeev Kumard004abc2016-02-17 12:09:56 -08007623/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007624 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7625 * @hdd_ctx: HDD context
7626 *
7627 * Disables all the dual mac features like DBS, Agile DFS etc.
7628 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307629 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007630 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007631static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007632{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007633 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307634 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007635
7636 if (!hdd_ctx) {
7637 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307638 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007639 }
7640
7641 cfg.scan_config = 0;
7642 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007643 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007644
7645 hdd_debug("Disabling all dual mac features...");
7646
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007647 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307648 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007649 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7650 return status;
7651 }
7652
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307653 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007654}
7655
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007656static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007657wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007658{
7659 struct policy_mgr_dual_mac_config cfg = {0};
7660 QDF_STATUS status;
7661
7662 if (!hdd_ctx) {
7663 hdd_err("HDD context is NULL");
7664 return QDF_STATUS_E_FAILURE;
7665 }
7666
7667 cfg.scan_config = 0;
7668 cfg.fw_mode_config = 0;
7669 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7670 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7671 hdd_ctx->hdd_psoc, &cfg.scan_config,
7672 &cfg.fw_mode_config,
7673 hdd_ctx->config->dual_mac_feature_disable);
7674
7675 if (status != QDF_STATUS_SUCCESS) {
7676 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7677 status);
7678 return status;
7679 }
7680
7681 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7682 cfg.scan_config, cfg.fw_mode_config);
7683
7684 status = sme_soc_set_dual_mac_config(cfg);
7685 if (status != QDF_STATUS_SUCCESS) {
7686 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7687 return status;
7688 }
7689
7690 return QDF_STATUS_SUCCESS;
7691}
7692
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007693/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007694 * hdd_override_ini_config - Override INI config
7695 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007696 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007697 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007698 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007699 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007700 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007701static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007702{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007703
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007704 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7705 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007706 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007707 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007708 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007709 if (0 == enable_11d || 1 == enable_11d) {
7710 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007711 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007712 }
Leo Chang11545d62016-10-17 14:53:50 -07007713
7714 if (!hdd_ipa_is_present(hdd_ctx))
7715 hdd_ctx->config->IpaConfig = 0;
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05307716
7717 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
7718 !hdd_ctx->config->enable_bcast_probe_rsp) {
7719 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
7720 hdd_ctx->config->rssi_assoc_reject_enabled,
7721 hdd_ctx->config->enable_bcast_probe_rsp);
7722 hdd_ctx->config->oce_sta_enabled = 0;
7723 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007724}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007725
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007726/**
7727 * hdd_set_trace_level_for_each - Set trace level for each INI config
7728 * @hdd_ctx - HDD context
7729 *
7730 * Set trace level for each module based on INI config.
7731 *
7732 * Return: None
7733 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007734static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007735{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307736 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7737 hdd_ctx->config->qdf_trace_enable_wdi);
7738 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7739 hdd_ctx->config->qdf_trace_enable_hdd);
7740 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7741 hdd_ctx->config->qdf_trace_enable_sme);
7742 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7743 hdd_ctx->config->qdf_trace_enable_pe);
7744 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7745 hdd_ctx->config->qdf_trace_enable_wma);
7746 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7747 hdd_ctx->config->qdf_trace_enable_sys);
7748 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7749 hdd_ctx->config->qdf_trace_enable_qdf);
7750 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7751 hdd_ctx->config->qdf_trace_enable_sap);
7752 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7753 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7754 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7755 hdd_ctx->config->qdf_trace_enable_bmi);
7756 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7757 hdd_ctx->config->qdf_trace_enable_cfg);
7758 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7759 hdd_ctx->config->qdf_trace_enable_epping);
7760 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7761 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7762 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007763 hdd_ctx->config->qdf_trace_enable_txrx);
7764 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7765 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307766 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7767 hdd_ctx->config->qdf_trace_enable_htc);
7768 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7769 hdd_ctx->config->qdf_trace_enable_hif);
7770 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7771 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7772 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7773 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007774 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7775 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007776 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7777 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007778 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7779 hdd_ctx->config->qdf_trace_enable_regulatory);
7780
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007781 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007782}
7783
7784/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007785 * hdd_context_init() - Initialize HDD context
7786 * @hdd_ctx: HDD context.
7787 *
7788 * Initialize HDD context along with all the feature specific contexts.
7789 *
7790 * return: 0 on success and errno on failure.
7791 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007792static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007793{
7794 int ret;
7795
7796 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7797 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7798
7799 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307800 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007801
7802 init_completion(&hdd_ctx->mc_sus_event_var);
7803 init_completion(&hdd_ctx->ready_to_suspend);
7804
7805 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307806 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007807 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307808
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007809 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007810
7811 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7812
7813 ret = hdd_scan_context_init(hdd_ctx);
7814 if (ret)
7815 goto list_destroy;
7816
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007817 hdd_rx_wake_lock_create(hdd_ctx);
7818
7819 ret = hdd_sap_context_init(hdd_ctx);
7820 if (ret)
7821 goto scan_destroy;
7822
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007823 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7824
7825 hdd_init_offloaded_packets_ctx(hdd_ctx);
7826
7827 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7828 hdd_ctx->config);
7829 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08007830 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007831
7832 return 0;
7833
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007834sap_destroy:
7835 hdd_sap_context_destroy(hdd_ctx);
7836
7837scan_destroy:
7838 hdd_scan_context_destroy(hdd_ctx);
7839 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007840list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007841 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007842
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007843 return ret;
7844}
7845
7846/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307847 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7848 * @hdd_ctx: pointer to hdd context
7849 *
7850 * Return: status of initialization
7851 * 0 - success
7852 * negative value - failure
7853 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007854static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307855{
7856 int ret;
7857
7858 if (!hdd_ctx->config->probe_req_ie_whitelist)
7859 return 0;
7860
7861 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7862 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7863 hdd_ctx->config->probe_req_ie_whitelist = false;
7864 return -EINVAL;
7865 }
7866
7867 /* parse ini string probe req oui */
7868 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7869 if (ret) {
7870 hdd_err("parsing error: disable ie whitelisting");
7871 hdd_ctx->config->probe_req_ie_whitelist = false;
7872 }
7873
7874 return ret;
7875}
7876
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05307877
7878/**
7879 * hdd_iface_change_callback() - Function invoked when stop modules expires
7880 * @priv: pointer to hdd context
7881 *
7882 * This function is invoked when the timer waiting for the interface change
7883 * expires, it shall cut-down the power to wlan and stop all the modules.
7884 *
7885 * Return: void
7886 */
7887static void hdd_iface_change_callback(void *priv)
7888{
7889 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
7890 int ret;
7891 int status = wlan_hdd_validate_context(hdd_ctx);
7892
7893 if (status)
7894 return;
7895
7896 ENTER();
7897 hdd_debug("Interface change timer expired close the modules!");
7898 ret = hdd_wlan_stop_modules(hdd_ctx, false);
7899 if (ret)
7900 hdd_err("Failed to stop modules");
7901 EXIT();
7902}
7903
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307904/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007905 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307906 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007907 *
7908 * Allocate and initialize HDD context. HDD context is allocated as part of
7909 * wiphy allocation and then context is initialized.
7910 *
7911 * Return: HDD context on success and ERR_PTR on failure
7912 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007913static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007914{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307915 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007916 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007917 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007918
7919 ENTER();
7920
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007921 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007922 if (hdd_ctx == NULL) {
7923 ret = -ENOMEM;
7924 goto err_out;
7925 }
7926
Dustin Brown6f427922017-09-19 12:19:00 -07007927 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
7928 hdd_iface_change_callback,
7929 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05307930
7931 mutex_init(&hdd_ctx->iface_change_lock);
7932
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007933 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307934 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007935
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307936 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007937 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007938 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007939 ret = -ENOMEM;
7940 goto err_free_hdd_context;
7941 }
7942
7943 /* Read and parse the qcom_cfg.ini file */
7944 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307945 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307946 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007947 WLAN_INI_FILE);
7948 ret = -EINVAL;
7949 goto err_free_config;
7950 }
7951
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307952 ie_whitelist_attrs_init(hdd_ctx);
7953
Dustin Brown7f939932017-05-18 15:02:17 -07007954 hdd_debug("setting timer multiplier: %u",
7955 hdd_ctx->config->timer_multiplier);
7956 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7957
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007958
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307959 if (hdd_ctx->config->fhostNSOffload)
7960 hdd_ctx->ns_offload_enable = true;
7961
Abhishek Singh5ea86532016-04-27 14:10:53 +05307962 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7963
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007964 hdd_override_ini_config(hdd_ctx);
7965
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007966 ret = hdd_context_init(hdd_ctx);
7967
7968 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007969 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007970
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007971 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307972 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007973
Anurag Chouhan6d760662016-02-20 16:05:43 +05307974 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007975 goto skip_multicast_logging;
7976
7977 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7978
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007979 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7980 if (ret)
7981 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307982
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007983 ret = hdd_init_netlink_services(hdd_ctx);
7984 if (ret)
7985 goto err_deinit_txrx_histogram;
7986
Dustin Brown7b3dea22017-07-10 13:02:47 -07007987 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7988 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307989
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007990skip_multicast_logging:
7991 hdd_set_trace_level_for_each(hdd_ctx);
7992
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007993 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7994
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007995 EXIT();
7996
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007997 return hdd_ctx;
7998
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007999err_deinit_txrx_histogram:
8000 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8001
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008002err_deinit_hdd_context:
8003 hdd_context_deinit(hdd_ctx);
8004
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008005err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308006 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008007
8008err_free_hdd_context:
8009 wiphy_free(hdd_ctx->wiphy);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308010 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008011
8012err_out:
8013 return ERR_PTR(ret);
8014}
8015
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008016#ifdef WLAN_OPEN_P2P_INTERFACE
8017/**
8018 * hdd_open_p2p_interface - Open P2P interface
8019 * @hdd_ctx: HDD context
8020 * @rtnl_held: True if RTNL lock held
8021 *
8022 * Open P2P interface during probe. This function called to open the P2P
8023 * interface at probe along with STA interface.
8024 *
8025 * Return: 0 on success and errno on failure
8026 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008027static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008028{
Jeff Johnson9d295242017-08-29 14:39:48 -07008029 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008030 uint8_t *p2p_dev_addr;
8031
8032 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8033 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008034 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008035 hdd_ctx->config->intfMacAddr[0].bytes,
8036 sizeof(tSirMacAddr));
8037
8038 /*
8039 * Generate the P2P Device Address. This consists of
8040 * the device's primary MAC address with the locally
8041 * administered bit set.
8042 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008043 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008044 } else {
8045 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8046 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008047 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008048 return -ENOSPC;
8049 }
8050
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008051 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8052 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008053 }
8054
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008055 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008056 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008057 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008058
8059 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008060 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008061 return -ENOSPC;
8062 }
8063
8064 return 0;
8065}
8066#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008067static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008068 bool rtnl_held)
8069{
8070 return 0;
8071}
8072#endif
8073
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008074static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008075{
Jeff Johnson9d295242017-08-29 14:39:48 -07008076 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008077 int ret = 0;
8078
8079 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8080 wlan_hdd_get_intf_addr(hdd_ctx),
8081 NET_NAME_UNKNOWN, rtnl_held);
8082 if (adapter == NULL) {
8083 hdd_err("Failed to open 802.11p interface");
8084 ret = -ENOSPC;
8085 }
8086
8087 return ret;
8088}
8089
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008090/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308091 * hdd_start_station_adapter()- Start the Station Adapter
8092 * @adapter: HDD adapter
8093 *
8094 * This function initializes the adapter for the station mode.
8095 *
8096 * Return: 0 on success or errno on failure.
8097 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008098int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308099{
8100 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008101 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308102
8103 ENTER_DEV(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008104 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8105 hdd_err("session is already opened, %d",
8106 adapter->session_id);
8107 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8108 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308109
Krunal Sonib51eec72017-11-20 21:53:01 -08008110 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8111 if (ret) {
8112 hdd_err("failed to create vdev: %d", ret);
8113 return ret;
8114 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308115 status = hdd_init_station_mode(adapter);
8116
8117 if (QDF_STATUS_SUCCESS != status) {
8118 hdd_err("Error Initializing station mode: %d", status);
8119 return qdf_status_to_os_return(status);
8120 }
8121
Arun Khandavallifae92942016-08-01 13:31:08 +05308122 hdd_register_tx_flow_control(adapter,
8123 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008124 hdd_tx_resume_cb,
8125 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308126
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308127 EXIT();
8128 return 0;
8129}
8130
8131/**
8132 * hdd_start_ap_adapter()- Start AP Adapter
8133 * @adapter: HDD adapter
8134 *
8135 * This function initializes the adapter for the AP mode.
8136 *
8137 * Return: 0 on success errno on failure.
8138 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008139int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308140{
8141 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008142 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308143
8144 ENTER();
8145
Krunal Sonib51eec72017-11-20 21:53:01 -08008146 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8147 hdd_err("session is already opened, %d",
8148 adapter->session_id);
8149 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8150 }
8151 /*
8152 * create sap context first and then create vdev as
8153 * while creating the vdev, driver needs to register
8154 * SAP callback and that callback uses sap context
8155 */
8156 if (!adapter->session.ap.sap_context &&
8157 !hdd_sap_create_ctx(adapter)) {
8158 hdd_err("sap creation failed");
8159 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8160 }
8161
8162 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8163 adapter->session.ap.sap_context);
8164 if (ret) {
8165 hdd_err("failed to create vdev, status:%d", ret);
8166 hdd_sap_destroy_ctx(adapter);
8167 return ret;
8168 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05308169 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308170
8171 if (QDF_STATUS_SUCCESS != status) {
8172 hdd_err("Error Initializing the AP mode: %d", status);
8173 return qdf_status_to_os_return(status);
8174 }
8175
Arun Khandavallifae92942016-08-01 13:31:08 +05308176 hdd_register_tx_flow_control(adapter,
8177 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008178 hdd_softap_tx_resume_cb,
8179 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308180
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308181 EXIT();
8182 return 0;
8183}
8184
8185/**
8186 * hdd_start_ftm_adapter()- Start FTM adapter
8187 * @adapter: HDD adapter
8188 *
8189 * This function initializes the adapter for the FTM mode.
8190 *
8191 * Return: 0 on success or errno on failure.
8192 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008193int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308194{
8195 QDF_STATUS qdf_status;
8196
8197 ENTER_DEV(adapter->dev);
8198
8199 qdf_status = hdd_init_tx_rx(adapter);
8200
8201 if (QDF_STATUS_SUCCESS != qdf_status) {
8202 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8203 return qdf_status_to_os_return(qdf_status);
8204 }
8205
8206 return 0;
8207 EXIT();
8208}
8209
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308210static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8211 bool rtnl_held)
8212{
8213 struct hdd_adapter *adapter;
8214
8215 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8216 hdd_ctx->config->enableConcurrentSTA,
8217 wlan_hdd_get_intf_addr(hdd_ctx),
8218 NET_NAME_UNKNOWN, rtnl_held);
8219
8220 if (!adapter)
8221 return -ENOSPC;
8222
8223 return 0;
8224}
8225
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308226/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008227 * hdd_open_interfaces - Open all required interfaces
8228 * hdd_ctx: HDD context
8229 * rtnl_held: True if RTNL lock is held
8230 *
8231 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8232 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008233 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008234 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008235static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008236{
Jeff Johnson9d295242017-08-29 14:39:48 -07008237 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008238 int ret;
8239
Ravi Joshia307f632017-07-17 23:41:41 -07008240 /* open monitor mode adapter if con_mode is monitor mode */
8241 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8242 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8243 wlan_hdd_get_intf_addr(hdd_ctx),
8244 NET_NAME_UNKNOWN, rtnl_held);
8245 if (!adapter) {
8246 hdd_err("open adapter failed");
8247 return -ENOSPC;
8248 }
8249 return 0;
8250 }
8251
Jeff Johnson957bc272017-02-02 08:54:48 -08008252 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308253 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008254 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008255
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008256 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008257 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008258 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008259
8260 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008261 return -ENOSPC;
8262
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008263 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8264 adapter->fast_roaming_allowed = true;
8265
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308266 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8267 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8268 if (ret)
8269 hdd_err("Cannot create concurrent STA interface");
8270 }
8271
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008272 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8273 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008274 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008275
8276 /* Open 802.11p Interface */
8277 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008278 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8279 if (ret)
8280 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008281 }
8282
Jeff Johnson957bc272017-02-02 08:54:48 -08008283 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008284
Jeff Johnson957bc272017-02-02 08:54:48 -08008285err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008286 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008287 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008288}
8289
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008290/**
8291 * hdd_update_country_code - Update country code
8292 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008293 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008294 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008295 *
8296 * Return: 0 on success and errno on failure
8297 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008298static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008299{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008300 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008301 return 0;
8302
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008303 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008304}
8305
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308306#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8307/**
8308 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8309 * @cds_cfg: CDS Configuration
8310 * @hdd_ctx: Pointer to hdd context
8311 *
8312 * Return: none
8313 */
8314static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8315 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008316 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308317{
8318 cds_cfg->tx_flow_stop_queue_th =
8319 hdd_ctx->config->TxFlowStopQueueThreshold;
8320 cds_cfg->tx_flow_start_queue_offset =
8321 hdd_ctx->config->TxFlowStartQueueOffset;
8322}
8323#else
8324static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8325 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008326 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308327{
8328}
8329#endif
8330
8331#ifdef FEATURE_WLAN_RA_FILTERING
8332/**
8333 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8334 * @cds_cfg: CDS Configuration
8335 * @hdd_ctx: Pointer to hdd context
8336 *
8337 * Return: none
8338 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308339static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008340 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308341{
8342 cds_cfg->ra_ratelimit_interval =
8343 hdd_ctx->config->RArateLimitInterval;
8344 cds_cfg->is_ra_ratelimit_enabled =
8345 hdd_ctx->config->IsRArateLimitEnabled;
8346}
8347#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308348static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008349 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308350{
8351}
8352#endif
8353
8354/**
8355 * hdd_update_cds_config() - API to update cds configuration parameters
8356 * @hdd_ctx: HDD Context
8357 *
8358 * Return: 0 for Success, errno on failure
8359 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008360static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308361{
8362 struct cds_config_info *cds_cfg;
8363
8364 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8365 if (!cds_cfg) {
8366 hdd_err("failed to allocate cds config");
8367 return -ENOMEM;
8368 }
8369
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008370 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008371 if (!hdd_ctx->config->nMaxPsPoll ||
8372 !hdd_ctx->config->enablePowersaveOffload) {
8373 cds_cfg->powersave_offload_enabled =
8374 hdd_ctx->config->enablePowersaveOffload;
8375 } else {
8376 if ((hdd_ctx->config->enablePowersaveOffload ==
8377 PS_QPOWER_NODEEPSLEEP) ||
8378 (hdd_ctx->config->enablePowersaveOffload ==
8379 PS_LEGACY_NODEEPSLEEP))
8380 cds_cfg->powersave_offload_enabled =
8381 PS_LEGACY_NODEEPSLEEP;
8382 else
8383 cds_cfg->powersave_offload_enabled =
8384 PS_LEGACY_DEEPSLEEP;
8385 hdd_info("Qpower disabled in cds config, %d",
8386 cds_cfg->powersave_offload_enabled);
8387 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308388 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8389 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8390 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8391 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8392 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8393
8394 /* Here ol_ini_info is used to store ini status of arp offload
8395 * ns offload and others. Currently 1st bit is used for arp
8396 * off load and 2nd bit for ns offload currently, rest bits are unused
8397 */
8398 if (hdd_ctx->config->fhostArpOffload)
8399 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8400 if (hdd_ctx->config->fhostNSOffload)
8401 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8402
8403 /*
8404 * Copy the DFS Phyerr Filtering Offload status.
8405 * This parameter reflects the value of the
8406 * dfs_phyerr_filter_offload flag as set in the ini.
8407 */
8408 cds_cfg->dfs_phyerr_filter_offload =
8409 hdd_ctx->config->fDfsPhyerrFilterOffload;
8410 if (hdd_ctx->config->ssdp)
8411 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8412
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308413 cds_cfg->force_target_assert_enabled =
8414 hdd_ctx->config->crash_inject_enabled;
8415
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308416 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8417 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8418
8419 cds_cfg->ap_maxoffload_reorderbuffs =
8420 hdd_ctx->config->apMaxOffloadReorderBuffs;
8421
8422 cds_cfg->ap_disable_intrabss_fwd =
8423 hdd_ctx->config->apDisableIntraBssFwd;
8424
8425 cds_cfg->dfs_pri_multiplier =
8426 hdd_ctx->config->dfsRadarPriMultiplier;
8427 cds_cfg->reorder_offload =
8428 hdd_ctx->config->reorderOffloadSupport;
8429
8430 /* IPA micro controller data path offload resource config item */
8431 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008432 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8433 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008434 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008435 hdd_ctx->config->IpaUcTxBufCount);
8436 hdd_ctx->config->IpaUcTxBufCount =
8437 rounddown_pow_of_two(
8438 hdd_ctx->config->IpaUcTxBufCount);
8439 if (!hdd_ctx->config->IpaUcTxBufCount) {
8440 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308441 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008442 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008443 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008444 hdd_ctx->config->IpaUcTxBufCount);
8445 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308446 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8447 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008448 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8449 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008450 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008451 hdd_ctx->config->IpaUcRxIndRingCount);
8452 hdd_ctx->config->IpaUcRxIndRingCount =
8453 rounddown_pow_of_two(
8454 hdd_ctx->config->IpaUcRxIndRingCount);
8455 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8456 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308457 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008458 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008459 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008460 hdd_ctx->config->IpaUcRxIndRingCount);
8461 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308462 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008463 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308464 cds_cfg->uc_tx_partition_base =
8465 hdd_ctx->config->IpaUcTxPartitionBase;
8466 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8467
8468 cds_cfg->ip_tcp_udp_checksum_offload =
8469 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008470 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308471 cds_cfg->ce_classify_enabled =
8472 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008473 cds_cfg->bpf_packet_filter_enable =
8474 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308475 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8476 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8477 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008478 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008479 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008480 cds_cfg->max_msdus_per_rxinorderind =
8481 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008482 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008483 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308484 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8485 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308486 cds_cfg->auto_power_save_fail_mode =
8487 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308488
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308489 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008490 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308491
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308492 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8493 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8494 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008495 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308496 cds_init_ini_config(cds_cfg);
8497 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308498
8499exit:
8500 qdf_mem_free(cds_cfg);
8501 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308502}
8503
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008504/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008505 * hdd_update_user_config() - API to update user configuration
8506 * parameters to obj mgr which are used by multiple components
8507 * @hdd_ctx: HDD Context
8508 *
8509 * Return: 0 for Success, errno on failure
8510 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008511static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008512{
8513 struct wlan_objmgr_psoc_user_config *user_config;
8514
8515 user_config = qdf_mem_malloc(sizeof(*user_config));
8516 if (user_config == NULL) {
8517 hdd_alert("Failed to alloc memory for user_config!");
8518 return -ENOMEM;
8519 }
8520
8521 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8522 user_config->dual_mac_feature_disable =
8523 hdd_ctx->config->dual_mac_feature_disable;
8524 user_config->indoor_channel_support =
8525 hdd_ctx->config->indoor_channel_support;
8526 user_config->is_11d_support_enabled =
8527 hdd_ctx->config->Is11dSupportEnabled;
8528 user_config->is_11h_support_enabled =
8529 hdd_ctx->config->Is11hSupportEnabled;
8530 user_config->optimize_chan_avoid_event =
8531 hdd_ctx->config->goptimize_chan_avoid_event;
8532 user_config->skip_dfs_chnl_in_p2p_search =
8533 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008534 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008535 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8536
8537 qdf_mem_free(user_config);
8538 return 0;
8539}
8540
8541/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008542 * hdd_init_thermal_info - Initialize thermal level
8543 * @hdd_ctx: HDD context
8544 *
8545 * Initialize thermal level at SME layer and set the thermal level callback
8546 * which would be called when a configured thermal threshold is hit.
8547 *
8548 * Return: 0 on success and errno on failure
8549 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008550static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008551{
8552 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308553 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008554
8555 thermal_param.smeThermalMgmtEnabled =
8556 hdd_ctx->config->thermalMitigationEnable;
8557 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8558
Poddar, Siddarth83905022016-04-16 17:56:08 -07008559 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8560 hdd_ctx->config->throttle_dutycycle_level0;
8561 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8562 hdd_ctx->config->throttle_dutycycle_level1;
8563 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8564 hdd_ctx->config->throttle_dutycycle_level2;
8565 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8566 hdd_ctx->config->throttle_dutycycle_level3;
8567
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008568 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8569 hdd_ctx->config->thermalTempMinLevel0;
8570 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8571 hdd_ctx->config->thermalTempMaxLevel0;
8572 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8573 hdd_ctx->config->thermalTempMinLevel1;
8574 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8575 hdd_ctx->config->thermalTempMaxLevel1;
8576 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8577 hdd_ctx->config->thermalTempMinLevel2;
8578 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8579 hdd_ctx->config->thermalTempMaxLevel2;
8580 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8581 hdd_ctx->config->thermalTempMinLevel3;
8582 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8583 hdd_ctx->config->thermalTempMaxLevel3;
8584
8585 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8586
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308587 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308588 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008589
8590 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8591 hdd_set_thermal_level_cb);
8592
8593 return 0;
8594
8595}
8596
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008597#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8598/**
8599 * hdd_hold_rtnl_lock - Hold RTNL lock
8600 *
8601 * Hold RTNL lock
8602 *
8603 * Return: True if held and false otherwise
8604 */
8605static inline bool hdd_hold_rtnl_lock(void)
8606{
8607 rtnl_lock();
8608 return true;
8609}
8610
8611/**
8612 * hdd_release_rtnl_lock - Release RTNL lock
8613 *
8614 * Release RTNL lock
8615 *
8616 * Return: None
8617 */
8618static inline void hdd_release_rtnl_lock(void)
8619{
8620 rtnl_unlock();
8621}
8622#else
8623static inline bool hdd_hold_rtnl_lock(void) { return false; }
8624static inline void hdd_release_rtnl_lock(void) { }
8625#endif
8626
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008627#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008628
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308629/* MAX iwpriv command support */
8630#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308631#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308632#define MAX_PKTLOG_SIZE 16
8633
8634/**
8635 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8636 * @hdd_ctx: hdd context
8637 * @set_value2: pktlog buffer size value
8638 *
8639 *
8640 * Return: 0 for success or error.
8641 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008642static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308643{
8644 struct sir_wifi_start_log start_log = { 0 };
8645 QDF_STATUS status;
8646
8647 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8648 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8649 start_log.ini_triggered = cds_is_packet_log_enabled();
8650 start_log.user_triggered = 1;
8651 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308652 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308653
8654 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8655 if (!QDF_IS_STATUS_SUCCESS(status)) {
8656 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8657 EXIT();
8658 return -EINVAL;
8659 }
8660
8661 return 0;
8662}
8663
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008664/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308665 * hdd_pktlog_clear_buff() - clear pktlog buffer
8666 * @hdd_ctx: hdd context
8667 *
8668 * Return: 0 for success or error.
8669 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008670static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308671{
8672 struct sir_wifi_start_log start_log;
8673 QDF_STATUS status;
8674
8675 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8676 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8677 start_log.ini_triggered = cds_is_packet_log_enabled();
8678 start_log.user_triggered = 1;
8679 start_log.size = 0;
8680 start_log.is_pktlog_buff_clear = true;
8681
8682 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8683 if (!QDF_IS_STATUS_SUCCESS(status)) {
8684 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8685 EXIT();
8686 return -EINVAL;
8687 }
8688
8689 return 0;
8690}
8691
8692
8693/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008694 * hdd_process_pktlog_command() - process pktlog command
8695 * @hdd_ctx: hdd context
8696 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308697 * @set_value2: pktlog buffer size value
8698 *
8699 * This function process pktlog command.
8700 * set_value2 only matters when set_value is 3 (set buff size)
8701 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008702 *
8703 * Return: 0 for success or error.
8704 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008705int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308706 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008707{
8708 int ret;
8709 bool enable;
8710 uint8_t user_triggered = 0;
8711
8712 ret = wlan_hdd_validate_context(hdd_ctx);
8713 if (0 != ret)
8714 return ret;
8715
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008716 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008717
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308718 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008719 hdd_err("invalid pktlog value %d", set_value);
8720 return -EINVAL;
8721 }
8722
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308723 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8724 if (set_value2 <= 0) {
8725 hdd_err("invalid pktlog size %d", set_value2);
8726 return -EINVAL;
8727 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8728 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8729 return -EINVAL;
8730 }
8731 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308732 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8733 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308734 }
8735
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008736 /*
8737 * set_value = 0 then disable packetlog
8738 * set_value = 1 enable packetlog forcefully
8739 * set_vlaue = 2 then disable packetlog if disabled through ini or
8740 * enable packetlog with AUTO type.
8741 */
8742 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8743 true : false;
8744
8745 if (1 == set_value) {
8746 enable = true;
8747 user_triggered = 1;
8748 }
8749
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308750 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008751}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008752
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008753/**
8754 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8755 * @hdd_ctx: HDD context
8756 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308757 * @user_triggered: triggered through iwpriv
8758 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008759 *
8760 * Return: 0 on success; error number otherwise
8761 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008762int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308763 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008764{
8765 struct sir_wifi_start_log start_log;
8766 QDF_STATUS status;
8767
8768 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8769 start_log.verbose_level =
8770 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008771 start_log.ini_triggered = cds_is_packet_log_enabled();
8772 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308773 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308774 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308775 /*
8776 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8777 * commands. Host uses this flag to decide whether to send pktlog
8778 * disable command to fw without sending pktlog enable command
8779 * previously. For eg, If vendor sends pktlog disable command without
8780 * sending pktlog enable command, then host discards the packet
8781 * but for iwpriv command, host will send it to fw.
8782 */
8783 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008784 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8785 if (!QDF_IS_STATUS_SUCCESS(status)) {
8786 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8787 EXIT();
8788 return -EINVAL;
8789 }
8790
8791 return 0;
8792}
8793#endif /* REMOVE_PKT_LOG */
8794
Komal Seelam92fff912016-03-24 11:51:41 +05308795/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008796 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8797 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308798 * @dev: Device Pointer
8799 * @num: Number of Valid Mac address
8800 *
8801 * Return: Pointer to MAC address buffer
8802 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008803static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8804 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308805{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008806 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308807}
Komal Seelam92fff912016-03-24 11:51:41 +05308808
8809/**
8810 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8811 * @hdd_ctx: HDD Context
8812 * @num: Number of random mac addresses needed
8813 *
8814 * Generate random addresses using bit manipulation on the base mac address
8815 *
8816 * Return: None
8817 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008818void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308819{
8820 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8821 uint32_t iter;
8822 struct hdd_config *ini = hdd_ctx->config;
8823 uint8_t *buf = NULL;
8824 uint8_t macaddr_b3, tmp_br3;
8825 uint8_t *src = ini->intfMacAddr[0].bytes;
8826
8827 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8828 buf = ini->intfMacAddr[iter].bytes;
8829 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8830 macaddr_b3 = buf[3];
8831 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8832 INTF_MACADDR_MASK;
8833 macaddr_b3 += tmp_br3;
8834 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8835 buf[0] |= 0x02;
8836 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008837 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308838 }
8839}
8840
8841/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008842 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308843 * @hdd_ctx: HDD Context
8844 *
8845 * API to get mac addresses from platform driver and update the driver
8846 * structures and configure FW with the base mac address.
8847 * Return: int
8848 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008849static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308850{
8851 uint32_t no_of_mac_addr, iter;
8852 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8853 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8854 uint8_t *addr, *buf;
8855 struct device *dev = hdd_ctx->parent_dev;
8856 struct hdd_config *ini = hdd_ctx->config;
8857 tSirMacAddr mac_addr;
8858 QDF_STATUS status;
8859
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008860 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308861
8862 if (no_of_mac_addr == 0 || !addr) {
8863 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8864 return -EINVAL;
8865 }
8866
8867 if (no_of_mac_addr > max_mac_addr)
8868 no_of_mac_addr = max_mac_addr;
8869
8870 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8871
8872 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8873 buf = ini->intfMacAddr[iter].bytes;
8874 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008875 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308876 }
8877
8878 status = sme_set_custom_mac_addr(mac_addr);
8879
8880 if (!QDF_IS_STATUS_SUCCESS(status))
8881 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008882
Komal Seelam92fff912016-03-24 11:51:41 +05308883 if (no_of_mac_addr < max_mac_addr)
8884 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8885 no_of_mac_addr);
8886 return 0;
8887}
8888
8889/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008890 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8891 * @hdd_ctx: HDD Context
8892 *
8893 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8894 * will generate its own MAC and update it to FW.
8895 *
8896 * Return: 0 for success
8897 * Non-zero error code for failure
8898 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008899static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008900{
8901 tSirMacAddr customMacAddr;
8902 QDF_STATUS status;
8903
8904 qdf_mem_copy(&customMacAddr,
8905 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8906 sizeof(tSirMacAddr));
8907 status = sme_set_custom_mac_addr(customMacAddr);
8908 if (!QDF_IS_STATUS_SUCCESS(status))
8909 return -EAGAIN;
8910 return 0;
8911}
8912
8913/**
Komal Seelam92fff912016-03-24 11:51:41 +05308914 * hdd_initialize_mac_address() - API to get wlan mac addresses
8915 * @hdd_ctx: HDD Context
8916 *
8917 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8918 * is provisioned with mac addresses, driver uses it, else it will use
8919 * wlan_mac.bin to update HW MAC addresses.
8920 *
8921 * Return: None
8922 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008923static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308924{
8925 QDF_STATUS status;
8926 int ret;
8927
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008928 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308929 if (ret == 0)
8930 return;
8931
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008932 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8933 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308934
8935 status = hdd_update_mac_config(hdd_ctx);
8936
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008937 if (QDF_IS_STATUS_SUCCESS(status))
8938 return;
8939
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008940 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8941 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008942
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008943 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008944 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008945 if (ret != 0) {
8946 hdd_err("MAC address out-of-sync, ret:%d", ret);
8947 QDF_ASSERT(ret);
8948 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008949 }
Komal Seelam92fff912016-03-24 11:51:41 +05308950}
8951
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008952static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008953{
8954 int vdev_id = 0;
8955 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8956 int value = hdd_ctx->config->smart_chainmask_enabled;
8957 int vpdev = PDEV_CMD;
8958 int ret;
8959
Naveen Rawat247a8682017-06-05 15:00:31 -07008960 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008961 if (ret)
8962 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8963
8964 return ret;
8965}
8966
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008967static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008968{
8969 int vdev_id = 0;
8970 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8971 int value = hdd_ctx->config->alternative_chainmask_enabled;
8972 int vpdev = PDEV_CMD;
8973 int ret;
8974
Naveen Rawat247a8682017-06-05 15:00:31 -07008975 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008976 if (ret)
8977 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8978 ret);
8979
8980 return ret;
8981}
8982
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008983static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008984{
8985 int vdev_id = 0;
8986 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8987 int value = hdd_ctx->config->ani_enabled;
8988 int vpdev = PDEV_CMD;
8989 int ret;
8990
Naveen Rawat247a8682017-06-05 15:00:31 -07008991 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008992 if (ret)
8993 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8994
8995 return ret;
8996}
8997
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008998/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008999 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9000 * @hdd_ctx: HDD context
9001 *
9002 * Pre configurations to be done at lower layer before calling cds enable.
9003 *
9004 * Return: 0 on success and errno on failure.
9005 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009006static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009007{
9008 int ret;
9009 QDF_STATUS status;
9010 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009011 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009012
Leo Changfdb45c32016-10-28 11:09:23 -07009013 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009014 /*
9015 * Set 802.11p config
9016 * TODO-OCB: This has been temporarily added here to ensure this
9017 * parameter is set in CSR when we init the channel list. This should
9018 * be removed once the 5.9 GHz channels are added to the regulatory
9019 * domain.
9020 */
9021 hdd_set_dot11p_config(hdd_ctx);
9022
9023 /*
9024 * Note that the cds_pre_enable() sequence triggers the cfg download.
9025 * The cfg download must occur before we update the SME config
9026 * since the SME config operation must access the cfg database
9027 */
9028 status = hdd_set_sme_config(hdd_ctx);
9029
9030 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009031 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009032 ret = qdf_status_to_os_return(status);
9033 goto out;
9034 }
9035
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009036 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9037 if (QDF_STATUS_SUCCESS != status) {
9038 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9039 ret = qdf_status_to_os_return(status);
9040 goto out;
9041 }
9042
Naveen Rawat247a8682017-06-05 15:00:31 -07009043 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009044 hdd_ctx->config->tx_chain_mask_1ss,
9045 PDEV_CMD);
9046 if (0 != ret) {
9047 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9048 goto out;
9049 }
9050
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009051 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9052 if (ret)
9053 goto out;
9054
9055 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9056 if (ret)
9057 goto out;
9058
Jeff Johnson12a744b2017-04-04 08:19:37 -07009059 ret = hdd_set_ani_enabled(hdd_ctx);
9060 if (ret)
9061 goto out;
9062
Naveen Rawat247a8682017-06-05 15:00:31 -07009063 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009064 hdd_ctx->config->arp_ac_category,
9065 PDEV_CMD);
9066 if (0 != ret) {
9067 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9068 hdd_ctx->config->arp_ac_category, ret);
9069 goto out;
9070 }
9071
9072
Prashanth Bhatta07998752016-04-28 12:35:33 -07009073 status = hdd_set_sme_chan_list(hdd_ctx);
9074 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009075 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009076 ret = qdf_status_to_os_return(status);
9077 goto out;
9078 }
9079
9080 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009081 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009082 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009083 ret = -EINVAL;
9084 goto out;
9085 }
9086
Prashanth Bhatta07998752016-04-28 12:35:33 -07009087 /*
9088 * Set the MAC Address Currently this is used by HAL to add self sta.
9089 * Remove this once self sta is added as part of session open.
9090 */
9091 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9092 hdd_ctx->config->intfMacAddr[0].bytes,
9093 sizeof(hdd_ctx->config->intfMacAddr[0]));
9094
9095 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9096 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9097 hal_status, hal_status);
9098 ret = -EINVAL;
9099 goto out;
9100 }
9101
9102 hdd_init_channel_avoidance(hdd_ctx);
9103
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309104 /* update enable sap mandatory chan list */
9105 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9106 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009107out:
9108 return ret;
9109}
9110
9111/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009112 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9113 * @context_ptr - hdd context pointer
9114 * @event_ptr - event structure pointer
9115 *
9116 * This is the p2p listen offload stop event handler, it sends vendor
9117 * event back to supplicant to notify the stop reason.
9118 *
9119 * Return: None
9120 */
9121static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9122 void *event_ptr)
9123{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009124 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009125 struct sir_p2p_lo_event *evt = event_ptr;
9126 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009127 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009128
9129 ENTER();
9130
9131 if (hdd_ctx == NULL) {
9132 hdd_err("Invalid HDD context pointer");
9133 return;
9134 }
9135
Peng Xu5c682812017-08-06 07:39:13 -07009136 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9137 if (!adapter) {
9138 hdd_err("Cannot find adapter by vdev_id = %d",
9139 evt->vdev_id);
9140 return;
9141 }
9142
Peng Xu8fdaa492016-06-22 10:20:47 -07009143 vendor_event =
9144 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009145 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009146 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9147 GFP_KERNEL);
9148
9149 if (!vendor_event) {
9150 hdd_err("cfg80211_vendor_event_alloc failed");
9151 return;
9152 }
9153
9154 if (nla_put_u32(vendor_event,
9155 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9156 evt->reason_code)) {
9157 hdd_err("nla put failed");
9158 kfree_skb(vendor_event);
9159 return;
9160 }
9161
9162 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009163 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9164 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009165}
9166
9167/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309168 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9169 * @hdd_ctx: HDD context
9170 *
9171 * This function sends the adaptive dwell time config configuration to the
9172 * firmware via WMA
9173 *
9174 * Return: 0 - success, < 0 - failure
9175 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009176static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309177{
9178 QDF_STATUS status;
9179 struct adaptive_dwelltime_params dwelltime_params;
9180
9181 dwelltime_params.is_enabled =
9182 hdd_ctx->config->adaptive_dwell_mode_enabled;
9183 dwelltime_params.dwelltime_mode =
9184 hdd_ctx->config->global_adapt_dwelltime_mode;
9185 dwelltime_params.lpf_weight =
9186 hdd_ctx->config->adapt_dwell_lpf_weight;
9187 dwelltime_params.passive_mon_intval =
9188 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9189 dwelltime_params.wifi_act_threshold =
9190 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9191
9192 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9193 &dwelltime_params);
9194
9195 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9196 if (!QDF_IS_STATUS_SUCCESS(status)) {
9197 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9198 return -EAGAIN;
9199 }
9200 return 0;
9201}
9202
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009203int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309204{
9205 QDF_STATUS status;
9206 struct wmi_dbs_scan_sel_params dbs_scan_params;
9207 uint32_t i = 0;
9208 uint8_t count = 0, numentries = 0;
9209 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9210 * CDS_DBS_SCAN_CLIENTS_MAX];
9211
9212 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009213 if (hdd_ctx->config->dual_mac_feature_disable ==
9214 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309215 return -EINVAL;
9216
9217 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9218 dbs_scan_config, &numentries,
9219 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9220 * CDS_DBS_SCAN_CLIENTS_MAX));
9221
9222 hdd_info("numentries %hu", numentries);
9223 if (!numentries) {
9224 hdd_info("Donot send scan_selection_config");
9225 return 0;
9226 }
9227
9228 /* hdd_set_fw_log_params */
9229 dbs_scan_params.num_clients = 0;
9230 while (count < (numentries - 2)) {
9231 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9232 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9233 dbs_scan_params.num_non_dbs_scans[i] =
9234 dbs_scan_config[count + 2];
9235 dbs_scan_params.num_clients++;
9236 hdd_debug("module:%d NDS:%d NNDS:%d",
9237 dbs_scan_params.module_id[i],
9238 dbs_scan_params.num_dbs_scans[i],
9239 dbs_scan_params.num_non_dbs_scans[i]);
9240 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9241 i++;
9242 }
9243
9244 dbs_scan_params.pdev_id = 0;
9245
9246 hdd_debug("clients:%d pdev:%d",
9247 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9248
9249 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9250 &dbs_scan_params);
9251 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9252 if (!QDF_IS_STATUS_SUCCESS(status)) {
9253 hdd_err("Failed to send DBS Scan selection configuration!");
9254 return -EAGAIN;
9255 }
9256 return 0;
9257}
9258
Arun Khandavallid4349a92016-07-25 11:10:43 +05309259#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9260/**
9261 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9262 * @hdd_ctx: HDD context
9263 *
9264 * Set auto shutdown callback to get indications from firmware to indicate
9265 * userspace to shutdown WLAN after a configured amount of inactivity.
9266 *
9267 * Return: 0 on success and errno on failure.
9268 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009269static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309270{
9271 QDF_STATUS status;
9272
9273 if (!hdd_ctx->config->WlanAutoShutdown)
9274 return 0;
9275
9276 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9277 wlan_hdd_auto_shutdown_cb);
9278 if (status != QDF_STATUS_SUCCESS)
9279 hdd_err("Auto shutdown feature could not be enabled: %d",
9280 status);
9281
9282 return qdf_status_to_os_return(status);
9283}
9284#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009285static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309286{
9287 return 0;
9288}
9289#endif
9290
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009291static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009292{
9293 QDF_STATUS status = QDF_STATUS_SUCCESS;
9294
9295 switch (hdd_ctx->config->dual_mac_feature_disable) {
9296 case DISABLE_DBS_CXN_AND_SCAN:
9297 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9298 if (status != QDF_STATUS_SUCCESS)
9299 hdd_err("Failed to disable dual mac features");
9300 break;
9301 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9302 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9303 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9304 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9305 if (status != QDF_STATUS_SUCCESS)
9306 hdd_err("Failed to set dbs scan and fw mode config");
9307 break;
9308 default:
9309 break;
9310 }
9311
9312 return status;
9313}
9314
Arun Khandavallid4349a92016-07-25 11:10:43 +05309315/**
9316 * hdd_features_init() - Init features
9317 * @hdd_ctx: HDD context
9318 * @adapter: Primary adapter context
9319 *
9320 * Initialize features and their feature context after WLAN firmware is up.
9321 *
9322 * Return: 0 on success and errno on failure.
9323 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009324static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309325{
9326 tSirTxPowerLimit hddtxlimit;
9327 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309328 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309329 int ret;
9330
9331 ENTER();
9332
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009333 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309334 if (ret) {
9335 hdd_err("Failed to update country code: %d", ret);
9336 goto out;
9337 }
9338
9339 /* FW capabilities received, Set the Dot11 mode */
9340 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009341 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9342 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309343
Arun Khandavallid4349a92016-07-25 11:10:43 +05309344
9345 if (hdd_ctx->config->fIsImpsEnabled)
9346 hdd_set_idle_ps_config(hdd_ctx, true);
9347 else
9348 hdd_set_idle_ps_config(hdd_ctx, false);
9349
Poddar, Siddarth37033032017-10-11 15:47:40 +05309350 /* Send Enable/Disable data stall detection cmd to FW */
9351 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9352 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9353
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309354 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009355 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309356
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309357 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9358 hdd_warn("Error in setting Voltage Corner mode config to FW");
9359
Arun Khandavallid4349a92016-07-25 11:10:43 +05309360 if (hdd_lro_init(hdd_ctx))
9361 hdd_err("Unable to initialize LRO in fw");
9362
9363 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9364 hdd_err("Unable to send adaptive dwelltime setting to FW");
9365
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309366 if (hdd_dbs_scan_selection_init(hdd_ctx))
9367 hdd_err("Unable to send DBS scan selection setting to FW");
9368
Arun Khandavallid4349a92016-07-25 11:10:43 +05309369 ret = hdd_init_thermal_info(hdd_ctx);
9370 if (ret) {
9371 hdd_err("Error while initializing thermal information");
9372 goto deregister_frames;
9373 }
9374
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309375 if (cds_is_packet_log_enabled())
9376 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9377
Arun Khandavallid4349a92016-07-25 11:10:43 +05309378 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9379 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9380 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9381 if (!QDF_IS_STATUS_SUCCESS(status))
9382 hdd_err("Error setting txlimit in sme: %d", status);
9383
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009384 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309385
Arun Khandavallid4349a92016-07-25 11:10:43 +05309386 ret = hdd_register_cb(hdd_ctx);
9387 if (ret) {
9388 hdd_err("Failed to register HDD callbacks!");
9389 goto deregister_frames;
9390 }
9391
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009392 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9393 if (!QDF_IS_STATUS_SUCCESS(status)) {
9394 hdd_err("Failed to set dbs scan and fw mode cfg");
9395 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309396 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009397
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309398 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9399 status = sme_enable_disable_chanavoidind_event(
9400 hdd_ctx->hHal, 0);
9401 if (!QDF_IS_STATUS_SUCCESS(status)) {
9402 hdd_err("Failed to disable Chan Avoidance Indication");
9403 goto deregister_cb;
9404 }
9405 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309406
Manjeet Singha9cae432017-02-28 11:58:22 +05309407 if (hdd_ctx->config->enable_5g_band_pref) {
9408 band_pref_params.rssi_boost_threshold_5g =
9409 hdd_ctx->config->rssi_boost_threshold_5g;
9410 band_pref_params.rssi_boost_factor_5g =
9411 hdd_ctx->config->rssi_boost_factor_5g;
9412 band_pref_params.max_rssi_boost_5g =
9413 hdd_ctx->config->max_rssi_boost_5g;
9414 band_pref_params.rssi_penalize_threshold_5g =
9415 hdd_ctx->config->rssi_penalize_threshold_5g;
9416 band_pref_params.rssi_penalize_factor_5g =
9417 hdd_ctx->config->rssi_penalize_factor_5g;
9418 band_pref_params.max_rssi_penalize_5g =
9419 hdd_ctx->config->max_rssi_penalize_5g;
9420 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9421 }
9422
Arun Khandavallid4349a92016-07-25 11:10:43 +05309423 /* register P2P Listen Offload event callback */
9424 if (wma_is_p2p_lo_capable())
9425 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9426 wlan_hdd_p2p_lo_event_callback);
9427
9428 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9429
9430 if (ret)
9431 goto deregister_cb;
9432
9433 EXIT();
9434 return 0;
9435
9436deregister_cb:
9437 hdd_deregister_cb(hdd_ctx);
9438deregister_frames:
9439 wlan_hdd_cfg80211_deregister_frames(adapter);
9440out:
9441 return -EINVAL;
9442
9443}
9444
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009445/**
9446 * hdd_features_deinit() - Deinit features
9447 * @hdd_ctx: HDD context
9448 *
9449 * De-Initialize features and their feature context.
9450 *
9451 * Return: none.
9452 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009453static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009454{
9455 wlan_hdd_tsf_deinit(hdd_ctx);
9456}
9457
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309458/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009459 * hdd_register_bcn_cb() - register scan beacon callback
9460 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309461 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009462 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309463 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009464static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309465{
9466 QDF_STATUS status;
9467
9468 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9469 wlan_cfg80211_inform_bss_frame,
9470 SCAN_CB_TYPE_INFORM_BCN);
9471 if (!QDF_IS_STATUS_SUCCESS(status)) {
9472 hdd_err("failed with status code %08d [x%08x]",
9473 status, status);
9474 return status;
9475 }
9476
9477 return QDF_STATUS_SUCCESS;
9478}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309479
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309480/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309481 * hdd_configure_cds() - Configure cds modules
9482 * @hdd_ctx: HDD context
9483 * @adapter: Primary adapter context
9484 *
9485 * Enable Cds modules after WLAN firmware is up.
9486 *
9487 * Return: 0 on success and errno on failure.
9488 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009489int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309490{
9491 int ret;
9492 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309493 int set_value;
9494 uint32_t num_abg_tx_chains = 0;
9495 uint32_t num_11b_tx_chains = 0;
9496 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009497 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309498
9499 if (hdd_ctx->config->sifs_burst_duration) {
9500 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9501 hdd_ctx->config->sifs_burst_duration;
9502
9503 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9504 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9505 set_value, PDEV_CMD);
9506 }
9507
9508 if (hdd_ctx->config->is_force_1x1)
9509 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9510 1, PDEV_CMD);
9511 /* set chip power save failure detected callback */
9512 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9513 hdd_chip_pwr_save_fail_detected_cb);
9514
9515 if (hdd_ctx->config->max_mpdus_inampdu) {
9516 set_value = hdd_ctx->config->max_mpdus_inampdu;
9517 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9518 set_value, PDEV_CMD);
9519 }
9520
9521 if (hdd_ctx->config->enable_rts_sifsbursting) {
9522 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9523 sme_cli_set_command(0,
9524 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9525 set_value, PDEV_CMD);
9526 }
9527
9528 if (hdd_ctx->config->sap_get_peer_info) {
9529 set_value = hdd_ctx->config->sap_get_peer_info;
9530 sme_cli_set_command(0,
9531 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9532 set_value, PDEV_CMD);
9533 }
9534
9535 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9536 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9537 if (!hdd_ctx->config->enable2x2) {
9538 if (num_11b_tx_chains > 1)
9539 num_11b_tx_chains = 1;
9540 if (num_11ag_tx_chains > 1)
9541 num_11ag_tx_chains = 1;
9542 }
9543 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9544 num_11b_tx_chains);
9545 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9546 num_11ag_tx_chains);
9547 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9548 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309549
9550 ret = hdd_pre_enable_configure(hdd_ctx);
9551 if (ret) {
9552 hdd_err("Failed to pre-configure cds");
9553 goto out;
9554 }
9555
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009556 /* Always get latest IPA resources allocated from cds_open and configure
9557 * IPA module before configuring them to FW. Sequence required as crash
9558 * observed otherwise.
9559 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009560 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9561 hdd_err("Failed to setup pipes");
9562 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009563 }
9564
Arun Khandavallifae92942016-08-01 13:31:08 +05309565 /*
9566 * Start CDS which starts up the SME/MAC/HAL modules and everything
9567 * else
9568 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009569 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309570
9571 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009572 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309573 goto out;
9574 }
9575
9576 status = hdd_post_cds_enable_config(hdd_ctx);
9577 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009578 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009579 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309580 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309581 status = hdd_register_bcn_cb(hdd_ctx);
9582 if (!QDF_IS_STATUS_SUCCESS(status)) {
9583 hdd_alert("hdd_post_cds_enable_config failed");
9584 goto cds_disable;
9585 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309586
9587 ret = hdd_features_init(hdd_ctx, adapter);
9588 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009589 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309590
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009591 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009592 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009593 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9594 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009595 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009596 goto cds_disable;
9597 }
9598
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309599 if (hdd_enable_egap(hdd_ctx))
9600 hdd_debug("enhance green ap is not enabled");
9601
Nachiket Kukadedd302662017-07-13 17:31:44 +05309602 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9603 hdd_debug("Failed to set wow pulse");
9604
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309605 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9606 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9607
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309608
9609 if (hdd_ctx->config->enable_phy_reg_retention)
9610 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9611 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9612
Arun Khandavallifae92942016-08-01 13:31:08 +05309613 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009614
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009615cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009616 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009617
Arun Khandavallifae92942016-08-01 13:31:08 +05309618out:
9619 return -EINVAL;
9620}
9621
9622/**
9623 * hdd_deconfigure_cds() -De-Configure cds
9624 * @hdd_ctx: HDD context
9625 *
9626 * Deconfigure Cds modules before WLAN firmware is down.
9627 *
9628 * Return: 0 on success and errno on failure.
9629 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009630static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309631{
9632 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009633 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309634
9635 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009636
9637 /* De-init features */
9638 hdd_features_deinit(hdd_ctx);
9639
Arun Khandavallifae92942016-08-01 13:31:08 +05309640 /* De-register the SME callbacks */
9641 hdd_deregister_cb(hdd_ctx);
9642
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009643 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309644 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9645 hdd_err("Failed to Disable the CDS Modules! :%d",
9646 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009647 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309648 }
9649
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309650 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9651 hdd_err("Failed to disconnect pipes");
9652 ret = -EINVAL;
9653 }
9654
Arun Khandavallifae92942016-08-01 13:31:08 +05309655 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009656 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309657}
9658
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009659#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9660static void hdd_deregister_policy_manager_callback(
9661 struct wlan_objmgr_psoc *psoc)
9662{
9663 if (QDF_STATUS_SUCCESS !=
9664 policy_mgr_deregister_hdd_cb(psoc)) {
9665 hdd_err("HDD callback deregister with policy manager failed");
9666 }
9667}
9668#else
9669static void hdd_deregister_policy_manager_callback(
9670 struct wlan_objmgr_psoc *psoc)
9671{
9672}
9673#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309674
9675/**
9676 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9677 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009678 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309679 *
9680 * This function maintains the driver state machine it will be invoked from
9681 * exit, shutdown and con_mode change handler. Depending on the driver state
9682 * shall perform the stopping/closing of the modules.
9683 *
9684 * Return: 0 for success; non-zero for failure
9685 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009686int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309687{
9688 void *hif_ctx;
9689 qdf_device_t qdf_ctx;
9690 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309691 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009692 bool is_idle_stop = !cds_is_driver_unloading() &&
9693 !cds_is_driver_recovering();
9694 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309695
9696 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009697 hdd_alert("stop WLAN module: entering driver status=%d",
9698 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309699
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009700 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9701
Arun Khandavallifae92942016-08-01 13:31:08 +05309702 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9703 if (!qdf_ctx) {
9704 hdd_err("QDF device context NULL");
9705 return -EINVAL;
9706 }
9707
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309708 mutex_lock(&hdd_ctx->iface_change_lock);
9709 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009710 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +05309711
Dustin Brown70111822017-03-30 15:31:40 -07009712 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -07009713 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009714 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -07009715 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -07009716
9717 cds_print_external_threads();
9718
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009719 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009720 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -07009721 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
9722 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309723 hdd_prevent_suspend_timeout(
9724 hdd_ctx->config->iface_change_wait_time,
9725 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009726 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009727 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -07009728 return 0;
9729 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009730 }
9731
Arun Khandavallifae92942016-08-01 13:31:08 +05309732 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9733
Kabilan Kannan6edafeb2017-11-16 16:34:34 -08009734 /* free user wowl patterns */
9735 hdd_free_user_wowl_ptrns();
9736
Arun Khandavallifae92942016-08-01 13:31:08 +05309737 switch (hdd_ctx->driver_status) {
9738 case DRIVER_MODULES_UNINITIALIZED:
9739 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309740 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309741 case DRIVER_MODULES_CLOSED:
9742 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309743 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309744 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309745 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309746 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009747 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309748 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309749 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309750 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009751 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309752 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9753 break;
9754 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009755 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309756 break;
9757 default:
9758 hdd_err("Trying to stop wlan in a wrong state: %d",
9759 hdd_ctx->driver_status);
9760 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309761 ret = -EINVAL;
9762 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309763 }
9764
Rajeev Kumarbe021242017-02-16 16:12:23 -08009765 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309766 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9767 hdd_err("Failed to process post CDS disable Modules! :%d",
9768 qdf_status);
9769 ret = -EINVAL;
9770 QDF_ASSERT(0);
9771 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07009772
9773 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
9774 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9775 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
9776 ret = -EINVAL;
9777 QDF_ASSERT(0);
9778 }
9779
Dustin Brown0707ddf2017-09-20 15:31:56 -07009780 /*
9781 * Close the scheduler before calling cds_close to make sure
9782 * no thread is scheduled after the each module close is
9783 * is called i.e after all the data structures are freed.
9784 */
9785 qdf_status = cds_sched_close();
9786 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
9787 if (QDF_IS_STATUS_ERROR(qdf_status))
9788 hdd_alert("Failed to close CDS Scheduler");
9789
Jeff Johnsone4b14592017-09-13 14:23:33 -07009790 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309791 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009792 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309793 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309794 QDF_ASSERT(0);
9795 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009796
Arun Khandavallifae92942016-08-01 13:31:08 +05309797 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9798 if (!hif_ctx) {
9799 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309800 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309801 }
9802
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309803 hdd_runtime_suspend_context_deinit(hdd_ctx);
9804
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309805 if (hdd_ctx->target_hw_name) {
9806 qdf_mem_free(hdd_ctx->target_hw_name);
9807 hdd_ctx->target_hw_name = NULL;
9808 }
9809
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309810 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309811
9812 ol_cds_free();
9813
Dustin Brown70111822017-03-30 15:31:40 -07009814 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309815 ret = pld_power_off(qdf_ctx->dev);
9816 if (ret)
9817 hdd_err("CNSS power down failed put device into Low power mode:%d",
9818 ret);
9819 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309820
9821 /* Once the firmware sequence is completed reset this flag */
9822 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309823 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009824 /*
9825 * Reset total mac phy during module stop such that during
9826 * next module start same psoc is used to populate new service
9827 * ready data
9828 */
9829 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309830
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309831done:
9832 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009833 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309834 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07009835 hdd_alert("stop WLAN module: exit driver status=%d",
9836 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309837 EXIT();
9838
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309839 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309840
9841}
9842
Arun Khandavallifae92942016-08-01 13:31:08 +05309843
9844/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309845 * hdd_state_info_dump() - prints state information of hdd layer
9846 * @buf: buffer pointer
9847 * @size: size of buffer to be filled
9848 *
9849 * This function is used to dump state information of hdd layer
9850 *
9851 * Return: None
9852 */
9853static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9854{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009855 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309856 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9857 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009858 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009859 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309860 uint16_t len = 0;
9861 char *buf = *buf_ptr;
9862
9863 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9864 if (!hdd_ctx) {
9865 hdd_err("Failed to get hdd context ");
9866 return;
9867 }
9868
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009869 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309870
9871 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -07009872 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309873 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009874 "\n is_scheduler_suspended %d",
9875 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309876
9877 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9878
9879 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009880 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309881 if (adapter->dev)
9882 len += scnprintf(buf + len, *size - len,
9883 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009884 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309885 "\n device_mode: %d", adapter->device_mode);
9886 switch (adapter->device_mode) {
9887 case QDF_STA_MODE:
9888 case QDF_P2P_CLIENT_MODE:
9889 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9890 len += scnprintf(buf + len, *size - len,
9891 "\n connState: %d",
9892 hdd_sta_ctx->conn_info.connState);
9893 break;
9894
9895 default:
9896 break;
9897 }
9898 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9899 adapter_node = next;
9900 }
9901
9902 *size -= len;
9903 *buf_ptr += len;
9904}
9905
9906/**
9907 * hdd_register_debug_callback() - registration function for hdd layer
9908 * to print hdd state information
9909 *
9910 * Return: None
9911 */
9912static void hdd_register_debug_callback(void)
9913{
9914 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9915}
9916
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309917/*
9918 * wlan_init_bug_report_lock() - Initialize bug report lock
9919 *
9920 * This function is used to create bug report lock
9921 *
9922 * Return: None
9923 */
9924static void wlan_init_bug_report_lock(void)
9925{
9926 p_cds_contextType p_cds_context;
9927
9928 p_cds_context = cds_get_global_context();
9929 if (!p_cds_context) {
9930 hdd_err("cds context is NULL");
9931 return;
9932 }
9933
9934 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9935}
9936
Mohit Khannaf8f96822017-05-17 17:11:59 -07009937void hdd_dp_trace_init(struct hdd_config *config)
9938{
9939
9940 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9941 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9942 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9943 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9944 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9945 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9946 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +08009947 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -07009948
9949 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9950 &num_entries, sizeof(config_params));
9951
9952 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +08009953 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +08009954 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +08009955 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +08009956 else if (bw_compute_interval > 1000) {
9957 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
9958 thresh_time_limit = 1;
9959 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -07009960 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9961
9962 switch (num_entries) {
9963 case 4:
9964 proto_bitmap = config_params[3];
9965 case 3:
9966 verbosity = config_params[2];
9967 case 2:
9968 thresh = config_params[1];
9969 case 1:
9970 live_mode = config_params[0];
9971 default:
9972 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9973 live_mode, thresh, thresh_time_limit,
9974 verbosity, proto_bitmap);
9975 };
9976
9977 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9978 verbosity, proto_bitmap);
9979
9980}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309981/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009982 * hdd_wlan_startup() - HDD init function
9983 * @dev: Pointer to the underlying device
9984 *
9985 * This is the driver startup code executed once a WLAN device has been detected
9986 *
9987 * Return: 0 for success, < 0 for failure
9988 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309989int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009990{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309991 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009992 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009993 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009994 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009995
9996 ENTER();
9997
Arun Khandavallifae92942016-08-01 13:31:08 +05309998 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009999
10000 if (IS_ERR(hdd_ctx))
10001 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010002
Abhishek Singhe9068f12017-03-31 14:14:52 +053010003 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10004 DEFAULT_PSOC_ID);
10005 if (ret) {
10006 hdd_err("Psoc creation fails!");
10007 QDF_BUG(0);
10008 goto err_hdd_free_context;
10009 }
10010
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010011 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010012#ifdef FEATURE_WLAN_CH_AVOID
10013 mutex_init(&hdd_ctx->avoid_freq_lock);
10014#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010015
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010016 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -070010017 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010018
Jeff Johnson957bc272017-02-02 08:54:48 -080010019 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010020 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010021 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -070010022 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010023 }
10024
Yingying Tang80e15f32016-09-27 18:23:01 +080010025 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010026
Anurag Chouhan6d760662016-02-20 16:05:43 +053010027 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010028
10029 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010030 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010031 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010032 }
10033
Prashanth Bhatta07998752016-04-28 12:35:33 -070010034 ret = hdd_wiphy_init(hdd_ctx);
10035 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010036 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010037 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010038 }
10039
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010040 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010041 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010042
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010043 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010044 goto err_wiphy_unregister;
10045
Kapil Gupta4f0c0c12017-02-07 15:21:15 +053010046 wlan_hdd_init_chan_info(hdd_ctx);
10047
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010048 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010049
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010050 ret = hdd_register_notifiers(hdd_ctx);
10051 if (ret)
10052 goto err_ipa_cleanup;
10053
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010054 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010055
Jeff Johnson957bc272017-02-02 08:54:48 -080010056 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10057 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010058 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010059 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010060 }
10061
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010062 hdd_release_rtnl_lock();
10063 rtnl_held = false;
10064
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010065 wlan_hdd_update_11n_mode(hdd_ctx->config);
10066
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010067#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010068 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010069 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010070 hdd_skip_acs_scan_timer_handler,
10071 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010072 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010073 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010074 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010075#endif
10076
Prashanth Bhattaab004382016-10-11 16:08:11 -070010077 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010078
Jeff Johnson9afc5012016-09-23 13:56:27 -070010079 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010080
Nirav Shahbd36b062016-07-18 11:12:59 +053010081 if (hdd_ctx->rps)
10082 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010083
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +053010084 status = wlansap_global_init();
10085 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -080010086 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010087
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010088 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010089 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010090
Arun Khandavallifae92942016-08-01 13:31:08 +053010091 if (hdd_ctx->config->fIsImpsEnabled)
10092 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010093 else
10094 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010095
Mukul Sharma07bd8752017-10-10 16:58:14 +053010096 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010097 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10098 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010099 hdd_prevent_suspend_timeout(
10100 hdd_ctx->config->iface_change_wait_time,
10101 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10102 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010103
Sachin Ahujadddd2632017-03-07 19:07:24 +053010104 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010105 goto success;
10106
Jeff Johnson957bc272017-02-02 08:54:48 -080010107err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010108 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010109
Jeff Johnson46bde382017-02-01 15:31:16 -080010110err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010111 if (rtnl_held)
10112 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010113
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010114 unregister_netdevice_notifier(&hdd_netdev_notifier);
10115
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010116err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010117 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010118
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010119err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010120 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010121
Arun Khandavallifae92942016-08-01 13:31:08 +053010122err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010123 hdd_wlan_stop_modules(hdd_ctx, false);
Dustin Brown792513d2017-11-07 11:07:09 -080010124 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010125
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -070010126err_hdd_free_psoc:
Houston Hoffman47a4a052016-11-14 23:22:44 -080010127 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010128 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010129 hdd_exit_netlink_services(hdd_ctx);
10130
Dustin Brown20912462017-06-07 13:48:25 -070010131 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10132
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010133err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010134 if (cds_is_fw_down())
10135 hdd_err("Not setting the complete event as fw is down");
10136 else
10137 hdd_start_complete(ret);
10138
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010139 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010140 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010141 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010142
10143success:
10144 EXIT();
10145 return 0;
10146}
10147
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010148/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010149 * hdd_wlan_update_target_info() - update target type info
10150 * @hdd_ctx: HDD context
10151 * @context: hif context
10152 *
10153 * Update target info received from firmware in hdd context
10154 * Return:None
10155 */
10156
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010157void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010158{
10159 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10160
10161 if (!tgt_info) {
10162 hdd_err("Target info is Null");
10163 return;
10164 }
10165
10166 hdd_ctx->target_type = tgt_info->target_type;
10167}
10168
10169/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010170 * hdd_get_nud_stats_cb() - callback api to update the stats
10171 * received from the firmware
10172 * @data: pointer to adapter.
10173 * @rsp: pointer to data received from FW.
10174 *
10175 * This is called when wlan driver received response event for
10176 * get arp stats to firmware.
10177 *
10178 * Return: None
10179 */
10180static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10181{
10182 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10183 struct hdd_nud_stats_context *context;
10184 int status;
10185 struct hdd_adapter *adapter = NULL;
10186
10187 ENTER();
10188
10189 if (!rsp) {
10190 hdd_err("data is null");
10191 return;
10192 }
10193
10194 status = wlan_hdd_validate_context(hdd_ctx);
10195 if (0 != status)
10196 return;
10197
10198 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10199 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10200 hdd_err("Invalid adapter or adapter has invalid magic");
10201 return;
10202 }
10203
10204 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10205 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10206 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10207 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10208 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10209 rsp->out_of_order_arp_rsp_drop_cnt);
10210 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10211 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10212 hdd_notice("rsp->ba_session_establishment_status :%x",
10213 rsp->ba_session_establishment_status);
10214
10215 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10216 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10217 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10218 adapter->dad |= rsp->dad_detected;
10219 adapter->con_status = rsp->connect_status;
10220
10221 spin_lock(&hdd_context_lock);
10222 context = &hdd_ctx->nud_stats_context;
10223 complete(&context->response_event);
10224 spin_unlock(&hdd_context_lock);
10225
10226 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010227}
10228
10229/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010230 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010231 * @hdd_ctx: HDD context
10232 *
10233 * Register the HDD callbacks to CDS/SME.
10234 *
10235 * Return: 0 for success or Error code for failure
10236 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010237int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010238{
10239 QDF_STATUS status;
10240 int ret = 0;
10241
10242 ENTER();
10243
10244 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10245
10246 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10247 hdd_send_oem_data_rsp_msg);
10248
10249 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10250 wlan_hdd_cfg80211_fw_mem_dump_cb);
10251 if (!QDF_IS_STATUS_SUCCESS(status)) {
10252 hdd_err("Failed to register memdump callback");
10253 ret = -EINVAL;
10254 return ret;
10255 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010256 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10257 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010258 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10259 sme_nan_register_callback(hdd_ctx->hHal,
10260 wlan_hdd_cfg80211_nan_callback);
10261 sme_stats_ext_register_callback(hdd_ctx->hHal,
10262 wlan_hdd_cfg80211_stats_ext_callback);
10263
10264 sme_ext_scan_register_callback(hdd_ctx->hHal,
10265 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010266 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10267 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010268
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010269 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10270 hdd_rssi_threshold_breached);
10271
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010272 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10273
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010274 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10275 wlan_hdd_cfg80211_link_layer_stats_callback);
10276
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010277 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10278
Zhang Qianca38fb12016-12-23 11:10:48 +080010279 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10280 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10281
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010282 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10283 hdd_lost_link_info_cb);
10284 /* print error and not block the startup process */
10285 if (!QDF_IS_STATUS_SUCCESS(status))
10286 hdd_err("set lost link info callback failed");
10287
Poddar, Siddarth34872782017-08-10 14:08:51 +053010288 ret = hdd_register_data_stall_detect_cb();
10289 if (ret) {
10290 hdd_err("Register data stall detect detect callback failed.");
10291 return ret;
10292 }
10293
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010294 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10295
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010296 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010297 hdd_set_connection_in_progress,
10298 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010299
10300 status = sme_congestion_register_callback(hdd_ctx->hHal,
10301 hdd_update_cca_info_cb);
10302 if (!QDF_IS_STATUS_SUCCESS(status))
10303 hdd_err("set congestion callback failed");
10304
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010305 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10306 hdd_bt_activity_cb);
10307 if (!QDF_IS_STATUS_SUCCESS(status))
10308 hdd_err("set bt activity info callback failed");
10309
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010310 EXIT();
10311
10312 return ret;
10313}
10314
10315/**
10316 * hdd_deregister_cb() - De-Register HDD callbacks.
10317 * @hdd_ctx: HDD context
10318 *
10319 * De-Register the HDD callbacks to CDS/SME.
10320 *
10321 * Return: void
10322 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010323void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010324{
10325 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010326 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010327
10328 ENTER();
10329
10330 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10331 if (!QDF_IS_STATUS_SUCCESS(status))
10332 hdd_err("De-register of dcc stats callback failed: %d",
10333 status);
10334
10335 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010336 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10337
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010338 sme_stats_ext_register_callback(hdd_ctx->hHal,
10339 wlan_hdd_cfg80211_stats_ext_callback);
10340
10341 sme_nan_deregister_callback(hdd_ctx->hHal);
10342 status = sme_reset_tsfcb(hdd_ctx->hHal);
10343 if (!QDF_IS_STATUS_SUCCESS(status))
10344 hdd_err("Failed to de-register tsfcb the callback:%d",
10345 status);
10346 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10347 if (!QDF_IS_STATUS_SUCCESS(status))
10348 hdd_err("Failed to de-register the fw mem dump callback: %d",
10349 status);
10350
Poddar, Siddarth34872782017-08-10 14:08:51 +053010351 ret = hdd_deregister_data_stall_detect_cb();
10352 if (ret)
10353 hdd_err("Failed to de-register data stall detect event callback");
10354
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010355 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10356 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10357
10358 EXIT();
10359}
10360
10361/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010362 * hdd_softap_sta_deauth() - handle deauth req from HDD
10363 * @adapter: Pointer to the HDD
10364 * @enable: bool value
10365 *
10366 * This to take counter measure to handle deauth req from HDD
10367 *
10368 * Return: None
10369 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010370QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010371 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010372{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010373 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010374
10375 ENTER();
10376
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010377 /* Ignore request to deauth bcmc station */
10378 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010379 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010380
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010381 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010382 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10383 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010384
10385 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010386 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010387}
10388
10389/**
10390 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10391 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010392 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010393 *
10394 * This to take counter measure to handle deauth req from HDD
10395 *
10396 * Return: None
10397 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010398void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010399 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010400{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010401 ENTER();
10402
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010403 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010404 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010405 return;
10406
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010407 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010408 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010409}
10410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010411/**
10412 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10413 * @hdd_ctx: HDD Context
10414 *
10415 * API to find if there is any STA or P2P-Client is connected
10416 *
10417 * Return: true if connected; false otherwise
10418 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010419QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010420{
10421 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10422}
10423
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010424/**
10425 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10426 * @adapter: HDD adapter pointer
10427 *
10428 * This function loop through each adapter and disable roaming on each STA
10429 * device mode except the input adapter.
10430 *
10431 * Note: On the input adapter roaming is not enabled yet hence no need to
10432 * disable.
10433 *
10434 * Return: None
10435 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010436void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010437{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010438 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010439 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010440 hdd_adapter_list_node_t *adapterNode = NULL;
10441 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010442 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010443
10444 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010445 hdd_ctx->config->isRoamOffloadScanEnabled &&
10446 QDF_STA_MODE == adapter->device_mode &&
10447 policy_mgr_is_sta_active_connection_exists(
10448 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010449 hdd_debug("Connect received on STA session Id(%d)",
10450 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010451 /*
10452 * Loop through adapter and disable roaming for each STA device
10453 * mode except the input adapter.
10454 */
10455 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10456
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010457 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010458 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010459
Jeff Johnson1b780e42017-10-31 14:11:45 -070010460 if (QDF_STA_MODE == adapterIdx->device_mode &&
10461 adapter->session_id != adapterIdx->session_id) {
10462 hdd_debug("Disable Roaming on session Id(%d)",
10463 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010464 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10465 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010466 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010467 }
10468
10469 status = hdd_get_next_adapter(hdd_ctx,
10470 adapterNode,
10471 &pNext);
10472 adapterNode = pNext;
10473 }
10474 }
10475}
10476
10477/**
10478 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10479 * @adapter: HDD adapter pointer
10480 *
10481 * This function loop through each adapter and enable roaming on each STA
10482 * device mode except the input adapter.
10483 * Note: On the input adapter no need to enable roaming because link got
10484 * disconnected on this.
10485 *
10486 * Return: None
10487 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010488void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010489{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010490 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010491 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010492 hdd_adapter_list_node_t *adapterNode = NULL;
10493 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010494 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010495
10496 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010497 hdd_ctx->config->isRoamOffloadScanEnabled &&
10498 QDF_STA_MODE == adapter->device_mode &&
10499 policy_mgr_is_sta_active_connection_exists(
10500 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010501 hdd_debug("Disconnect received on STA session Id(%d)",
10502 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010503 /*
10504 * Loop through adapter and enable roaming for each STA device
10505 * mode except the input adapter.
10506 */
10507 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10508
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010509 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010510 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010511
Jeff Johnson1b780e42017-10-31 14:11:45 -070010512 if (QDF_STA_MODE == adapterIdx->device_mode &&
10513 adapter->session_id != adapterIdx->session_id) {
10514 hdd_debug("Enabling Roaming on session Id(%d)",
10515 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010516 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10517 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010518 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010519 REASON_CONNECT);
10520 }
10521
10522 status = hdd_get_next_adapter(hdd_ctx,
10523 adapterNode,
10524 &pNext);
10525 adapterNode = pNext;
10526 }
10527 }
10528}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010529
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010530/**
10531 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10532 * @skb: sk buffer pointer
10533 *
10534 * Sends the bcast message to SVC multicast group with generic nl socket
10535 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10536 *
10537 * Return: None
10538 */
10539static void nl_srv_bcast_svc(struct sk_buff *skb)
10540{
10541#ifdef CNSS_GENL
10542 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10543#else
10544 nl_srv_bcast(skb);
10545#endif
10546}
10547
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010548void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010549{
10550 struct sk_buff *skb;
10551 struct nlmsghdr *nlh;
10552 tAniMsgHdr *ani_hdr;
10553 void *nl_data = NULL;
10554 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010555 struct radio_index_tlv *radio_info;
10556 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010557
10558 if (in_interrupt() || irqs_disabled() || in_atomic())
10559 flags = GFP_ATOMIC;
10560
10561 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10562
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010563 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010564 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010565
10566 nlh = (struct nlmsghdr *)skb->data;
10567 nlh->nlmsg_pid = 0; /* from kernel */
10568 nlh->nlmsg_flags = 0;
10569 nlh->nlmsg_seq = 0;
10570 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10571
10572 ani_hdr = NLMSG_DATA(nlh);
10573 ani_hdr->type = type;
10574
10575 switch (type) {
10576 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010577 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010578 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010579 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010580 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010581 ani_hdr->length = 0;
10582 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010583 break;
10584 case WLAN_SVC_WLAN_STATUS_IND:
10585 case WLAN_SVC_WLAN_VERSION_IND:
10586 case WLAN_SVC_DFS_CAC_START_IND:
10587 case WLAN_SVC_DFS_CAC_END_IND:
10588 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10589 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10590 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010591 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010592 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010593 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010594 ani_hdr->length = len;
10595 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10596 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10597 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010598 break;
10599
10600 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010601 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010602 type);
10603 kfree_skb(skb);
10604 return;
10605 }
10606
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010607 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010608 * Add radio index at the end of the svc event in TLV format
10609 * to maintain the backward compatibility with userspace
10610 * applications.
10611 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010612
10613 tlv_len = 0;
10614
10615 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10616 < WLAN_NL_MAX_PAYLOAD) {
10617 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10618 sizeof(*ani_hdr) + len);
10619 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10620 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10621 radio_info->radio = radio;
10622 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010623 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010624 "Added radio index tlv - radio index %d",
10625 radio_info->radio);
10626 }
10627
10628 nlh->nlmsg_len += tlv_len;
10629 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10630
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010631 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010632}
10633
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010634#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10635void wlan_hdd_auto_shutdown_cb(void)
10636{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010637 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010638
10639 if (!hdd_ctx)
10640 return;
10641
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010642 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010643 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10644 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010645}
10646
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010647void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010648{
10649 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010650 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010651 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010652 bool ap_connected = false, sta_connected = false;
10653 tHalHandle hal_handle;
10654
10655 hal_handle = hdd_ctx->hHal;
10656 if (hal_handle == NULL)
10657 return;
10658
10659 if (hdd_ctx->config->WlanAutoShutdown == 0)
10660 return;
10661
10662 if (enable == false) {
10663 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010664 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010665 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010666 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010667 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010668 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010669 return;
10670 }
10671
10672 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010673 if (policy_mgr_concurrent_open_sessions_running(
10674 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010675 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10676
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010677 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010678 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010679 if (adapter
10680 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010681 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010682 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10683 conn_info.connState ==
10684 eConnectionState_Associated) {
10685 sta_connected = true;
10686 break;
10687 }
10688 }
10689 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010690 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010691 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070010692 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010693 ap_connected = true;
10694 break;
10695 }
10696 }
10697 status = hdd_get_next_adapter(hdd_ctx,
10698 adapterNode,
10699 &pNext);
10700 adapterNode = pNext;
10701 }
10702 }
10703
10704 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010705 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010706 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010707 }
Jeff Johnson68755312017-02-10 11:46:55 -080010708
10709 if (sme_set_auto_shutdown_timer(hal_handle,
10710 hdd_ctx->config->WlanAutoShutdown)
10711 != QDF_STATUS_SUCCESS)
10712 hdd_err("Failed to start wlan auto shutdown timer");
10713 else
10714 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10715 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010716}
10717#endif
10718
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010719struct hdd_adapter *
10720hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10721 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010722{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010723 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010724 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010725 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010726 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10727
10728 con_sap_adapter = NULL;
10729
10730 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010731 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010732 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010733 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10734 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010735 adapter != this_sap_adapter) {
10736 if (check_start_bss) {
10737 if (test_bit(SOFTAP_BSS_STARTED,
10738 &adapter->event_flags)) {
10739 con_sap_adapter = adapter;
10740 break;
10741 }
10742 } else {
10743 con_sap_adapter = adapter;
10744 break;
10745 }
10746 }
10747 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10748 adapterNode = pNext;
10749 }
10750
10751 return con_sap_adapter;
10752}
10753
10754#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010755static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010756{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010757 return adapter->device_mode == QDF_STA_MODE ||
10758 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010759}
10760
Jeff Johnson9d295242017-08-29 14:39:48 -070010761static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010762{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010763 return adapter->device_mode == QDF_SAP_MODE ||
10764 adapter->device_mode == QDF_P2P_GO_MODE;
10765}
10766
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010767static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010768{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010769 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010770 hdd_adapter_list_node_t *node;
10771
10772 status = hdd_get_front_adapter(hdd_ctx, &node);
10773 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010774 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010775
10776 if (adapter &&
10777 hdd_adapter_is_sta(adapter) &&
10778 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10779 conn_info.connState == eConnectionState_Associated) {
10780 return true;
10781 }
10782
10783 if (adapter &&
10784 hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070010785 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070010786 return true;
10787 }
10788
10789 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10790 }
10791
10792 return false;
10793}
10794
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010795static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010796{
10797 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010798
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010799 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010800 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010801 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010802
Dustin Brown5ec6b552017-03-31 12:11:40 -070010803 return is_running;
10804}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010805
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010806static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010807{
10808 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10809 hdd_ctx->bus_bw_timer_running = true;
10810 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10811 hdd_ctx->config->busBandwidthComputeInterval);
10812 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10813}
10814
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010815void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010816{
10817 ENTER();
10818
10819 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10820 hdd_debug("Bandwidth compute timer already started");
10821 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010822 }
10823
Dustin Brown5ec6b552017-03-31 12:11:40 -070010824 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10825
10826 EXIT();
10827}
10828
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010829void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010830{
10831 ENTER();
10832
10833 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10834 hdd_debug("Bandwidth compute timer already started");
10835 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010836 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010837
10838 if (hdd_any_adapter_is_assoc(hdd_ctx))
10839 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10840
10841 EXIT();
10842}
10843
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010844static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010845{
10846 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10847
10848 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10849 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10850 hdd_ctx->bus_bw_timer_running = false;
10851 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10852
10853 hdd_reset_tcp_delack(hdd_ctx);
10854}
10855
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010856void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010857{
10858 ENTER();
10859
10860 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10861 hdd_debug("Bandwidth compute timer already stopped");
10862 return;
10863 }
10864
10865 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10866
10867 EXIT();
10868}
10869
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010870void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010871{
10872 ENTER();
10873
10874 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10875 hdd_debug("Bandwidth compute timer already stopped");
10876 return;
10877 }
10878
10879 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10880 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10881
10882 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010883}
10884#endif
10885
10886/**
10887 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10888 * and sta's operating channel.
10889 * @sta_adapter: Describe the first argument to foobar.
10890 * @ap_adapter: Describe the second argument to foobar.
10891 * @roam_profile: Roam profile of AP to which STA wants to connect.
10892 * @concurrent_chnl_same: If both SAP and STA channels are same then
10893 * set this flag to true else false.
10894 *
10895 * This function checks the sap's operating channel and sta's operating channel.
10896 * if both are same then it will return false else it will restart the sap in
10897 * sta's channel and return true.
10898 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010899 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010900 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010901QDF_STATUS
10902wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10903 struct hdd_adapter *ap_adapter,
10904 tCsrRoamProfile *roam_profile,
10905 tScanResultHandle *scan_cache,
10906 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010907{
Jeff Johnson87251032017-08-29 13:31:11 -070010908 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010909 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010910 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080010911 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010912 *concurrent_chnl_same = true;
10913
10914 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10915 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010916 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010917 scan_cache,
10918 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010919 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010920 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010921 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070010922 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010923 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010924 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010925 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010926 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010927 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070010928 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010929 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010930 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010931 }
10932 }
10933 } else {
10934 /*
10935 * Lets handle worst case scenario here, Scan cache lookup is
10936 * failed so we have to stop the SAP to avoid any channel
10937 * discrepancy between SAP's channel and STA's channel.
10938 * Return the status as failure so caller function could know
10939 * that scan look up is failed.
10940 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010941 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010942 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010943 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010944 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010945}
10946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010947/**
10948 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10949 * @ap_adapter: SAP adapter
10950 *
10951 * This function will process the stopping of sap adapter.
10952 *
10953 * Return: None
10954 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010955void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010956{
Jeff Johnson87251032017-08-29 13:31:11 -070010957 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010958 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010959 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010960 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010961
10962 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010963 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010964 return;
10965 }
10966
10967 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10968 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010969 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010970 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010971
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010972 mutex_lock(&hdd_ctx->sap_lock);
10973 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010974 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010975 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010976 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010977 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010978 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070010979 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053010980 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010981 qdf_stop_bss_event,
10982 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010983 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010984 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010985 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010986 return;
10987 }
10988 }
10989 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010990 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10991 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070010992 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010993 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010994 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010995 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010996 }
10997 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010998}
10999
11000/**
11001 * wlan_hdd_start_sap() - this function starts bss of SAP.
11002 * @ap_adapter: SAP adapter
11003 *
11004 * This function will process the starting of sap adapter.
11005 *
11006 * Return: None
11007 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011008void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011009{
Jeff Johnson87251032017-08-29 13:31:11 -070011010 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011011 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011012 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011013 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011014 tsap_Config_t *sap_config;
11015
11016 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011017 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011018 return;
11019 }
11020
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011021 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011022 hdd_err("SoftAp role has not been enabled");
11023 return;
11024 }
11025
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011026 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11027 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11028 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011029 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011030
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011031 mutex_lock(&hdd_ctx->sap_lock);
11032 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11033 goto end;
11034
11035 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011036 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011037 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
11038 goto end;
11039 }
11040
Wei Song2f76f642016-11-18 16:32:53 +080011041 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011042 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011043 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011044 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011045 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011046 goto end;
11047
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011048 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011049 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011050 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011051 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011052 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011053 goto end;
11054 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011055 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011056 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070011057 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011058 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11059 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011060 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011061 mutex_unlock(&hdd_ctx->sap_lock);
11062
11063 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011064end:
11065 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011066 /* SAP context and beacon cleanup will happen during driver unload
11067 * in hdd_stop_adapter
11068 */
11069 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11070
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011071}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011072
11073/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011074 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11075 * mac scan config
11076 * @status: Status of set antenna mode
11077 *
11078 * Callback on setting the dual mac configuration
11079 *
11080 * Return: None
11081 */
11082void wlan_hdd_soc_set_antenna_mode_cb(
11083 enum set_antenna_mode_status status)
11084{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011085 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011086
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011087 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011088
11089 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11090 if (0 != wlan_hdd_validate_context(hdd_ctx))
11091 return;
11092
11093 /* Signal the completion of set dual mac config */
11094 complete(&hdd_ctx->set_antenna_mode_cmpl);
11095}
11096
11097/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011098 * hdd_get_fw_version() - Get FW version
11099 * @hdd_ctx: pointer to HDD context.
11100 * @major_spid: FW version - major spid.
11101 * @minor_spid: FW version - minor spid
11102 * @ssid: FW version - ssid
11103 * @crmid: FW version - crmid
11104 *
11105 * This function is called to get the firmware build version stored
11106 * as part of the HDD context
11107 *
11108 * Return: None
11109 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011110void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011111 uint32_t *major_spid, uint32_t *minor_spid,
11112 uint32_t *siid, uint32_t *crmid)
11113{
11114 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11115 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11116 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11117 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11118}
11119
11120#ifdef QCA_CONFIG_SMP
11121/**
11122 * wlan_hdd_get_cpu() - get cpu_index
11123 *
11124 * Return: cpu_index
11125 */
11126int wlan_hdd_get_cpu(void)
11127{
11128 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011129
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011130 put_cpu();
11131 return cpu_index;
11132}
11133#endif
11134
11135/**
11136 * hdd_get_fwpath() - get framework path
11137 *
11138 * This function is used to get the string written by
11139 * userspace to start the wlan driver
11140 *
11141 * Return: string
11142 */
11143const char *hdd_get_fwpath(void)
11144{
11145 return fwpath.string;
11146}
11147
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011148static int hdd_qdf_print_init(void)
11149{
11150 int qdf_print_idx;
11151 QDF_STATUS status;
11152
11153 status = qdf_print_setup();
11154 if (status != QDF_STATUS_SUCCESS) {
11155 pr_err("qdf_print_setup failed\n");
11156 return -EINVAL;
11157 }
11158
11159 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11160
11161 if (qdf_print_idx < 0) {
11162 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11163 qdf_print_idx);
11164 return -EINVAL;
11165 }
11166
11167 qdf_set_pidx(qdf_print_idx);
11168
11169 return 0;
11170}
11171
11172static void hdd_qdf_print_deinit(void)
11173{
11174 int qdf_print_idx;
11175
11176 qdf_print_idx = qdf_get_pidx();
11177 qdf_print_ctrl_cleanup(qdf_print_idx);
11178}
11179
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011180/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011181 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011182 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011183 * This function initilizes CDS global context with the help of cds_init. This
11184 * has to be the first function called after probe to get a valid global
11185 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011186 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011187 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011188 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011189int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011190{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011191 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011192 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011193
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011194 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011195 if (QDF_IS_STATUS_ERROR(status)) {
11196 hdd_err("Failed to allocate CDS context");
11197 ret = -ENOMEM;
11198 goto err_out;
11199 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011200
11201 wlan_init_bug_report_lock();
11202
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011203#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11204 wlan_logging_sock_init_svc();
11205#endif
11206
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011207 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11208 (void *)hdd_drv_ops_inactivity_handler, NULL,
11209 QDF_TIMER_TYPE_SW);
11210
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011211 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011212 hdd_qdf_print_init();
11213
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011214 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011215
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011216err_out:
11217 return ret;
11218}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011219
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011220/**
11221 * hdd_deinit() - Deinitialize Driver
11222 *
11223 * This function frees CDS global context with the help of cds_deinit. This
11224 * has to be the last function call in remove callback to free the global
11225 * context.
11226 */
11227void hdd_deinit(void)
11228{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011229 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011230
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011231 wlan_destroy_bug_report_lock();
11232 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011233
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011234 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011235#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11236 wlan_logging_sock_deinit_svc();
11237#endif
11238}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011239
Yue Ma6e7b1a02017-04-03 14:17:46 -070011240#ifdef QCA_WIFI_NAPIER_EMULATION
11241#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11242#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011243#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011244#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011245
Sachin Ahujadddd2632017-03-07 19:07:24 +053011246static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11247 struct file *file)
11248{
11249 return 0;
11250}
11251
11252static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11253 const char __user *user_buf,
11254 size_t count,
11255 loff_t *f_pos)
11256{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011257 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011258 static const char wlan_off_str[] = "OFF";
11259 static const char wlan_on_str[] = "ON";
11260 int ret;
11261 unsigned long rc;
11262
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011263 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011264 pr_err("Failed to read buffer\n");
11265 return -EINVAL;
11266 }
11267
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011268 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011269 pr_debug("Wifi turning off from UI\n");
11270 goto exit;
11271 }
11272
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011273 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011274 pr_err("Invalid value received from framework");
11275 goto exit;
11276 }
11277
11278 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011279 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011280 rc = wait_for_completion_timeout(&wlan_start_comp,
11281 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11282 if (!rc) {
11283 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11284 ret = -EINVAL;
11285 hdd_start_complete(ret);
11286 return ret;
11287 }
11288
11289 hdd_start_complete(0);
11290 }
11291
11292exit:
11293 return count;
11294}
11295
11296
11297const struct file_operations wlan_hdd_state_fops = {
11298 .owner = THIS_MODULE,
11299 .open = wlan_hdd_state_ctrl_param_open,
11300 .write = wlan_hdd_state_ctrl_param_write,
11301};
11302
11303static int wlan_hdd_state_ctrl_param_create(void)
11304{
11305 unsigned int wlan_hdd_state_major = 0;
11306 int ret;
11307 struct device *dev;
11308
11309 device = MKDEV(wlan_hdd_state_major, 0);
11310
11311 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11312 if (ret) {
11313 pr_err("Failed to register qcwlanstate");
11314 goto dev_alloc_err;
11315 }
11316 wlan_hdd_state_major = MAJOR(device);
11317
11318 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11319 if (IS_ERR(class)) {
11320 pr_err("wlan_hdd_state class_create error");
11321 goto class_err;
11322 }
11323
11324 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11325 if (IS_ERR(dev)) {
11326 pr_err("wlan_hdd_statedevice_create error");
11327 goto err_class_destroy;
11328 }
11329
11330 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11331 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11332 if (ret) {
11333 pr_err("Failed to add cdev error");
11334 goto cdev_add_err;
11335 }
11336
11337 pr_info("wlan_hdd_state %s major(%d) initialized",
11338 WLAN_MODULE_NAME, wlan_hdd_state_major);
11339
11340 return 0;
11341
11342cdev_add_err:
11343 device_destroy(class, device);
11344err_class_destroy:
11345 class_destroy(class);
11346class_err:
11347 unregister_chrdev_region(device, dev_num);
11348dev_alloc_err:
11349 return -ENODEV;
11350}
11351
11352static void wlan_hdd_state_ctrl_param_destroy(void)
11353{
11354 cdev_del(&wlan_hdd_state_cdev);
11355 device_destroy(class, device);
11356 class_destroy(class);
11357 unregister_chrdev_region(device, dev_num);
11358
11359 pr_info("Device node unregistered");
11360}
11361
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011362/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011363 * component_init - API to init cld component's
11364 *
11365 * Return: None
11366 */
11367static void component_init(void)
11368{
11369 pmo_init();
11370}
11371
11372/**
11373 * component_deinit - API to deinit cld component's
11374 *
11375 * Return: None
11376 */
11377static void component_deinit(void)
11378{
11379 pmo_deinit();
11380}
11381
11382/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011383 * __hdd_module_init - Module init helper
11384 *
11385 * Module init helper function used by both module and static driver.
11386 *
11387 * Return: 0 for success, errno on failure
11388 */
11389static int __hdd_module_init(void)
11390{
11391 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011392
Dustin Brown96cd9632017-11-13 12:45:04 -080011393 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011394 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011395 g_wlan_driver_version,
Dustin Brownab482ac2017-06-09 17:00:44 -070011396 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011397
Sachin Ahujadddd2632017-03-07 19:07:24 +053011398 ret = wlan_hdd_state_ctrl_param_create();
11399 if (ret) {
11400 pr_err("wlan_hdd_state_create:%x\n", ret);
11401 goto err_dev_state;
11402 }
11403
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011404 pld_init();
11405
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011406 ret = hdd_init();
11407 if (ret) {
11408 pr_err("hdd_init failed %x\n", ret);
11409 goto err_hdd_init;
11410 }
11411
Rajeev Kumar97767a02016-11-30 11:20:40 -080011412 dispatcher_init();
11413
Mukul Sharmad75a6672017-06-22 15:40:53 +053011414 /* Ensure to call post objmgr init */
11415 component_init();
11416
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011417 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011418
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011419 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011420
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011421 ret = wlan_hdd_register_driver();
11422 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011423 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11424 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011425 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011426 }
11427
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011428 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011429
11430 return 0;
11431out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011432 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011433 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011434 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011435 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011436
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011437err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011438 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011439 wlan_hdd_state_ctrl_param_destroy();
11440err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011441 return ret;
11442}
11443
11444/**
11445 * __hdd_module_exit - Module exit helper
11446 *
11447 * Module exit helper function used by both module and static driver.
11448 */
11449static void __hdd_module_exit(void)
11450{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011451
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011452 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11453 QWLAN_VERSIONSTR);
11454
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011455 hdd_wait_for_recovery_completion();
11456
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011457 wlan_hdd_unregister_driver();
11458
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011459 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011460
Mukul Sharmad75a6672017-06-22 15:40:53 +053011461 /* Ensure to call prior to objmgr deinit */
11462 component_deinit();
11463
Rajeev Kumar97767a02016-11-30 11:20:40 -080011464 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011465 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011466 pld_deinit();
11467
Sachin Ahujadddd2632017-03-07 19:07:24 +053011468 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011469}
11470
Arun Khandavallifae92942016-08-01 13:31:08 +053011471#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011472/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011473 * wlan_boot_cb() - Wlan boot callback
11474 * @kobj: object whose directory we're creating the link in.
11475 * @attr: attribute the user is interacting with
11476 * @buff: the buffer containing the user data
11477 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011478 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011479 * This callback is invoked when the fs is ready to start the
11480 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011481 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011482 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011483 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011484static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011485 struct kobj_attribute *attr,
11486 const char *buf,
11487 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011488{
Arun Khandavallifae92942016-08-01 13:31:08 +053011489
Arun Khandavallifae92942016-08-01 13:31:08 +053011490 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011491 pr_err("%s: wlan driver already initialized\n", __func__);
11492 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011493 }
11494
Arun Khandavallifae92942016-08-01 13:31:08 +053011495 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011496 pr_err("%s: wlan driver initialization failed\n", __func__);
11497 return -EIO;
11498 }
11499
11500 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011501
11502 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011503}
Arun Khandavallifae92942016-08-01 13:31:08 +053011504
11505/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011506 * hdd_sysfs_cleanup() - cleanup sysfs
11507 *
11508 * Return: None
11509 *
11510 */
11511static void hdd_sysfs_cleanup(void)
11512{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011513 /* remove from group */
11514 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11515 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11516 wlan_loader->attr_group);
11517
11518 /* unlink the object from parent */
11519 kobject_del(wlan_loader->boot_wlan_obj);
11520
11521 /* free the object */
11522 kobject_put(wlan_loader->boot_wlan_obj);
11523
11524 kfree(wlan_loader->attr_group);
11525 kfree(wlan_loader);
11526
11527 wlan_loader = NULL;
11528}
11529
11530/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011531 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11532 * ready
11533 *
11534 * This is creates the syfs entry boot_wlan. Which shall be invoked
11535 * when the filesystem is ready.
11536 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011537 * QDF API cannot be used here since this function is called even before
11538 * initializing WLAN driver.
11539 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011540 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011541 */
11542static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011543{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011544 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011545
11546 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011547 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011548 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011549
11550 wlan_loader->boot_wlan_obj = NULL;
11551 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11552 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011553 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011554 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011555
11556 wlan_loader->loaded_state = 0;
11557 wlan_loader->attr_group->attrs = attrs;
11558
11559 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11560 kernel_kobj);
11561 if (!wlan_loader->boot_wlan_obj) {
11562 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011563 goto error_return;
11564 }
11565
11566 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11567 wlan_loader->attr_group);
11568 if (ret) {
11569 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11570 goto error_return;
11571 }
11572
11573 return 0;
11574
11575error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011576 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011577
11578 return ret;
11579}
11580
11581/**
11582 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11583 *
11584 * Return: 0 on success or errno on failure
11585 */
11586static int wlan_deinit_sysfs(void)
11587{
Arun Khandavallifae92942016-08-01 13:31:08 +053011588 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011589 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011590 return -EINVAL;
11591 }
11592
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011593 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011594 return 0;
11595}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011596
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011597#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011598
11599#ifdef MODULE
11600/**
11601 * __hdd_module_init - Module init helper
11602 *
11603 * Module init helper function used by both module and static driver.
11604 *
11605 * Return: 0 for success, errno on failure
11606 */
11607static int hdd_module_init(void)
11608{
Arun Khandavallifae92942016-08-01 13:31:08 +053011609 if (__hdd_module_init()) {
11610 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011611 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011612 }
11613
Dustin Brownab482ac2017-06-09 17:00:44 -070011614 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011615}
11616#else
11617static int __init hdd_module_init(void)
11618{
11619 int ret = -EINVAL;
11620
11621 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011622 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011623 pr_err("Failed to create sysfs entry for loading wlan");
11624
11625 return ret;
11626}
11627#endif
11628
11629
11630#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011631/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011632 * hdd_module_exit() - Exit function
11633 *
11634 * This is the driver exit point (invoked when module is unloaded using rmmod)
11635 *
11636 * Return: None
11637 */
11638static void __exit hdd_module_exit(void)
11639{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011640 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011641}
Arun Khandavallifae92942016-08-01 13:31:08 +053011642#else
11643static void __exit hdd_module_exit(void)
11644{
11645 __hdd_module_exit();
11646 wlan_deinit_sysfs();
11647}
11648#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011649
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011650static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11651{
11652 return param_set_copystring(kmessage, kp);
11653}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011654
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011655/**
11656 * is_con_mode_valid() check con mode is valid or not
11657 * @mode: global con mode
11658 *
11659 * Return: TRUE on success FALSE on failure
11660 */
11661static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11662{
11663 switch (mode) {
11664 case QDF_GLOBAL_MONITOR_MODE:
11665 case QDF_GLOBAL_FTM_MODE:
11666 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011667 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011668 return true;
11669 default:
11670 return false;
11671 }
11672}
11673
11674/**
11675 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11676 * @mode: global con mode
11677 *
11678 * Return: adapter mode
11679 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011680static enum QDF_OPMODE hdd_get_adpter_mode(
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011681 enum tQDF_GLOBAL_CON_MODE mode)
11682{
11683
11684 switch (mode) {
11685 case QDF_GLOBAL_MISSION_MODE:
11686 return QDF_STA_MODE;
11687 case QDF_GLOBAL_MONITOR_MODE:
11688 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011689 case QDF_GLOBAL_EPPING_MODE:
11690 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011691 case QDF_GLOBAL_FTM_MODE:
11692 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011693 case QDF_GLOBAL_QVIT_MODE:
11694 return QDF_QVIT_MODE;
11695 default:
11696 return QDF_MAX_NO_OF_MODE;
11697 }
11698}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011699
Dustin Brown27cd9942017-09-27 16:11:44 -070011700static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11701 enum tQDF_GLOBAL_CON_MODE curr_mode)
11702{
11703 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11704 return;
11705
11706 switch (curr_mode) {
11707 case QDF_GLOBAL_MISSION_MODE:
11708 case QDF_GLOBAL_MONITOR_MODE:
11709 case QDF_GLOBAL_FTM_MODE:
11710 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11711 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11712
11713 /* re-use the existing session */
11714 hdd_stop_all_adapters(hdd_ctx, false);
11715 break;
11716 default:
11717 break;
11718 }
11719}
11720
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011721static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011722 enum tQDF_GLOBAL_CON_MODE curr_mode)
11723{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011724 int driver_status;
11725
11726 driver_status = hdd_ctx->driver_status;
11727
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011728 switch (curr_mode) {
11729 case QDF_GLOBAL_MISSION_MODE:
11730 case QDF_GLOBAL_MONITOR_MODE:
11731 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011732 hdd_deinit_all_adapters(hdd_ctx, false);
11733 hdd_close_all_adapters(hdd_ctx, false);
11734 break;
11735 case QDF_GLOBAL_EPPING_MODE:
11736 epping_disable();
11737 epping_close();
11738 break;
11739 default:
11740 return;
11741 }
11742}
11743
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011744static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011745 enum tQDF_GLOBAL_CON_MODE mode)
11746{
Jeff Johnson9d295242017-08-29 14:39:48 -070011747 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011748 int ret = 0;
11749 bool rtnl_held;
11750 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11751 QDF_STATUS status;
11752
11753 if (!qdf_dev) {
11754 hdd_err("qdf device context is Null return!");
11755 return -EINVAL;
11756 }
11757
11758 rtnl_held = hdd_hold_rtnl_lock();
11759 switch (mode) {
11760 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011761 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11762 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011763 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011764 break;
11765 case QDF_GLOBAL_FTM_MODE:
11766 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11767 wlan_hdd_get_intf_addr(hdd_ctx),
11768 NET_NAME_UNKNOWN, rtnl_held);
11769 if (adapter == NULL)
11770 ret = -EINVAL;
11771 break;
11772 case QDF_GLOBAL_MONITOR_MODE:
11773 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11774 wlan_hdd_get_intf_addr(hdd_ctx),
11775 NET_NAME_UNKNOWN, rtnl_held);
11776 if (adapter == NULL)
11777 ret = -EINVAL;
11778 break;
11779 case QDF_GLOBAL_EPPING_MODE:
11780 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011781 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011782 hdd_err("Failed to open in eeping mode: %d", status);
11783 ret = -EINVAL;
11784 break;
11785 }
11786 ret = epping_enable(qdf_dev->dev);
11787 if (ret) {
11788 hdd_err("Failed to enable in epping mode : %d", ret);
11789 epping_close();
11790 }
11791 break;
11792 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011793 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011794 ret = -ENOTSUPP;
11795 break;
11796 }
11797 hdd_release_rtnl_lock();
11798 rtnl_held = false;
11799 return ret;
11800}
11801
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011802/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011803 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011804 * @kmessage: con mode name on which driver to be bring up
11805 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011806 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011807 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011808 * This function is invoked when user updates con mode using sys entry,
11809 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011810 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011811 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011812 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011813static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011814 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011815{
11816 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011817 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011818 enum tQDF_GLOBAL_CON_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011819 enum QDF_OPMODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011820
Dustin Brownab6029b2017-05-24 13:04:19 -070011821 hdd_info("con_mode handler: %s", kmessage);
11822
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011823 ret = wlan_hdd_validate_context(hdd_ctx);
11824 if (ret)
11825 return ret;
11826
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011827 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011828
11829 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011830
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011831 if (!(is_con_mode_valid(con_mode))) {
11832 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011833 ret = -EINVAL;
11834 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011835 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011836
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011837 curr_mode = hdd_get_conparam();
11838 if (curr_mode == con_mode) {
11839 hdd_err("curr mode: %d is same as user triggered mode %d",
11840 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011841 ret = 0;
11842 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011843 }
11844
Dustin Brown27cd9942017-09-27 16:11:44 -070011845 /* ensure adapters are stopped */
11846 hdd_stop_present_mode(hdd_ctx, curr_mode);
11847
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011848 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011849 if (ret) {
11850 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011851 goto reset_flags;
11852 }
11853
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011854 /* Cleanup present mode before switching to new mode */
11855 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11856
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011857 hdd_set_conparam(con_mode);
11858
11859 /* Register for new con_mode & then kick_start modules again */
11860 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11861 if (ret) {
11862 hdd_err("Failed to register for new mode");
11863 goto reset_flags;
11864 }
11865
11866 adapter_mode = hdd_get_adpter_mode(con_mode);
11867 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11868 hdd_err("invalid adapter");
11869 ret = -EINVAL;
11870 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011871 }
11872
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011873 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011874 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011875 hdd_err("Failed to get adapter:%d", adapter_mode);
11876 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011877 }
11878
11879 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11880 if (ret) {
11881 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011882 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011883 }
11884
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011885 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011886 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011887 if (hdd_start_adapter(adapter)) {
11888 hdd_err("Failed to start %s adapter", kmessage);
11889 ret = -EINVAL;
11890 goto reset_flags;
11891 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011892 }
11893
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011894 hdd_info("Mode successfully changed to %s", kmessage);
11895 ret = 0;
11896
11897reset_flags:
11898 cds_set_load_in_progress(false);
11899 return ret;
11900}
11901
11902
11903static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11904{
11905 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011906 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011907
11908 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11909 ret = wlan_hdd_validate_context(hdd_ctx);
11910 if (ret)
11911 return ret;
11912
11913 cds_ssr_protect(__func__);
11914 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11915 cds_ssr_unprotect(__func__);
11916
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011917 return ret;
11918}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011919
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011920static int con_mode_handler_ftm(const char *kmessage,
11921 struct kernel_param *kp)
11922{
11923 int ret;
11924
11925 ret = param_set_int(kmessage, kp);
11926
11927 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11928 pr_err("Only FTM mode supported!");
11929 return -ENOTSUPP;
11930 }
11931
11932 hdd_set_conparam(con_mode_ftm);
11933 con_mode = con_mode_ftm;
11934
11935 return ret;
11936}
11937
Ravi Joshia307f632017-07-17 23:41:41 -070011938static int con_mode_handler_monitor(const char *kmessage,
11939 struct kernel_param *kp)
11940{
11941 int ret;
11942
11943 ret = param_set_int(kmessage, kp);
11944
11945 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11946 pr_err("Only Monitor mode supported!");
11947 return -ENOTSUPP;
11948 }
11949
11950 hdd_set_conparam(con_mode_monitor);
11951 con_mode = con_mode_monitor;
11952
11953 return ret;
11954}
11955
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011956/**
11957 * hdd_get_conparam() - driver exit point
11958 *
11959 * This is the driver exit point (invoked when module is unloaded using rmmod)
11960 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011961 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011962 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011963enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011964{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011965 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011966}
11967
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011968void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011969{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011970 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011971}
11972
Komal Seelamc11bb222016-01-27 18:57:10 +053011973/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011974 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11975 * @hdd_ctx: HDD context
11976 *
11977 * Cleans up the pre cac interface, if it exists
11978 *
11979 * Return: None
11980 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011981void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011982{
11983 uint8_t session_id;
11984 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011985 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011986
11987 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11988 if (QDF_IS_STATUS_ERROR(status)) {
11989 hdd_err("failed to get pre cac vdev id");
11990 return;
11991 }
11992
11993 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11994 if (!precac_adapter) {
11995 hdd_err("invalid pre cac adapater");
11996 return;
11997 }
11998
11999 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12000 wlan_hdd_sap_pre_cac_failure,
12001 (void *)precac_adapter);
12002 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12003
12004}
12005
12006/**
Komal Seelamec702b02016-02-24 18:42:16 +053012007 * hdd_update_ol_config - API to update ol configuration parameters
12008 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012009 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012010 * Return: void
12011 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012012static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012013{
Komal Seelamec702b02016-02-24 18:42:16 +053012014 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012015 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012016
Komal Seelamec702b02016-02-24 18:42:16 +053012017 if (!ol_ctx)
12018 return;
12019
12020 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12021 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12022 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12023 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012024 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012025
12026 ol_init_ini_config(ol_ctx, &cfg);
12027}
12028
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012029#ifdef FEATURE_RUNTIME_PM
12030/**
12031 * hdd_populate_runtime_cfg() - populate runtime configuration
12032 * @hdd_ctx: hdd context
12033 * @cfg: pointer to the configuration memory being populated
12034 *
12035 * Return: void
12036 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012037static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012038 struct hif_config_info *cfg)
12039{
12040 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12041 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12042}
12043#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012044static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012045 struct hif_config_info *cfg)
12046{
12047}
12048#endif
12049
Komal Seelamec702b02016-02-24 18:42:16 +053012050/**
12051 * hdd_update_hif_config - API to update HIF configuration parameters
12052 * @hdd_ctx: HDD Context
12053 *
12054 * Return: void
12055 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012056static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012057{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012058 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012059 struct hif_config_info cfg;
12060
12061 if (!scn)
12062 return;
12063
12064 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012065 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012066 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012067
12068 if (hdd_ctx->config->prevent_link_down)
12069 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012070}
12071
12072/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012073 * hdd_update_dp_config() - Propagate config parameters to Lithium
12074 * datapath
12075 * @hdd_ctx: HDD Context
12076 *
12077 * Return: 0 for success/errno for failure
12078 */
12079static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12080{
12081 struct cdp_config_params params;
12082 QDF_STATUS status;
12083
12084 params.tso_enable = hdd_ctx->config->tso_enable;
12085 params.lro_enable = hdd_ctx->config->lro_enable;
12086#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12087 params.tx_flow_stop_queue_threshold =
12088 hdd_ctx->config->TxFlowStopQueueThreshold;
12089 params.tx_flow_start_queue_offset =
12090 hdd_ctx->config->TxFlowStartQueueOffset;
12091#endif
12092 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12093 params.napi_enable = hdd_ctx->napi_enable;
12094 params.tcp_udp_checksumoffload =
12095 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12096
12097 status = cdp_update_config_parameters(
12098 cds_get_context(QDF_MODULE_ID_SOC),
12099 &params);
12100 if (status) {
12101 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
12102 "%s: Failed to attach config parameters", __func__);
12103 return status;
12104 }
12105
12106 return 0;
12107}
12108
12109/**
Komal Seelamec702b02016-02-24 18:42:16 +053012110 * hdd_update_config() - Initialize driver per module ini parameters
12111 * @hdd_ctx: HDD Context
12112 *
12113 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012114 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012115 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012116int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012117{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012118 int ret;
12119
Komal Seelamec702b02016-02-24 18:42:16 +053012120 hdd_update_ol_config(hdd_ctx);
12121 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012122 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12123 ret = hdd_update_cds_config_ftm(hdd_ctx);
12124 else
12125 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012126 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012127
12128 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012129}
12130
Mukul Sharma9d797a02017-01-05 20:26:03 +053012131#ifdef FEATURE_WLAN_RA_FILTERING
12132/**
12133 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12134 * @psoc_cfg: pmo psoc Configuration
12135 * @hdd_ctx: Pointer to hdd context
12136 *
12137 * Return: none
12138 */
12139static inline void hdd_ra_populate_pmo_config(
12140 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012141 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012142{
12143 psoc_cfg->ra_ratelimit_interval =
12144 hdd_ctx->config->RArateLimitInterval;
12145 psoc_cfg->ra_ratelimit_enable =
12146 hdd_ctx->config->IsRArateLimitEnabled;
12147}
12148#else
12149static inline void hdd_ra_populate_pmo_config(
12150 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012151 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012152{
12153}
12154#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012155
Mukul Sharma9d797a02017-01-05 20:26:03 +053012156/**
12157 * hdd_update_pmo_config - API to update pmo configuration parameters
12158 * @hdd_ctx: HDD context
12159 *
12160 * Return: void
12161 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012162static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012163{
12164 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12165 struct pmo_psoc_cfg psoc_cfg;
12166 QDF_STATUS status;
12167
12168 /*
12169 * Value of hdd_ctx->wowEnable can be,
12170 * 0 - Disable both magic pattern match and pattern byte match.
12171 * 1 - Enable magic pattern match on all interfaces.
12172 * 2 - Enable pattern byte match on all interfaces.
12173 * 3 - Enable both magic patter and pattern byte match on
12174 * all interfaces.
12175 */
12176 psoc_cfg.magic_ptrn_enable =
12177 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12178 psoc_cfg.ptrn_match_enable_all_vdev =
12179 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012180 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12181 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012182 psoc_cfg.bpf_enable =
12183 hdd_ctx->config->bpf_packet_filter_enable;
12184 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012185 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012186 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12187 if (hdd_ctx->config->fhostNSOffload)
12188 psoc_cfg.ns_offload_enable_dynamic = true;
12189 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12190 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12191 psoc_cfg.active_mode_offload =
12192 hdd_ctx->config->active_mode_offload;
12193 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012194 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9d797a02017-01-05 20:26:03 +053012195 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012196 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12197 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12198 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12199 psoc_cfg.power_save_mode =
12200 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012201 psoc_cfg.auto_power_save_fail_mode =
12202 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012203
12204 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012205 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12206 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012207 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012208 if (status != QDF_STATUS_SUCCESS) {
12209 hdd_err("failed pmo psoc configuration");
12210 return -EINVAL;
12211 }
12212
12213 return 0;
12214}
12215
Abhishek Singhb20db962017-03-03 21:28:46 +053012216#ifdef FEATURE_WLAN_SCAN_PNO
12217static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12218 struct hdd_config *cfg)
12219{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012220 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12221
Abhishek Singhb20db962017-03-03 21:28:46 +053012222 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12223 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12224 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12225 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12226 pno_cfg->channel_prediction_full_scan =
12227 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012228 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12229 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12230 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12231 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012232}
12233#else
12234static inline void
12235hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012236 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012237{
Abhishek Singhb20db962017-03-03 21:28:46 +053012238}
12239#endif
12240
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012241void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12242 struct hdd_config *cfg)
12243{
12244 uint8_t i = 0;
12245
12246 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12247 if (!ie_whitelist->white_list)
12248 return;
12249
12250 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12251 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12252 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12253 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12254 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12255 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12256 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12257 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12258
12259 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12260 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12261 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12262}
12263
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012264uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12265{
12266 uint8_t i, score;
12267
12268 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12269 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12270 if (score > MAX_INDEX_SCORE)
12271 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12272 MAX_INDEX_SCORE, i);
12273 }
12274
12275 return per_index_score;
12276}
12277
12278/**
12279 * hdd_update_score_config - API to update candidate scoring related params
12280 * configuration parameters
12281 * @score_config: score config to update
12282 * @cfg: config params
12283 *
12284 * Return: 0 if success else err
12285 */
12286static void hdd_update_score_config(
12287 struct scoring_config *score_config, struct hdd_config *cfg)
12288{
12289 int total_weight;
12290
12291 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12292 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12293 score_config->weight_cfg.vht_caps_weightage =
12294 cfg->vht_caps_weightage;
12295 score_config->weight_cfg.he_caps_weightage =
12296 cfg->he_caps_weightage;
12297 score_config->weight_cfg.chan_width_weightage =
12298 cfg->chan_width_weightage;
12299 score_config->weight_cfg.chan_band_weightage =
12300 cfg->chan_band_weightage;
12301 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12302 score_config->weight_cfg.beamforming_cap_weightage =
12303 cfg->beamforming_cap_weightage;
12304 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12305 score_config->weight_cfg.channel_congestion_weightage =
12306 cfg->channel_congestion_weightage;
12307 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12308
12309 total_weight = score_config->weight_cfg.rssi_weightage +
12310 score_config->weight_cfg.ht_caps_weightage +
12311 score_config->weight_cfg.vht_caps_weightage +
12312 score_config->weight_cfg.he_caps_weightage +
12313 score_config->weight_cfg.chan_width_weightage +
12314 score_config->weight_cfg.chan_band_weightage +
12315 score_config->weight_cfg.nss_weightage +
12316 score_config->weight_cfg.beamforming_cap_weightage +
12317 score_config->weight_cfg.pcl_weightage +
12318 score_config->weight_cfg.channel_congestion_weightage +
12319 score_config->weight_cfg.oce_wan_weightage;
12320
12321 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12322 hdd_err("total weight is greater than %d fallback to default values",
12323 BEST_CANDIDATE_MAX_WEIGHT);
12324
12325 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12326 score_config->weight_cfg.ht_caps_weightage =
12327 HT_CAPABILITY_WEIGHTAGE;
12328 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12329 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12330 score_config->weight_cfg.chan_width_weightage =
12331 CHAN_WIDTH_WEIGHTAGE;
12332 score_config->weight_cfg.chan_band_weightage =
12333 CHAN_BAND_WEIGHTAGE;
12334 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12335 score_config->weight_cfg.beamforming_cap_weightage =
12336 BEAMFORMING_CAP_WEIGHTAGE;
12337 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12338 score_config->weight_cfg.channel_congestion_weightage =
12339 CHANNEL_CONGESTION_WEIGHTAGE;
12340 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12341 }
12342
12343 score_config->bandwidth_weight_per_index =
12344 hdd_limit_max_per_index_score(
12345 cfg->bandwidth_weight_per_index);
12346 score_config->nss_weight_per_index =
12347 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12348 score_config->band_weight_per_index =
12349 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12350
12351 score_config->rssi_score.best_rssi_threshold =
12352 cfg->best_rssi_threshold;
12353 score_config->rssi_score.good_rssi_threshold =
12354 cfg->good_rssi_threshold;
12355 score_config->rssi_score.bad_rssi_threshold =
12356 cfg->bad_rssi_threshold;
12357 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12358 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12359 score_config->rssi_score.good_rssi_bucket_size =
12360 cfg->good_rssi_bucket_size;
12361 score_config->rssi_score.bad_rssi_bucket_size =
12362 cfg->bad_rssi_bucket_size;
12363 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12364 cfg->rssi_pref_5g_rssi_thresh;
12365
12366 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12367 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12368 hdd_limit_max_per_index_score(
12369 cfg->esp_qbss_score_slots3_to_0);
12370 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12371 hdd_limit_max_per_index_score(
12372 cfg->esp_qbss_score_slots7_to_4);
12373 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12374 hdd_limit_max_per_index_score(
12375 cfg->esp_qbss_score_slots11_to_8);
12376 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12377 hdd_limit_max_per_index_score(
12378 cfg->esp_qbss_score_slots15_to_12);
12379
12380 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12381 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12382 hdd_limit_max_per_index_score(
12383 cfg->oce_wan_score_slots3_to_0);
12384 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12385 hdd_limit_max_per_index_score(
12386 cfg->oce_wan_score_slots7_to_4);
12387 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12388 hdd_limit_max_per_index_score(
12389 cfg->oce_wan_score_slots11_to_8);
12390 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12391 hdd_limit_max_per_index_score(
12392 cfg->oce_wan_score_slots15_to_12);
12393
12394
12395 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12396 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12397 score_config->nss = cfg->enable2x2 ? 2 : 1;
12398
12399 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12400 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12401 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12402 score_config->he_cap = 1;
12403
12404 if (score_config->he_cap ||
12405 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12406 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12407 score_config->vht_cap = 1;
12408
12409 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12410 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12411 score_config->ht_cap = 1;
12412
12413 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12414 score_config->vht_24G_cap = 1;
12415
12416 if (cfg->enableTxBF)
12417 score_config->beamformee_cap = 1;
12418
12419}
12420
Abhishek Singh257a9482017-03-06 16:52:39 +053012421/**
12422 * hdd_update_scan_config - API to update scan configuration parameters
12423 * @hdd_ctx: HDD context
12424 *
12425 * Return: 0 if success else err
12426 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012427static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012428{
12429 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12430 struct scan_user_cfg scan_cfg;
12431 struct hdd_config *cfg = hdd_ctx->config;
12432 QDF_STATUS status;
12433
12434 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12435 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12436 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12437 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12438 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12439 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12440 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012441 /* convert to ms */
12442 scan_cfg.scan_cache_aging_time =
12443 cfg->scanAgingTimeout * 1000;
12444 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12445 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12446 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12447 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012448 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012449 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012450 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12451 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012452 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012453 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singh257a9482017-03-06 16:52:39 +053012454
Abhishek Singhb20db962017-03-03 21:28:46 +053012455 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012456 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012457 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012458
Abhishek Singh257a9482017-03-06 16:52:39 +053012459 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12460 if (status != QDF_STATUS_SUCCESS) {
12461 hdd_err("failed pmo psoc configuration");
12462 return -EINVAL;
12463 }
12464
12465 return 0;
12466}
Abhishek Singh257a9482017-03-06 16:52:39 +053012467
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012468static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012469{
12470 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12471 struct tdls_start_params tdls_cfg;
12472 struct tdls_user_config *config = &tdls_cfg.config;
12473 struct hdd_config *cfg = hdd_ctx->config;
12474 QDF_STATUS status;
12475
12476 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12477 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12478 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12479 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12480 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12481 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12482 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12483 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12484 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12485 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12486 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12487 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12488 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12489 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12490 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12491 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12492 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12493 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12494 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12495 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12496 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12497 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12498 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12499 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12500 (cfg->fEnableTDLSImplicitTrigger ?
12501 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12502 (cfg->fTDLSExternalControl ?
12503 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12504
12505 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12506 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12507 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12508 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012509 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012510 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012511 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12512 tdls_cfg.tdls_evt_cb_data = psoc;
12513 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12514 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12515 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012516 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12517 tdls_cfg.tdls_wmm_cb_data = psoc;
12518 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12519 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012520 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012521
12522 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12523 if (status != QDF_STATUS_SUCCESS) {
12524 hdd_err("failed pmo psoc configuration");
12525 return -EINVAL;
12526 }
12527
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012528 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012529 /* enable napier specific tdls data path */
12530 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012531
Frank Liud4b2fa02017-03-29 11:46:48 +080012532 return 0;
12533}
Frank Liud4b2fa02017-03-29 11:46:48 +080012534
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012535int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012536{
12537 int ret;
12538
12539 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012540 if (ret)
12541 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012542
Abhishek Singh257a9482017-03-06 16:52:39 +053012543 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012544 if (ret)
12545 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012546
Frank Liud4b2fa02017-03-29 11:46:48 +080012547 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012548 if (ret)
12549 return ret;
12550
12551 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012552
12553 return ret;
12554}
12555
Agrawal Ashish65634612016-08-18 13:24:32 +053012556/**
12557 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12558 * @mode : cfg80211 DFS mode
12559 *
12560 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12561 */
12562enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12563{
12564 switch (mode) {
12565 case DFS_MODE_ENABLE:
12566 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012567 case DFS_MODE_DISABLE:
12568 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012569 case DFS_MODE_DEPRIORITIZE:
12570 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012571 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012572 hdd_debug("ACS dfs mode is NONE");
12573 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012574 }
12575}
12576
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012577/**
12578 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12579 * @hddctx: pointer to hdd context
12580 * @set_value: enable/disable
12581 *
12582 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12583 * Host(even though it is duplicate). When Host send vendor command
12584 * disable,FW doesn't perform any action. Whenever any change in
12585 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12586 *
12587 * return - 0 on success, appropriate error values on failure.
12588 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012589int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012590{
12591 QDF_STATUS status;
12592
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012593 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012594 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012595
12596 if (!hddctx->config->goptimize_chan_avoid_event) {
12597 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12598 return -EINVAL;
12599 }
12600
12601 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12602 if (!QDF_IS_STATUS_SUCCESS(status)) {
12603 hdd_err("Failed to send chan avoid command to SME");
12604 return -EINVAL;
12605 }
12606 return 0;
12607}
Agrawal Ashish65634612016-08-18 13:24:32 +053012608
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012609/**
12610 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12611 * @value: value to set
12612 *
12613 * This function will set the passed value to roaming in progress flag.
12614 *
12615 * Return: None
12616 */
12617void hdd_set_roaming_in_progress(bool value)
12618{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012619 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012620
12621 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12622 if (!hdd_ctx) {
12623 hdd_err("HDD context is NULL");
12624 return;
12625 }
12626
12627 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012628 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012629}
12630
12631/**
12632 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012633 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012634 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012635 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012636 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012637bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012638{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012639 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012640 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012641
12642 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12643 if (!hdd_ctx) {
12644 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012645 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012646 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012647 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12648 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012649 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12650 hdd_ctx->roaming_in_progress);
12651
12652 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012653}
12654
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012655/**
12656 * hdd_is_connection_in_progress() - check if connection is in
12657 * progress
12658 * @session_id: session id
12659 * @reason: scan reject reason
12660 *
12661 * Go through each adapter and check if Connection is in progress
12662 *
12663 * Return: true if connection is in progress else false
12664 */
12665bool hdd_is_connection_in_progress(uint8_t *session_id,
12666 enum scan_reject_states *reason)
12667{
12668 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012669 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012670 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012671 QDF_STATUS status = 0;
12672 uint8_t sta_id = 0;
12673 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012674 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012675
12676 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12677 if (!hdd_ctx) {
12678 hdd_err("HDD context is NULL");
12679 return false;
12680 }
12681
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012682 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12683 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012684 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012685 if (!adapter)
12686 goto end;
12687
12688 hdd_info("Adapter with device mode %s(%d) exists",
12689 hdd_device_mode_to_string(adapter->device_mode),
12690 adapter->device_mode);
12691 if (((QDF_STA_MODE == adapter->device_mode)
12692 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12693 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12694 && (eConnectionState_Connecting ==
12695 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12696 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012697 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012698 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012699 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012700 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012701 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012702 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012703 }
12704 return true;
12705 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012706 /*
12707 * sme_neighbor_middle_of_roaming is for LFR2
12708 * hdd_is_roaming_in_progress is for LFR3
12709 */
12710 if (((QDF_STA_MODE == adapter->device_mode) &&
12711 sme_neighbor_middle_of_roaming(
12712 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012713 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012714 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012715 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012716 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012717 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012718 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012719 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012720 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012721 }
12722 return true;
12723 }
12724 if ((QDF_STA_MODE == adapter->device_mode) ||
12725 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12726 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12727 hdd_sta_ctx =
12728 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12729 if ((eConnectionState_Associated ==
12730 hdd_sta_ctx->conn_info.connState)
12731 && (false ==
12732 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12733 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070012734 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012735 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012736 " is in middle of WPS/EAPOL exchange.",
12737 MAC_ADDR_ARRAY(sta_mac));
12738 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012739 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012740 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012741 }
12742 return true;
12743 }
12744 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12745 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12746 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12747 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012748 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012749 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012750 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012751 continue;
12752
12753 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012754 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070012755 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012756 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012757 " of SAP/GO is in middle of WPS/EAPOL exchange",
12758 MAC_ADDR_ARRAY(sta_mac));
12759 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012760 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012761 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012762 }
12763 return true;
12764 }
12765 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012766 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012767 return true;
12768 }
12769 }
12770end:
12771 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12772 adapter_node = next;
12773 }
12774 return false;
12775}
12776
12777/**
12778 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012779 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012780 *
12781 * Return: None
12782 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012783void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012784{
Jeff Johnson87251032017-08-29 13:31:11 -070012785 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012786 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012787 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012788 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012789 tsap_Config_t *sap_config;
12790 void *sap_ctx;
12791
12792 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070012793 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012794 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012795
12796 mutex_lock(&hdd_ctx->sap_lock);
12797 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12798 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012799 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12800 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12801 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12802 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053012803 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012804 qdf_stop_bss_event,
12805 SME_CMD_TIMEOUT_VALUE);
12806
12807 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012808 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012809 goto end;
12810 }
12811 }
12812 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012813 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012814 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012815 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012816
12817 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012818 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012819 wlansap_reset_sap_config_add_ie(sap_config,
12820 eUPDATE_IE_ALL);
12821 goto end;
12822 }
12823
12824 qdf_event_reset(&hostapd_state->qdf_event);
12825 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12826 sap_config,
12827 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012828 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012829 wlansap_reset_sap_config_add_ie(sap_config,
12830 eUPDATE_IE_ALL);
12831 goto end;
12832 }
12833
Jeff Johnson6867ec32017-09-29 20:30:20 -070012834 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012835 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053012836 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012837 SME_CMD_TIMEOUT_VALUE);
12838 wlansap_reset_sap_config_add_ie(sap_config,
12839 eUPDATE_IE_ALL);
12840 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012841 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012842 goto end;
12843 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012844 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012845 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070012846 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012847 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12848 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012849 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012850 }
12851end:
12852 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012853}
12854
12855/**
12856 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12857 * with non dfs acs
12858 *
12859 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12860 *
12861 * Return: None
12862 */
12863void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12864{
Jeff Johnson9d295242017-08-29 14:39:48 -070012865 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012866 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012867 cds_context_type *cds_ctx;
12868
12869 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12870 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012871 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012872 return;
12873 }
12874
12875 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12876 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012877 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012878 return;
12879 }
12880
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012881 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12882 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012883 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012884 return;
12885 }
12886
12887 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012888 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12889 &ap_adapter->event_flags) &&
12890 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070012891 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012892
Jeff Johnson6867ec32017-09-29 20:30:20 -070012893 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070012894 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012895 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070012896 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012897 acs_cfg.acs_mode = true;
12898
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012899 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012900 }
12901}
12902
12903/**
12904 * hdd_set_connection_in_progress() - to set the connection in
12905 * progress flag
12906 * @value: value to set
12907 *
12908 * This function will set the passed value to connection in progress flag.
12909 * If value is previously being set to true then no need to set it again.
12910 *
12911 * Return: true if value is being set correctly and false otherwise.
12912 */
12913bool hdd_set_connection_in_progress(bool value)
12914{
12915 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012916 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012917
12918 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12919 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012920 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012921 return false;
12922 }
12923
12924 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12925 /*
12926 * if the value is set to true previously and if someone is
12927 * trying to make it true again then it could be some race
12928 * condition being triggered. Avoid this situation by returning
12929 * false
12930 */
12931 if (hdd_ctx->connection_in_progress && value)
12932 status = false;
12933 else
12934 hdd_ctx->connection_in_progress = value;
12935 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12936 return status;
12937}
12938
Jeff Johnson9d295242017-08-29 14:39:48 -070012939int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012940{
12941 if (!adapter) {
12942 hdd_err("Invalid adapter");
12943 return -EINVAL;
12944 }
12945 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070012946 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012947 WMA_VDEV_MCC_SET_TIME_QUOTA,
12948 set_value, VDEV_CMD);
12949 return 0;
12950
12951}
12952
Jeff Johnson9d295242017-08-29 14:39:48 -070012953int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012954{
12955 if (!adapter) {
12956 hdd_err("Invalid adapter");
12957 return -EINVAL;
12958 }
12959
12960 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070012961 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012962 WMA_VDEV_MCC_SET_TIME_LATENCY,
12963 set_value, VDEV_CMD);
12964 return 0;
12965}
12966
Jeff Johnson9d295242017-08-29 14:39:48 -070012967struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012968 *psoc, uint8_t vdev_id)
12969{
Jeff Johnson9d295242017-08-29 14:39:48 -070012970 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012971 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012972
12973 /*
12974 * Currently PSOC is not being used. But this logic will
12975 * change once we have the converged implementation of
12976 * HDD context per PSOC in place. This would break if
12977 * multiple vdev objects reuse the vdev id.
12978 */
12979 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12980 if (!adapter)
12981 hdd_err("Get adapter by vdev id failed");
12982
12983 return adapter;
12984}
12985
Jeff Johnson9d295242017-08-29 14:39:48 -070012986int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012987 int8_t *rssi, int8_t *snr)
12988{
12989 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012990 struct hdd_wext_state *wext_state =
12991 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012992 tCsrRoamProfile *profile = &wext_state->roamProfile;
12993
12994 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12995 profile, bssid, rssi, snr);
12996 if (QDF_STATUS_SUCCESS != status) {
12997 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12998 return -EINVAL;
12999 }
13000
13001 return 0;
13002}
13003
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013004/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013005 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13006 * @adapter - HDD adapter
13007 * @tos - type of service
13008 * @status - status of the traffic
13009 *
13010 * Return: 0 on success and non zero value on failure
13011 */
13012
13013int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13014 bool is_tos_active)
13015{
13016 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013017 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013018 uint32_t max_off_chan_time = 0;
13019 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013020 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013021 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013022
13023 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13024 ret = wlan_hdd_validate_context(hdd_ctx);
13025
13026 if (ret < 0) {
13027 hdd_err("failed to set limit off chan params");
13028 return ret;
13029 }
13030
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013031 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13032
13033 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013034 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013035 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013036 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013037
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013038 if (adapter->active_ac) {
13039 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013040 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013041 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13042 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13043 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013044 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013045 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013046 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13047 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13048 PM_LATENCY);
13049 } else {
13050 /*ignore this command if only BE/BK is active */
13051 is_tos_active = false;
13052 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13053 hdd_ctx->config->conc_system_pref);
13054 }
13055 } else {
13056 /* No active tos */
13057 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13058 hdd_ctx->config->conc_system_pref);
13059 }
13060
Jeff Johnson1b780e42017-10-31 14:11:45 -070013061 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013062 is_tos_active, max_off_chan_time,
13063 hdd_ctx->config->nRestTimeConc, true);
13064 if (!QDF_IS_STATUS_SUCCESS(status)) {
13065 hdd_err("failed to set limit off chan params");
13066 ret = -EINVAL;
13067 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013068
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013069 return ret;
13070}
13071
13072/**
13073 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13074 * @adapter - HDD adapter
13075 *
13076 * Return: 0 on success and non zero value on failure
13077 */
13078int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13079{
13080 struct hdd_context *hdd_ctx;
13081 int ret;
13082 QDF_STATUS status;
13083 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13084
13085 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13086 ret = wlan_hdd_validate_context(hdd_ctx);
13087 if (ret < 0)
13088 return ret;
13089
13090 /* set the system preferece to default */
13091 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13092 hdd_ctx->config->conc_system_pref);
13093
13094 /* clear the bitmap */
13095 adapter->active_ac = 0;
13096
13097 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013098 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013099
Jeff Johnson1b780e42017-10-31 14:11:45 -070013100 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013101 false, 0, 0, false);
13102 if (!QDF_IS_STATUS_SUCCESS(status)) {
13103 hdd_err("failed to reset limit off chan params");
13104 ret = -EINVAL;
13105 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013106
13107 return ret;
13108}
13109
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013110/**
13111 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13112 * @drv_op: Enum indicating driver op
13113 *
13114 * Return: none
13115 */
13116void hdd_start_driver_ops_timer(int drv_op)
13117{
13118 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13119 switch (drv_op) {
13120 case eHDD_DRV_OP_PROBE:
13121 memcpy(drv_ops_string, "probe", sizeof("probe"));
13122 break;
13123 case eHDD_DRV_OP_REMOVE:
13124 memcpy(drv_ops_string, "remove", sizeof("remove"));
13125 break;
13126 case eHDD_DRV_OP_SHUTDOWN:
13127 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13128 break;
13129 case eHDD_DRV_OP_REINIT:
13130 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13131 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013132 case eHDD_DRV_OP_IFF_UP:
13133 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13134 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013135 }
13136
13137 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13138 HDD_OPS_INACTIVITY_TIMEOUT);
13139}
13140
13141/**
13142 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13143 *
13144 * Return: none
13145 */
13146void hdd_stop_driver_ops_timer(void)
13147{
13148 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13149}
13150
13151/**
13152 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13153 * inactivity timer
13154 *
13155 * Return: None
13156 */
13157void hdd_drv_ops_inactivity_handler(void)
13158{
13159 hdd_err("%s: %d Sec timer expired while in .%s",
13160 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13161
13162 /* Driver shutdown is stuck, no recovery possible at this point */
13163 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13164 sizeof("shutdown")))
13165 QDF_BUG(0);
13166
13167 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013168 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013169 else
13170 QDF_BUG(0);
13171}
13172
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013173void hdd_pld_ipa_uc_shutdown_pipes(void)
13174{
13175 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13176
13177 if (!hdd_ctx)
13178 return;
13179
13180 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13181}
13182
Yun Parkff6a16a2017-09-26 16:38:18 -070013183/**
13184 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13185 * @struct hdd_context *hdd_ctx
13186 * @struct hdd_adapter *padapter
13187 * @bool enble
13188 *
13189 * Return: none
13190 */
13191void hdd_set_rx_mode_rps(bool enable)
13192{
13193 struct cds_config_info *cds_cfg = cds_get_ini_config();
13194 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13195 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13196
13197 if (adapter && hdd_ctx &&
13198 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13199 if (enable && !cds_cfg->rps_enabled)
13200 hdd_send_rps_ind(adapter);
13201 else if (!enable && cds_cfg->rps_enabled)
13202 hdd_send_rps_disable_ind(adapter);
13203 }
13204}
13205
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013206/* Register the module init/exit functions */
13207module_init(hdd_module_init);
13208module_exit(hdd_module_exit);
13209
13210MODULE_LICENSE("Dual BSD/GPL");
13211MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13212MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13213
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013214module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13215 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013216
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013217module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13218 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13219
Ravi Joshia307f632017-07-17 23:41:41 -070013220module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13221 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13222
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013223module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13224 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13225
13226module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13227
13228module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13229
13230module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);